GitLab Runner - Docker Image - docker

I started to work with GitLab CI/CD. I have setup my own GitLab-runner with docker executor. It is working fine. When I read about docker, I came to know that it creates a separate space for each run so that we could even access it and use it. I would like to know the path in which the docker images are created.
This is my config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Linux-Docker1"
url = "https://gitlab.com/"
token = "4-UWY1A_J2rS7r32wxJi"
executor = "docker"
builds_dir = "/var/working/gitlab-runner-docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.docker]
tls_verify = false
image = "ruby:2.6"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[[runners]]
name = "Linux-Shell1"
url = "https://gitlab.com/"
token = "LzdxrS1zA58rXihSQWCn"
executor = "shell"
builds_dir = "/var/working/gitlab-runner"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
This is my .gitlab-ci.yml file
stages:
- build
- test
build:
stage: build
script:
- whoami
- mkdir test-build
- touch test-build/info.txt
- ls
- pwd
- cd ..
- pwd
- ls
artifacts:
paths:
- test-build/
test:
stage: test
script:
- echo "Test Script"
- ls
- test -f "test-build/info.txt"

In your case you didn't create a docker image, because in your build step you do not run docker build command
about the path, if you build a docker image, you need to push it to a container registry (docker hub or a private one)
look at this doc to know how to do it
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html

Related

Error in gitlab CI/CD while docker login invalid certificate

Hey i got GitLab and gitlab runner runned in docker in gitlab i got working container registry.
when in CI/CD im trying to do
stages: # List of stages for jobs, and their order of execution
- build
docker-build:
# Use the official docker image.
image: docker:latest
services:
- docker:dind
stage: build
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
I got error like
Get "https://git.domain.com:5050/v2/": x509: certificate signed by unknown authority
my runner config.toml looks like this
concurrent = 1
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Runner"
url = "http://git.domain.com/"
id = 3
token = "xxxxxxxxxcccccc"
token_obtained_at = 2023-02-07T22:14:54Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
clone_url = "http://git.domain.com/"
[runners.custom_build_dir]
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "node:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
What can i do with this?
When i do login from my pc its works perfect
edit:
My cert is not selfsigned
I added my CA certificate to certificate, and now its works

Gitlab runner failing ERROR: Cannot connect to the Docker daemon at local runner

I have a local runner that cannot connect to the docker daemon.
I tried adding an alias to the service and it still failed
ERROR: Cannot connect to the Docker daemon at tcp://docker:2375/. Is the docker daemon running?
ERROR: Cannot connect to the Docker daemon at tcp://thealias:2375/. Is the docker daemon running?
gitlab-ci
push_image:
image: docker:20.10.16-dind
services:
- docker:20.10.16-dind
before_script:
- docker info
- docker login ext_registry.com -u $NEXUS_USER -p $NEXUS_PASS
script:
- docker build -t ext_registry.com.liberty.edu:5000/occ/groupsyncer:latest .
gitlab-runner.toml
[[runners]]
name = "docker-runner"
url = "https://gitlab.example.com/"
token = REDACTED
executor = "docker"
cache_dir="/cache"
clone_url = "https://gitlab.example.com"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
volumes = ["/opt/gitlab-runner/cache:/cache:rw"]
tls_verify = false
image = "docker:20.10.16"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
shm_size = 0
In my case the error came from not sharing the docker sock.
[runners.docker]
volumes = ["/var/run/docker.sock:/var/run/docker.sock","/opt/gitlab-runner/cache:/cache:rw"]
Also make sure the gitlab-runner has permissions to docker.
usermod -aG docker gitlab-runner

The difference between running a docker image form a gitlab-runner or directly

I need a customised maven docker image to execute my tests.
It requires me to tweak the time zone and add true type fonts.
I created my own maven image FROM maven:3.6.3-openjdk-8
I am using the gitlab/gitlab-ce:latest locally on my Mac and executing my tests in two ways
1.
From the container shell
docker run -it -v /Users/myuser/.m2:/root/.m2 -v \
/local/config:/local/ config -v \
/Users/ myuser /workspace/:/build \
--network=mynetwrok \
maven- tweak:1.0.1 bash
2.
from the local gitlab with the following runner config
oncurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "maven- tweak "
url = "http://gitlab"
token = "xyz"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "maven- tweak:1.0.0"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache","/Users/myuser/.m2:/root/.m2",“/Users/ myuser/workspace/:/build "]
network_mode = "mynetwork"
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
I am trying to figure it out for a while now.
What are the deferences between the two executions so I could figure out the problems.

Gitlab CI run code quality not generate .json file

