1

I have some troubles getting my gitlab-runner to execute docker buildx command. I have a gitlab-runner which is configured like this:

[[runners]]
  name = "Name"
  url = "https://gitlab.mypage.com/"
  token = "token"
  executor = "shell"
  shell = "powershell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

And the pipeline which is triggered:

stages:
  - test
  - build

test_backend:
  stage: test
  script:
    - exit 0
  only:
    - merge_request
    - master

build:
  stage: build
  script:
    - docker login someregistry -u xxxx -p yyyy
    - docker buildx ls
  only:
    - merge_request
    - master
    - dev

I obfuscated the code a bit.

The problem I have is, that the docker login command is executed correctly but the docker buildx command not. I already tested the command manually on the machine and it was successfull.

Can somebody help me here?

enter image description here

enter image description here

enter image description here

Silvester Schn.
  • 144
  • 1
  • 2
  • 13

2 Answers2

0

In my experience with the docker runners the most likly situation here is, that the docker runner doesnt have the experimental features enabled just because the docker base have it... I have experienced things like that in the past: The docker in the runner IS NOT the docker where you hosting the runner at!

You problably have to add the DIND (Docker in Docker) Service for that, because as far as I understand this runner systems, only then the docker from your host is connected with the docker within the runner.

We did it like that:

  # gitlab-runner
gitlab-runner:
container_name: vivavis.gitlab-runner
image: gitlab/gitlab-runner:latest
restart: always
volumes: 
  - gitlab-runner:/etc/gitlab-runner
  - /var/run/docker.sock:/var/run/docker.sock // <<<<<< THIS IS THE IMPORTANT LINE
networks:
  - swp-infra-code

A little bit of warning here:

When activating that, we experienced a bug / not well cleaned up thing: Because the GitLab Runner is now connected with the base docker, the images that will be created while running a CI / CD are not deleted properly: GitLab doesnt implemented that feature, it just assumes, that when the gitlab-runner-container dies, all data dies within. But with this connection the data here is not dying becuase it is not created within the container - it is created in the base docker.

PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
  • Thanks a lot for your answer! But i do not really have a docker executor, I use the shell. Am I right when i assume you are using a docker executor? I thought, that when i use shell i can just do usual commands, or am I wrong? – Silvester Schn. Aug 05 '20 at 19:05
  • Well, docker shell means docker is installed, right? So it basicly is the executor?! – PassionateDeveloper Aug 05 '20 at 19:15
  • I am not sure i understand you corretcly. I thought shell means powershell , like my configuration? – Silvester Schn. Aug 05 '20 at 20:20
0

I found a solution for my problem. To use the experimental features you can set environment variables.

$env:DOCKER_CLI_EXPERIMENTAL=enabled

this command can be used in ci pipeline.

It looks like the docker cli in shell executor is not the same as the docker cli you can use on system if you try out. Very confusing.

Silvester Schn.
  • 144
  • 1
  • 2
  • 13