forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programming Exercises: Experimental support for GitLab CI (ls1intum#6044
- Loading branch information
1 parent
980f6f7
commit c201db4
Showing
53 changed files
with
1,869 additions
and
148 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
.idea/runConfigurations/Artemis__Server__GitLabCI___Gitlab_.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
GitLab CI and GitLab Setup | ||
-------------------------- | ||
|
||
This section describes how to set up a programming exercise environment | ||
based on GitLab CI and GitLab. | ||
|
||
.. note:: | ||
Depending on your operating system, it might not work with the predefined values (``host.docker.internal``). | ||
Therefore, it might be necessary to adapt these with e.g. your local IP address. | ||
|
||
**Prerequisites:** | ||
|
||
* `Docker <https://docs.docker.com/install>`__ | ||
* `Docker-Compose <https://docs.docker.com/compose/install/>`__ | ||
|
||
.. contents:: Content of this section | ||
:local: | ||
:depth: 1 | ||
|
||
|
||
GitLab | ||
^^^^^^ | ||
|
||
This section describes how to set up a development environment for Artemis with GitLab and GitLab CI. | ||
The same basic steps as for a `GitLab and Jenkins <#jenkins-and-gitlab-setup>`__ setup apply, but the steps that describe generating tokens for Jenkins can be skipped. | ||
For a production setup of GitLab, also see the documentation of the GitLab and Jenkins setup. | ||
|
||
GitLab | ||
"""""" | ||
|
||
1. Depending on your operating system, it is necessary to update the host file of your machine to include the following line: | ||
|
||
.. code:: text | ||
127.0.0.1 host.docker.internal | ||
::1 host.docker.internal | ||
2. Configure GitLab | ||
.. code:: bash | ||
cp src/main/docker/env.example.gitlab-gitlabci.txt src/main/docker/.env | ||
3. Start GitLab and the GitLab Runner | ||
.. code:: bash | ||
docker-compose -f src/main/docker/gitlab-gitlabci.yml --env-file src/main/docker/.env up --build -d | ||
4. Get your GitLab root password | ||
.. code:: bash | ||
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password | ||
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 | ||
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. | ||
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. | ||
|
||
Then execute this command with the registration token: | ||
|
||
.. code:: bash | ||
docker exec -it 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" | ||
You should now find the runner in the list of runners (``http://host.docker.internal/admin/runners``) | ||
|
||
.. note:: | ||
Adding a runner in a production setup works the same way. | ||
The GitLab administration page also contains alternative ways of setting up GitLab runners. | ||
All variants should allow the passing of the configuration options ``tag-list``, ``run-untagged``, ``locked``, and ``access-level`` similarly as in the Docker command above. | ||
If forgotten, Artemis might not use this runner to run the tests for exercise submissions. | ||
|
||
|
||
Artemis | ||
^^^^^^^ | ||
|
||
.. note:: | ||
Make sure that the database is empty and contains no data from previous Artemis runs. | ||
|
||
1. Generate authentication token | ||
The notification plugin has to authenticate to upload the test results. | ||
Therefore, a random string has to be generated, e.g., via a password generator. | ||
This should be used in place of ``notification-plugin-token`` value in the example config below. | ||
2. Configure Artemis | ||
For local development, copy the following configuration into the ``application-local.yml`` file and adapt it with the values from the previous steps. | ||
|
||
.. code:: yaml | ||
artemis: | ||
user-management: | ||
use-external: false | ||
internal-admin: | ||
username: artemis_admin | ||
password: gHn7JlggD9YPiarOEJSx19EFp2BDkkq9 | ||
login: | ||
account-name: TUM | ||
version-control: | ||
url: http://host.docker.internal:80 | ||
user: root | ||
password: password # change this value | ||
token: gitlab-personal-access-token # change this value | ||
continuous-integration: | ||
build-timeout: 30 | ||
artemis-authentication-token-value: notification-plugin-token # change this value | ||
git: | ||
name: Artemis | ||
email: [email protected] | ||
server: | ||
url: http://host.docker.internal:8080 | ||
.. note:: | ||
In GitLab, the password of a user must not be the same as the username and must fulfill specific requirements. | ||
Therefore, there is a random password in the example above. | ||
|
||
3. Start Artemis | ||
Start Artemis with the ``gitlab`` and ``gitlabci`` profile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
GIT_SERVER_NAME=http://git.example.com | ||
GIT_SERVER_NAME=http://host.docker.internal | ||
# Make sure to change to https | ||
SSL_ENABLED=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/de/tum/in/www1/artemis/domain/BuildPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.tum.in.www1.artemis.domain; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
import javax.persistence.UniqueConstraint; | ||
import javax.validation.constraints.Size; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
@Entity | ||
@Table(name = "build_plan", uniqueConstraints = { @UniqueConstraint(columnNames = { "build_plan" }) }) | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class BuildPlan extends DomainObject { | ||
|
||
@Size(max = 10_000) | ||
@Nullable | ||
@Column(name = "build_plan", table = "build_plan", length = 10_000) | ||
private String buildPlan; | ||
|
||
public BuildPlan() { | ||
// explicit constructor needed for Jackson | ||
} | ||
|
||
public BuildPlan(String buildPlan) { | ||
this.buildPlan = buildPlan; | ||
} | ||
|
||
public String getBuildPlan() { | ||
return buildPlan; | ||
} | ||
|
||
public void setBuildPlan(String buildPlan) { | ||
this.buildPlan = buildPlan; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/de/tum/in/www1/artemis/exception/GitLabCIException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.tum.in.www1.artemis.exception; | ||
|
||
public class GitLabCIException extends ContinuousIntegrationException { | ||
|
||
public GitLabCIException(String message) { | ||
super(message); | ||
} | ||
|
||
public GitLabCIException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public GitLabCIException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/de/tum/in/www1/artemis/repository/BuildPlanRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.tum.in.www1.artemis.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import de.tum.in.www1.artemis.domain.BuildPlan; | ||
|
||
public interface BuildPlanRepository extends JpaRepository<BuildPlan, Long> { | ||
|
||
Optional<BuildPlan> findByBuildPlan(String buildPlan); | ||
} |
Oops, something went wrong.