I followed the official guid deploied a pipline to analyse my code quality. Although the pipline passed and the job successed, the json file didn't generated by docker. And these notis displaied:
WARNING: A new version (v0.83.0) is available. Upgrade instructions
are available at: https://github.com/codeclimate/codeclimate#packages
Uploading artifacts... WARNING: gl-code-quality-report.json: no
matching files ERROR: No files to upload
Job succeeded
And this is my /etc/gitlab-runner/config.toml file:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "code_quality"
url = "http://192.168.0.2/"
token = "pyKK8v9C6Bnay8yMmfph"
executor = "docker"
[runners.docker]
tls_verify = false
image = "docker:stable"
privileged = true
cache_dir = "cache"
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
My Gitlab version is 11.7
And this is my .gitlab-ci.yml file:
code_quality:
tags:
- quality
image: docker:latest
variables:
DOCKER_DRIVER: overlay2
before_script:
- ip -4 a
allow_failure: true
services:
- name: docker:stable-dind
command: ["--insecure-registry=192.168.0.1:5000"]
script:
- ip -4 a
- docker pull 192.168.0.1:5000/codeclimate:0.72.0
- docker tag 192.168.0.1:5000/codeclimate:0.72.0 codeclimate/codeclimate:0.72.0
- docker pull 192.168.0.1:5000/codeclimate-coffeelint:latest
- docker tag 192.168.0.1:5000/codeclimate-coffeelint:latest codeclimate/codeclimate-coffeelint:latest
- docker pull 192.168.0.1:5000/codeclimate-csslint:latest
- docker tag 192.168.0.1:5000/codeclimate-csslint:latest codeclimate/codeclimate-csslint:latest
- docker pull 192.168.0.1:5000/codeclimate-eslint:latest
- docker tag 192.168.0.1:5000/codeclimate-eslint:latest codeclimate/codeclimate-eslint:latest
- docker pull 192.168.0.1:5000/codeclimate-rubocop:latest
- docker tag 192.168.0.1:5000/codeclimate-rubocop:latest codeclimate/codeclimate-rubocop:latest
- docker pull 192.168.0.1:5000/codeclimate-fixme:latest
- docker tag 192.168.0.1:5000/codeclimate-fixme:latest codeclimate/codeclimate-fixme:latest
- docker pull 192.168.0.1:5000/codeclimate-structure:latest
- docker tag 192.168.0.1:5000/codeclimate-structure:latest codeclimate/codeclimate-structure:latest
- docker pull 192.168.0.1:5000/codeclimate-duplication:latest
- docker tag 192.168.0.1:5000/codeclimate-duplication:latest codeclimate/codeclimate-duplication:latest
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker images
- docker run
--env SOURCE_CODE="$PWD"
--env CODECLIMATE_VERSION=0.72.0
--env TIMEOUT_SECONDS=900
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
192.168.0.1:5000/codequality:latest /code
artifacts:
reports:
codequality: gl-code-quality-report.json
Due to I want increase the speed of pulling image, so I deployed a docker registry in localhost.
Can you give me some advice?
Thank you all!
ANyways, months later, if you are using Gitlab CE ths won't work, is a feature for EE only.

Docker-ssh non-root path/getsockopt: connection refused

I’m trying to use the gitlab-runner with docker-ssh. Here is how my config.toml looks like:
[[runners]]
name = “CI/CD docker-ssh alfa”
url = “https://gitlab.com/”
token = “<SOME_TOKEN>“
executor = “docker-ssh”
[runners.ssh]
user = “myuser”
password = “my password”
[runners.docker]
tls_verify = false
image = “ubuntu:latest”
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
But I got this error:
Running with gitlab-runner 11.3.0 (d78e9e67)
on CI/CD docker-ssh alfa 1f147b76
Using Docker executor with image ubuntu:latest …
ERROR: Preparation failed: build directory needs to be absolute and non-root path
Will be retried in 3s …
Using Docker executor with image ubuntu:latest …
ERROR: Preparation failed: build directory needs to be absolute and non-root path
So I tried to change the build directory and here hows my config.toml file looks like now:
[[runners]]
name = “CI/CD docker-ssh alfa”
url = “https://gitlab.com/”
token = “<SOME_TOKEN>“
executor = “docker-ssh”
builds_dir = “/home/myuser/“
[runners.ssh]
user = “myuser”
password = “my password”
[runners.docker]
tls_verify = false
image = “ubuntu:latest”
privileged = false
disable_cache = false
volumes = [”/cache"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
But I got this new error:
Running with gitlab-runner 11.3.0 (d78e9e67)
on CI/CD docker-ssh alfa 1f147b76
Using Docker executor with image ubuntu:latest …
WARNING: Since GitLab Runner 10.0 docker-ssh and docker-ssh+machine executors are marked as DEPRECATED and will be removed in one of the upcoming releases
Pulling docker image ubuntu:latest …
Using docker image sha256:cd6d8154f1e16e38493c3c2798977c5e142be5e5d41403ca89883840c6d51762 for ubuntu:latest …
ERROR: Preparation failed: dial tcp 172.17.0.2:22: getsockopt: connection refused
Will be retried in 3s …
Any idea what am I doing wrong?
Stick with an HTTPS URL, and try fixing instead the error:
build directory needs to be absolute and non-root path
See this thread
I was running my CI on an old gitlab-ci-multi-runner 9.5.1.
I update to gitlab-runner 10.8.0 and now it’s ok.
Or this thread:
Set build_dir="C:\\gitlab-runner\\builds" in the config.toml.

Resources