Problem
I am pretty new to the CI/CD realm, and I’m trying to figure out how to get my project deployed/tested with it. But I’m running into some pretty simple problems.
I am trying to specify a container in a GitLab instance to use, and the CI Jobs always seem to fail when pulling my docker image. The errors change based on the image value I use, and I’m not clear which one is closer to be correct. I’m leaning towards "invalid reference format" being the correct one, but am unclear.
I have already verified that the Project CI_TOKEN’s are enabled (-/settings/ci_cd/TOKEN ACCESS -> CI_JOB_TOKEN)
I have a feeling this may have to do with the port being explicitly set in the image path. But I’m not sure?
Error (#1): "invalid reference format"
default:
image: gitlab-ci-token:${CI_JOB_TOKEN}@git.domain.tld:1234/path/to/<subgroup>/<project>/<container>:latest
Running with gitlab-runner 14.10.1 (f761588f) on <subgroup>-group nHMWApbD
00:00 - Resolving secrets
00:01 - Preparing the "docker" executor
Using Docker executor with image gitlab-ci-token:[MASKED]@git.domain.tld:1234/path/to/<subgroup>/<project>/<container>:latest ...
Pulling docker image gitlab-ci-token:[MASKED]@git.domain.tld:1234/path/to/<subgroup>/<project>/<container>:latest ...
WARNING: Failed to pull image with policy "always":
invalid reference format (manager.go:203:0s)
Error (#2): "requested access to the resource is denied"
default:
image: <project>/<container>:latest
Running with gitlab-runner 14.10.1 (f761588f) on <subgroup>-group nHMWApbD
00:00 - Resolving secrets
00:01 - Preparing the "docker" executor
Using Docker executor with image <project>/<container>:latest ...
Pulling docker image <project>/<container>:latest ...
WARNING: Failed to pull image with policy "always":
Error response from daemon:
pull access denied for <project>/<container>,
repository does not exist or may require 'docker login':
denied: requested access to the resource is denied (manager.go:203:0s)
3
Answers
Answer
The issue was that b/c I was using a private registry, the job was having trouble authenticating to it. The solution was to create a variable in
Settings -> CI/CD -> Variables
with a key value ofDOCKER_AUTH_CONFIG
.You can find the general format below, or you can look on your Local Host at
~/.docker/config.json
to find the file contents that serve as the value forDOCKER_AUTH_CONFIG
.NOTE
Since the entire config value can't be masked, I opted to use a $VARIABLE in place of the Base64 encoded value
bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=
. This is better practice security wise, since it allows you to mask the encoded form of your username:password in CI/CD logs..gitlab-ci.yml
Get the Base64 value of your username & password/token (from Local Host)
Set Variable : DOCKER_AUTH_B64 (In GitLab,
Settings -> CI/CD -> Variables
)Set Variable : DOCKER_AUTH_CONFIG (In GitLab,
Settings -> CI/CD -> Variables
)Source
You could use the second format with the following:
More on this and this.
The problem is because as Gitlab official explain:
solve method
After reading this guidance at GitLab website, I changed config.toml of gitlab-runner add a new line for pull_policy as following: