A guide to automated Docker deployments w/ GitLab CI
Pete Saia
326

Good read — please note that if you have a properly set up GitLab instance, then your registry is available under this variable: $CI_REGISTRY.

If you ever need to reference this job, you can make use of $CI_JOB_ID (should be unique per job) or in the case of the project $CI_PROJECT_ID if you rather have a static reference.

~~

I usually need to deploy an image from the private registry to a public one so that’s usually a variable I define under secret variables as you mentioned (note that I would rather like to have global variables or per-user variables since the registry is public).

But for now I could simply write something like the following to set my variables:

variables:
CONTAINER_TEST_IMAGE:$CI_REGISTRY/
<NAMESPACE>/<PROJECT-NAME>:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE:$CI_REGISTRY/
<NAMESPACE>/<PROJECT-NAME>:latest

But that can be improved with:

variables:
CONTAINER_TEST_IMAGE:$CI_REGISTRY/$CI_PROJECT_PATH
CONTAINER_RELEASE_IMAGE:$PUB_REGISTRY/$CI_PROJECT_PATH:latest

While not much changed, it does make it portable (there goes a snippet to share). Note that $PUB_REGISTRY requires that secret variable to be set. Additionally, $CI_COMMIT_REF_NAME takes care of picking the branch name.

I’m still learning GitLab so I keep this in one of my tabs at the moment.

Show your support

Clapping shows how much you appreciated Luis Alvarado’s story.