Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Fix GitLab CI Setup #8023

Merged
merged 29 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1b332ac
Update setup documentation and fix bugs
bensofficial Sep 23, 2023
e9bc651
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 2, 2023
78ec4f7
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 3, 2023
ecf6364
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 4, 2023
80cfab0
Add saveAndFlush() before triggerBuild()
bensofficial Oct 4, 2023
c679856
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 5, 2023
8b6ec03
Merge branch 'fix/gitlab-ci-setup' of ssh://github.com/ls1intum/Artem…
bensofficial Oct 5, 2023
f0c7509
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 8, 2023
6e62644
Remove saveAndFlush()
bensofficial Oct 8, 2023
c33d9a3
Refactor trigger
bensofficial Oct 8, 2023
5b07511
Fix build plan id for creation of participation
bensofficial Oct 8, 2023
c26e0da
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 10, 2023
ffdc6fd
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 24, 2023
8beed6d
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 9, 2024
804bb28
Remove fix
bensofficial Feb 12, 2024
1cff56a
Fix compile error
bensofficial Feb 12, 2024
f96e0fd
Remove gitlab from migration
bensofficial Feb 12, 2024
c10df02
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 12, 2024
9827b14
Enable TS10
bensofficial Feb 12, 2024
d88c104
Merge branch 'fix/gitlab-ci-setup' of ssh://github.com/ls1intum/Artem…
bensofficial Feb 12, 2024
4c90818
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 16, 2024
39eda43
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 28, 2024
7b47e6d
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Mar 18, 2024
df14a32
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Mar 27, 2024
0a5c221
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Mar 28, 2024
0b93639
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Apr 2, 2024
01d67d8
Remove TS10
bensofficial Apr 2, 2024
a6834e2
Restore formating
bensofficial Apr 2, 2024
4351761
Apply suggestions from code review
bensofficial Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions docker/gitlab-gitlabci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,13 @@

services:
gitlab:
# TODO: check if more settings can also be integrated into gitlab.yml
extends:
file: ./gitlab.yml
service: gitlab
volumes:
- artemis-gitlab-data:/var/opt/gitlab
- artemis-gitlab-logs:/var/log/gitlab
- artemis-gitlab-config:/etc/gitlab
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url "${GIT_SERVER_NAME}"
prometheus_monitoring['enable'] = false
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0']
letsencrypt['enable'] = ${SSL_ENABLED}
letsencrypt['auto_renew_hour'] = "12"
letsencrypt['auto_renew_minute'] = "30"
letsencrypt['auto_renew_day_of_month'] = "*/7"
ports:
- "2222:22"
- "80:80"
- "443:443"
# expose the ports to make them reachable docker internally even if the external port mapping changes
expose:
- "22"
- "80"
- "443"
shm_size: "256m"
external_url "http://host.docker.internal:8081"
nginx['listen_port'] = 80
gitlab-runner:
image: docker.io/gitlab/gitlab-runner:latest
pull_policy: if_not_present
Expand Down
57 changes: 28 additions & 29 deletions docs/dev/setup/gitlabci-gitlab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,61 @@ For a production setup of GitLab, also see the documentation of the GitLab and J
GitLab
""""""

1. Depending on your operating system, it is necessary to update the host file of your machine to include the following line:
1. Depending on your operating system and your Docker installation, it is necessary to update the host file of your machine to include the following lines:

.. code:: text

127.0.0.1 host.docker.internal
::1 host.docker.internal

2. Configure GitLab
2. Start GitLab and the GitLab Runner
.. code:: bash

cp docker/env.example.gitlab-gitlabci.txt docker/.env
docker-compose -f docker/gitlab-gitlabci.yml up -d

3. Start GitLab and the GitLab Runner
3. Get your GitLab root password
.. code:: bash

docker-compose -f docker/gitlab-gitlabci.yml --env-file docker/.env up --build -d
docker exec artemis-gitlab grep 'Password:' /etc/gitlab/initial_root_password

4. Get your GitLab root password
.. code:: bash

docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
4. Generate an access token
Go to ``http://localhost:8081/-/profile/personal_access_tokens`` and generate an access token with all scopes.
This token is used for generating a runner token and in the Artemis configuration as ``artemis.version-control.token``.

5. Generate an access token
Go to ``http://host.docker.internal/-/profile/personal_access_tokens`` and generate an access token with all scopes.
This token is used in the Artemis configuration as ``artemis.version-control.token``.

6. Allow outbound requests to local network
5. Allow outbound requests to local network
For setting up the webhook between Artemis and GitLab, it is necessary to allow requests to the local network.
Go to ``http://host.docker.internal/admin/application_settings/network`` and allow the outbound requests.
Go to ``http://localhost:8081/admin/application_settings/network`` and allow the outbound requests.
More information about this aspect can be found in the `GitLab setup instructions <#gitlab-access-token>`__ (step 12).

GitLab Runner
"""""""""""""

1. Register a new runner
Login to your GitLab instance and open ``http://host.docker.internal/admin/runners``.
Click on ``Register an instance runner`` and copy the registration token.
1. Create a runner token
In order to create a token which can be used to register a runner, go to ``http://localhost:8081/admin/runners/new``.
Alternatively you can execute the command below with the personal access token generated before.

.. code:: bash
bensofficial marked this conversation as resolved.
Show resolved Hide resolved

curl --request POST --header "PRIVATE-TOKEN: <gitlab-personal-access-token>" \
--data "runner_type=instance_type" \
--data "run_untagged=true" \
--data "access_level=not_protected" \
"http://host.docker.internal:8081/api/v4/user/runners"

1. Register a new runner
Then execute this command with the registration token:

.. code:: bash

docker exec -it gitlab-runner gitlab-runner register \
docker exec -it artemis-gitlab-runner gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image alpine:latest \
--url http://host.docker.internal:80 \
--registration-token "PROJECT_REGISTRATION_TOKEN" \
--description "docker-runner" \
--maintenance-note "Test Runner" \
--tag-list "docker,artemis" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
--url http://host.docker.internal:8081 \
--token "REGISTRATION_TOKEN" \
--description "docker-runner"

You should now find the runner in the list of runners (``http://host.docker.internal/admin/runners``)
You should now find the runner in the list of runners (``http://localhost:8081/admin/runners``)

.. note::
Adding a runner in a production setup works the same way.
Expand Down Expand Up @@ -116,7 +115,7 @@ Artemis
login:
account-name: TUM
version-control:
url: http://host.docker.internal:80
url: http://localhost:8081
user: root
password: password # change this value
token: gitlab-personal-access-token # change this value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class MigrationEntry20230808_203400 extends MigrationEntry {

private final CopyOnWriteArrayList<ProgrammingExerciseParticipation> errorList = new CopyOnWriteArrayList<>();

private static final List<String> MIGRATABLE_PROFILES = List.of("bamboo", "gitlab", "jenkins");
private static final List<String> MIGRATABLE_PROFILES = List.of("bamboo", "jenkins");
bensofficial marked this conversation as resolved.
Show resolved Hide resolved

public MigrationEntry20230808_203400(ProgrammingExerciseRepository programmingExerciseRepository,
SolutionProgrammingExerciseParticipationRepository solutionProgrammingExerciseParticipationRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class GitLabCIProgrammingLanguageFeatureService extends ProgrammingLanguageFeatureService {

public GitLabCIProgrammingLanguageFeatureService() {
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, true, false));
programmingLanguageFeatures.put(JAVA, new ProgrammingLanguageFeature(JAVA, false, false, false, true, false, List.of(PLAIN_MAVEN, MAVEN_MAVEN), true, true, false));
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, false, false));
programmingLanguageFeatures.put(JAVA, new ProgrammingLanguageFeature(JAVA, false, false, false, true, false, List.of(PLAIN_MAVEN, MAVEN_MAVEN), false, false, false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@Service
public class GitLabCIService extends AbstractContinuousIntegrationService {

private static final String GITLAB_CI_FILE_EXTENSION = ".yml";

private static final Logger log = LoggerFactory.getLogger(GitLabCIService.class);

private static final String VARIABLE_BUILD_DOCKER_IMAGE_NAME = "ARTEMIS_BUILD_DOCKER_IMAGE";
Expand Down Expand Up @@ -112,7 +114,7 @@ public GitLabCIService(ProgrammingSubmissionRepository programmingSubmissionRepo
public void createBuildPlanForExercise(ProgrammingExercise exercise, String planKey, VcsRepositoryUri repositoryUri, VcsRepositoryUri testRepositoryUri,
VcsRepositoryUri solutionRepositoryUri) {
addBuildPlanToProgrammingExerciseIfUnset(exercise);
setupGitLabCIConfiguration(repositoryUri, exercise, planKey);
setupGitLabCIConfiguration(repositoryUri, exercise, generateBuildPlanId(exercise.getProjectKey(), planKey));
// TODO: triggerBuild(repositoryUri, exercise.getBranch());
}

Expand All @@ -126,7 +128,7 @@ private void setupGitLabCIConfiguration(VcsRepositoryUri repositoryUri, Programm
project.setSharedRunnersEnabled(true);
project.setAutoDevopsEnabled(false);

final String buildPlanUrl = buildPlanService.generateBuildPlanURL(exercise);
final String buildPlanUrl = buildPlanService.generateBuildPlanURL(exercise) + "&file-extension=" + GITLAB_CI_FILE_EXTENSION;
project.setCiConfigPath(buildPlanUrl);

projectApi.updateProject(project);
Expand Down Expand Up @@ -200,7 +202,11 @@ public String copyBuildPlan(ProgrammingExercise sourceExercise, String sourcePla

// When sending the build results back, the build plan key is used to identify the participation.
// Therefore, we return the key here even though GitLab CI does not need it.
return targetExercise.getProjectKey() + "-" + targetPlanName.toUpperCase().replaceAll("[^A-Z0-9]", "");
return generateBuildPlanId(targetExercise.getProjectKey(), targetPlanName);
}

private String generateBuildPlanId(String projectKey, String planKey) {
return projectKey + "-" + planKey.toUpperCase().replaceAll("[^A-Z0-9]", "");
}

@Override
Expand Down
Loading