Scripts to help with GitLab CI/CD management.
[[TOC]]
- a Linux, or a Windows with WSL
- Docker
- jq tool
- OpenSSL 1.1+ (with TLS 1.3)
Personal Token
This token is used for accessing the GitLab API.
To generate it:
- Click on the Avatar at the top-right corner
- Select "Preferences"
- Click "Access Tokens" on the left sidebar
- Add a "Add a personal access token"
- You may select the checkboxes for all the scopes
- Submit the form to create the Access Token
- Jot down the given code somewhere
Group/Project Access Token
This token is used for assigning a CI/CD Runner to a Group or an individual Project. If you used a Group Access Token, the runner will be available to all Projects in the same Group.
To generate it:
- Go to a Group/Project, and the left sidebar
- Go to "Settings > CI/CD"
- Expand the "Runners" section
- Under "Set up a ... Runner for a project", jot down the "Registration Token" somwhere
Prepare the Credentials file
Create a file called credentials.sh
, and populate it as follows:
#!/usr/bin/env bash
GITLAB_HOSTNAME="gitlab.myexample.com"
TOKEN_PERSONAL="<PERSONAL TOKEN>"
TOKENS_CICD=(
"<PRJ/GRP NAME> <PRJ/GRP ID> <PRJ/GRP TOKEN>"
"<PRJ/GRP NAME> <PRJ/GRP ID> <PRJ/GRP TOKEN>"
)
Note:
- You can insert as many Group/Project tokens as you want
- If your GitLab is at
https://gitlab.mysite.com/
, thenGITLAB_HOSTNAME
isgitlab.mysite.com
If your GitLab is using a self-signed cert, run the following to download the cert that allows the scripts to authenticate properly:
./certDownload.sh
# will generate a .crt file
You should see the following confirmation code:
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
...
Verify return code: 0 (ok)
If it fails, check that you are using an updated version of OpenSSL that supports TLS 1.3.
- Prepend
sudo
if you usesudo docker ls
instead ofdocker ls
. - Prepend
wsl
(e.g.wsl sudo ./runnersAdd.sh
) if you're using WSL.
- Edit
include.sh
- Set
SELF_SIGNED
field to the appropriate values
A Runner is a process hosted by a machine, which takes CI/CD jobs to run.
To let a Machine contribute as a Runner:
- Edit
runnersAdd.sh
- Scroll to the function definition for
register()
, and look at thedocker run
command:
docker run --rm -it \
-v $VOL:/etc/gitlab-runner \
gitlab/gitlab-runner:latest register \
--non-interactive \
--url $GITLAB_URL \
--registration-token $TOKEN \
--name "$NAME-$(hostname)" \
--tag-list "linux, docker, cuda, gpu, sonarqube" \
--docker-image "alpine:latest" \
--docker-gpus "all" \
--docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \
--docker-pull-policy="always" \
--docker-pull-policy="if-not-present" \
--executor "docker" \
--run-untagged="true" \
--locked="false"
- Edit the
docker run
command parameters. You may consider modifying or deleting:tag-list
to indicate your machine capabilitiesdocker-gpus
to provide GPU capabilitiesrun-untagged
to dictate what jobs it should accept
- When all edits are saved, execute
./runnersAdd.sh
.
To inspect all Runners available to you, run ./runnersInspect.sh
.
To shutdown all Runners this Machine is running, run ./runnersRemove.sh
.
To remove past pipeline jobs, run ./remotePipelinesCleanup.sh
.
To remove old and unreachable Runners, run ./remoteRunnersCleanup.sh
.