Here’s my gitlab-ci.yml
which I use to build a docker image and publish it to my repo’s gitlab.com
registry and to hub.docker.com
:
default:
image: docker:24.0.5
services:
- docker:24.0.5-dind
.default_scripts: &default_scripts
- docker pull $CI_REGISTRY_IMAGE:latest || true
- >
docker build
--pull
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
--tag $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
.
- docker push $CI_REGISTRY_IMAGE --all-tags
gitlab_registry:
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- *default_scripts
environment:
name: gitlab.com
docker_hub:
variables:
CI_REGISTRY: docker.io
CI_REGISTRY_IMAGE: docker.io/${DOCKER_USERNAME}/${CI_PROJECT_NAME}
before_script:
- echo -n $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $CI_REGISTRY
script:
- *default_scripts
environment:
name: hub.docker.com
The images are build just fine, tagged, and pushed if I only do:
git add .
git commit -m "message"
git push
But if I use git tags
:
git add .
git commit -m "message"
git tag -a 1.0.0 -m "message"
git push
Images are build, tagged, and pushed to gitlab.com
just fine. But the hub.docker.com
pipeline fails with an error unrelated to git tags
:
Running with gitlab-runner 16.6.0~beta.105.gd2263193 (d2263193)
on blue-5.saas-linux-small-amd64.runners-manager.gitlab.com/default -AzERasQ, system ID: s_4cb09cee29e2
feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor
00:31
Using Docker executor with image docker:24.0.5 ...
Starting service docker:24.0.5-dind ...
Pulling docker image docker:24.0.5-dind ...
Using docker image sha256:7015f2c475d511a251955877c2862016a4042512ba625ed905e69202f87e1a21 for docker:24.0.5-dind with digest docker@sha256:3c6e4dca7a63c9a32a4e00da40461ce067f255987ccc9721cf18ffa087bcd1ef ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image docker:24.0.5 ...
Using docker image sha256:7015f2c475d511a251955877c2862016a4042512ba625ed905e69202f87e1a21 for docker:24.0.5 with digest docker@sha256:3c6e4dca7a63c9a32a4e00da40461ce067f255987ccc9721cf18ffa087bcd1ef ...
Preparing environment
00:00
Running on runner--azerasq-project-53436565-concurrent-0 via runner-azerasq-s-l-s-amd64-1703962998-08bd33b7...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/b00jum/heuristic-babbage/.git/
Created fresh repository.
Checking out 05e15ad5 as detached HEAD (ref is 2.2.0)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:01
Using docker image sha256:7015f2c475d511a251955877c2862016a4042512ba625ed905e69202f87e1a21 for docker:24.0.5 with digest docker@sha256:3c6e4dca7a63c9a32a4e00da40461ce067f255987ccc9721cf18ffa087bcd1ef ...
$ echo -n $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $CI_REGISTRY
Error: Cannot perform an interactive login from a non TTY device
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
Notice the Error: Cannot perform an interactive login from a non TTY device
. Authentication works just fine if I don’t use git tag
. Why is it so? How I can fix it?