From b297e7cde053d37a862a758c31668be8568985e4 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Wed, 18 Jul 2018 12:38:36 +0200 Subject: [PATCH] Update README.md --- README.md | 23 +++++++++++------------ abgabesystem.py | 24 ++++++++++++------------ config.yml | 4 ++-- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7c3f821..4f16de2 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,24 @@ -# The Abgabesystem +# The abgabesystem ## Setup -0. Configure gitlab with your LDAP configuration. +0. Optional: If you have not previously set up GitLab for the abgabesystem, you can use the playbook in playbook.yml to setup your instance. -1. Generate a deploy key and an API token. +1. Create a new group with the name of the course. -2. Set up container images and runners. - - [checkstyle](https://ips1.ibr.cs.tu-bs.de/abgabesystem/checkstyle) - - [abgabesystem](https://ips1.ibr.cs.tu-bs.de/abgabesystem/abgabesystem) +2. Create a fork of abgabesystem inside that group. -3. Create a group for your course and add all administrative users to it. +3. Configure config.yml and generate an SSH key pair. + Add the private key to the fork as the secret variable SSH_PRIVATE_KEY. + Add the public key to config.yml as deploy_key. -4. Clone [abgabesystem](https://ips1.ibr.cs.tu-bs.de/abgabesystem/docker-abgabesystem) as a private project of that group and add SSH_PRIVATE_KEY and PRIVATE_API_TOKEN to the private variables. +4. Export the student list from StudIP and add it to the project. -5. Edit [config.yml](blob/master/config.yml) to include the name of the student list, your public -deploy key and the name of the course. +5. Create an API key with admin access and add it to the fork as the secret variable PRIVATE_API_TOKEN. -6. Export student list from StudIP and add it to the project. +6. Add all administrative users to the group of your course (but not the students). -7. wait for ci jobs to finish.... +The CI jobs should then create the student repositories. ## Recommended settings for gitlab.rb diff --git a/abgabesystem.py b/abgabesystem.py index 486b27d..ea273e3 100644 --- a/abgabesystem.py +++ b/abgabesystem.py @@ -16,14 +16,16 @@ class Course(yaml.YAMLObject): - name: name of the course - base: the project containig the official solutions - students: path to the CSV file that can be exported from Stud.IP + - deploy_key: a deploy key for deploying student repos to CI jobs """ yaml_tag = 'Course' - def __init__(self, name, base, studentsfile): + def __init__(self, name, studentsfile, deploy_key): self.name = name - self.base = base + self.base = 'solutions' self.students = studentsfile + self.deploy_key = deploy_key def sync_group(self, gl): """Creates the group for the course @@ -52,7 +54,7 @@ class Course(yaml.YAMLObject): All student projects will fork from this projects and can be updated using ``` - git remote add upstream .gitlab + git remote add upstream git pull upstream master ``` """ @@ -117,7 +119,7 @@ class Student(): 'name': self.name, 'provider': ldap['provider'], 'skip_confirmation': True, - 'extern_uid': 'uid=%s,%s' % (self.user, ldap['basedn']), + 'extern_uid': 'uid=%s,%s' % (self.user, ldap['main']['base']), 'password': secrets.token_urlsafe(nbytes=32) }) user.customattributes.set('group', self.group) @@ -158,14 +160,12 @@ def sync_project(gl, course, student): except gitlab.exceptions.GitlabGetError as e: student_member = project.members.create({'user_id': student.user.id, 'access_level': gitlab.DEVELOPER_ACCESS}) - deploy_key = None - for k in gl.deploykeys.list(): - if k.key == course.deploy_key: - deploy_key = k - if deploy_key is None: - print('Missing deploy key. Add global deploy key and sync again') - else: - project.keys.enable(deploy_key.id) + deploy_key = project.keys.create({ + 'title': course.name, + 'key': course.deploy_key + }) + + project.keys.enable(deploy_key.id) project.container_registry_enabled = False project.lfs_enabled = False project.save() diff --git a/config.yml b/config.yml index f0768b3..341ef5f 100644 --- a/config.yml +++ b/config.yml @@ -1,10 +1,10 @@ ldap: - basedn: "ou=people,dc=tu-bs,dc=de" + main: + base: 'ou=people,dc=tu-bs,dc=de' provider: main course: !!python/object:abgabesystem.Course name: test_course - base: test_base students: Students.csv deploy_key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKl2zu3ClMIOI6EhEi0qGjwCgEaWYfRl2149T45pcggnYc3CVln0FJhjXvWbfMU984TjJMw4X8dfeZpf9p7xtieAab6yz+vB6QTW1ur9Uge0Wv/D084Sdzb3FovC+Qr90d6BAd+A6+v/vEprTLnuX8McQuB4p8l6iimFrhmv4IdrD1W/y0AUEzdz/eXpsHavlqGrpb4oQ0aAnZq0qQ9cYAltcXKQzgLi7zoKJGNWR+gz4hfRfqme87+k0ABO3hWwcIuwm/XdHm9Z+hjZrPfqmZGJF71FasE9jymP0Si4sgQLjaX+qQh3ojubBN7RwhUo3zjFFFUL5/tLEIr42SGpXF abgabesystem'