Skip to content

Add labels to cache-init docker container

Adrien Kohlbecker requested to merge ak/label-cache-init-container into master

What does this MR do?

Add labels to the cache-init container created by the docker executor, with job ids, pipeline ids...

Follow up to !2334 (merged)

Why was this MR needed?

Every resource that our Docker executor is generally labeled so that users can easily identify that the resource is managed by the Runner. The Runner creates cache-init containers but they are not labeled by the Runner.

What's the best way to test this MR?

Run a build and inspect the container using docker inspect

What are the relevant issue numbers?

Closes #25481 (closed)

QA

  • Since the cache-init container is ephemeral, you can't inspect its labels at runtime. However, we can validate that it has been correctly labeled by filtering the docker events firehose. Run in the background docker events --filter "label=com.gitlab.gitlab-runner.type=cache-init"

  • Run a build:

image: ubuntu:20.04

build1:
  stage: build
  script:
    - echo "success!"
  • Notice creation & deletion events for containers labeled with that type in the firehose:
2020-09-15T15:04:03.654834400+02:00 container create 5898b90f0052b69bf90d7ae7b0d40ede7b42d63e1d683e07ff4df95485b5429d (com.gitlab.gitlab-runner.job.before_sha=8e734afb27a68436ff29b2973b05351fdd51669f, com.gitlab.gitlab-runner.job.id=792, com.gitlab.gitlab-runner.job.ref=master, com.gitlab.gitlab-runner.job.sha=6c8eb7f4ffb1c00bd5ea92d420851b1e41052304, com.gitlab.gitlab-runner.pipeline.id=84, com.gitlab.gitlab-runner.project.id=21, com.gitlab.gitlab-runner.runner.id=g_XWCUS4, com.gitlab.gitlab-runner.runner.local_id=0, com.gitlab.gitlab-runner.type=cache-init, image=sha256:a0ba1bbb17442f504557cda685751b85d9f634f0ac9a0b93bf18cce2390f5ebd, name=runner-gxwcus4-project-21-concurrent-0-cache-904f6ed42e0fa2b14c1d7a2ed6f1875e-set-permission-c9ae6bd31089109b)
2020-09-15T15:04:03.896769400+02:00 container start 5898b90f0052b69bf90d7ae7b0d40ede7b42d63e1d683e07ff4df95485b5429d (com.gitlab.gitlab-runner.job.before_sha=8e734afb27a68436ff29b2973b05351fdd51669f, com.gitlab.gitlab-runner.job.id=792, com.gitlab.gitlab-runner.job.ref=master, com.gitlab.gitlab-runner.job.sha=6c8eb7f4ffb1c00bd5ea92d420851b1e41052304, com.gitlab.gitlab-runner.pipeline.id=84, com.gitlab.gitlab-runner.project.id=21, com.gitlab.gitlab-runner.runner.id=g_XWCUS4, com.gitlab.gitlab-runner.runner.local_id=0, com.gitlab.gitlab-runner.type=cache-init, image=sha256:a0ba1bbb17442f504557cda685751b85d9f634f0ac9a0b93bf18cce2390f5ebd, name=runner-gxwcus4-project-21-concurrent-0-cache-904f6ed42e0fa2b14c1d7a2ed6f1875e-set-permission-c9ae6bd31089109b)
2020-09-15T15:04:03.969627200+02:00 container die 5898b90f0052b69bf90d7ae7b0d40ede7b42d63e1d683e07ff4df95485b5429d (com.gitlab.gitlab-runner.job.before_sha=8e734afb27a68436ff29b2973b05351fdd51669f, com.gitlab.gitlab-runner.job.id=792, com.gitlab.gitlab-runner.job.ref=master, com.gitlab.gitlab-runner.job.sha=6c8eb7f4ffb1c00bd5ea92d420851b1e41052304, com.gitlab.gitlab-runner.pipeline.id=84, com.gitlab.gitlab-runner.project.id=21, com.gitlab.gitlab-runner.runner.id=g_XWCUS4, com.gitlab.gitlab-runner.runner.local_id=0, com.gitlab.gitlab-runner.type=cache-init, exitCode=0, image=sha256:a0ba1bbb17442f504557cda685751b85d9f634f0ac9a0b93bf18cce2390f5ebd, name=runner-gxwcus4-project-21-concurrent-0-cache-904f6ed42e0fa2b14c1d7a2ed6f1875e-set-permission-c9ae6bd31089109b)
2020-09-15T15:04:04.053765600+02:00 container destroy 5898b90f0052b69bf90d7ae7b0d40ede7b42d63e1d683e07ff4df95485b5429d (com.gitlab.gitlab-runner.job.before_sha=8e734afb27a68436ff29b2973b05351fdd51669f, com.gitlab.gitlab-runner.job.id=792, com.gitlab.gitlab-runner.job.ref=master, com.gitlab.gitlab-runner.job.sha=6c8eb7f4ffb1c00bd5ea92d420851b1e41052304, com.gitlab.gitlab-runner.pipeline.id=84, com.gitlab.gitlab-runner.project.id=21, com.gitlab.gitlab-runner.runner.id=g_XWCUS4, com.gitlab.gitlab-runner.runner.local_id=0, com.gitlab.gitlab-runner.type=cache-init, image=sha256:a0ba1bbb17442f504557cda685751b85d9f634f0ac9a0b93bf18cce2390f5ebd, name=runner-gxwcus4-project-21-concurrent-0-cache-904f6ed42e0fa2b14c1d7a2ed6f1875e-set-permission-c9ae6bd31089109b)
  • You can confirm this is the right container by matching the container_id with the one shown in the runner logs:
Created container to set volume permissions         container_id=5898b90f0052b69bf90d7ae7b0d40ede7b42d63e1d683e07ff4df95485b5429d context=set_volume_permission job=792 project=21 runner=g_XWCUS4 volume_name=runner-gxwcus4-project-21-concurrent-0-cache-904f6ed42e0fa2b14c1d7a2ed6f1875e

Merge request reports