Container Registry Access

Container Registry Access

This section explains how to enable the GitLab-Runner to access the container registry. The container registry of the target repository contains the docker image needed to run the different scripts.

⚠️
Prerequisite : You must have completed the Remote Host and Deploy Token section before following this one.

Configuration of the GitLab-Runner

The deployment token is used to give access to the container registry. The GitLab-Runner need to access this registry to pull the image needed to run the scripts.

Encoding

Encoding the username and password in base 64 as follows :

printf "<username>:<token>" | openssl base64 -A

Where <username> is the value contained in $CI_DEPLOY_USER and the <token> value is contained in $CI_DEPLOY_PASSWORD. These values are also accessible when the deployment token is created.

The output is a base 64 encoded string such as : bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=. Note that the length may be different.

Modify the config.toml

Finally, modify the config.toml of the GitLab-Runner by adding the parameter environement under executor = "docker":

[[runners]]
...
executor = "docker"
environment = ["DOCKER_AUTH_CONFIG={\"auths\":{\"registry.gitlab.com\":{\"auth\":\"bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=\"}}}"]
[runners.cache]
...

Where bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ= is replaced by the output of the previous step. Replace the registry.gitlab.com with your GitLab address.

Restart the service

Restart GitLab-Runner using this command :

sudo gitlab-runner restart