Can you explain. I have Gitlab runner and now I am configuring CI/CD using one guide. It says that runner requires the image names in docker-compose.yml
to be named like this:
$CI_REGISTRY/organisation/path-to-project/project_image:$CI_ENVIRONMENT_SLUG-$CI_COMMIT_SHA
I put this value in a variable in the .env
file. But now when I run docker compose up
- error pops up - says $CI_REGISTRY
, $CI_ENVIRONMENT_SLUG
and $CI_COMMIT_SHA
are not set. What should I do in this case? Everything was working fine before CI/CD was connected.
level=warning msg="The \"CI_REGISTRY\" variable is not set. Defaulting to a blank string."
level=warning msg="The \"CI_ENVIRONMENT_SLUG\" variable is not set. Defaulting to a blank string."
level=warning msg="The \"CI_COMMIT_SHA\" variable is not set. Defaulting to a blank string."
Error response from daemon: no such image: organisation/path-to-project/project_image:-: invalid reference format
At the same time docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
in before_script
in .gitlab-ci.yml
works and variable values are calculated from somewhere.
image: docker/compose:alpine-1.28.0
stages:
- build
- deploy
before_script:
- apk add make
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- cp $ENV $(pwd)/src/.env
build:
stage: build
script:
- make build push
tags:
- job:build
only:
- main
environment:
name: production
deploy:
stage: deploy
script:
- make pull down migrate up
tags:
- job:deploy
only:
- main
environment:
name: production
$ENV
in before_script
is variable on Gitlab.
Here is docker-compose.yml
(${IMAGE_NAME}
- variable from .env
):
services:
app1:
build: .
image: ${IMAGE_NAME}
env_file:
- .env
# ...
app2:
build: .
image: ${IMAGE_NAME}
env_file:
- .env
# ...
Can you tell me what I'm doing wrong? I'm just getting started with CI/CD.