Skip to content

Fix volume mounting when mode specified

Steve Xuereb requested to merge 4250-fix-volume-mounting-with-mode into master

What does this MR do?

Fix volume mounting when mode specified, which a user reported in #4250 (closed)

Why was this MR needed?

When a mode is specified for volumes, the length is incremented. The length of the volume is checked by the volume manager https://gitlab.com/gitlab-org/gitlab-runner/blob/d323a2b92f9599ccf4c8b0829235a2a1fb4ab9fd/executors/docker/internal/volumes/manager.go#L66-71 to see where to add the Volume, but since a src:dst:mode is specified the length is 3 so it never matches any case leading into the volume being dropped completely. If there is no match we should maybe send an error instead of being silent, but this can lead to a breaking change.

Manual testing

Tested with the following config.toml and .gitlab-ci.yml

config.toml
[[runners]]
  name = "docker"
  url = "http://192.168.1.79:3000/"
  token = "MASKED"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:3.9"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
	volumes = [
	"/cache",
	"/tmp/gitlab/runner/gcloud/service_accont_key_file.json:/root/.config/gcloud/service_accont_key_file.json:ro",
	"/tmp/gitlab/runner/config/config.json:/root/.docker/config.json:ro", 
	"/tmp/gitlab/runner/ssh:/root/.ssh:ro", 
	"/tmp/gitlab/runner/mvn/settings.xml:/root/.m2/settings.xml:ro", 
	]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
.gitlab-ci.yml
image: alpine:3.9

job:
  stage: test
  script:
  - "ls -la /root/.config/gcloud"
  - cat /root/.config/gcloud/service_accont_key_file.json
  - "ls -la /root/.docker/"
  - cat /root/.docker/config.json
  - "ls -la /root/.ssh"
  - "ls -la /root/.m2"
  - cat /root/.m2/settings.xml
job log
[0KRunning with gitlab-runner development version (HEAD)
[0;m[0K  on docker yj3uiViT
[0;msection_start:1558429439:prepare_executor
[0K[0KUsing Docker executor with image alpine:3.9 ...
[0;m[0KPulling docker image alpine:3.9 ...
[0;m[0KUsing docker image sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1 for alpine:3.9 ...
[0;msection_end:1558429442:prepare_executor
[0Ksection_start:1558429442:prepare_script
[0KRunning on runner-yj3uiViT-project-28-concurrent-0 via steve-mbp-gitlab.local...
section_end:1558429444:prepare_script
[0Ksection_start:1558429444:get_sources
[0KReinitialized existing Git repository in /builds/root/ci-scratch-pad/.git/
[32;1mFetching changes...[0;m
[32;1mChecking out e74496a5 as 4250...[0;m

[32;1mSkipping Git submodules setup[0;m
section_end:1558429446:get_sources
[0Ksection_start:1558429446:restore_cache
[0Ksection_end:1558429448:restore_cache
[0Ksection_start:1558429448:download_artifacts
[0Ksection_end:1558429450:download_artifacts
[0Ksection_start:1558429450:build_script
[0K[32;1m$ ls -la /root/.config/gcloud[0;m
total 12
drwxr-xr-x    2 root     root          4096 May 21 09:04 .
drwxr-xr-x    3 root     root          4096 May 21 09:04 ..
-rw-r--r--    1 root     root            63 May 21 07:26 service_accont_key_file.json
[32;1m$ cat /root/.config/gcloud/service_accont_key_file.json[0;m
/tmp/gitlab/runner/gcloud/service_accont_key_file.json content
[32;1m$ ls -la /root/.docker/[0;m
total 12
drwxr-xr-x    2 root     root          4096 May 21 09:04 .
drwx------    1 root     root          4096 May 21 09:04 ..
-rw-r--r--    1 root     root            46 May 21 07:27 config.json
[32;1m$ cat /root/.docker/config.json[0;m
/tmp/gitlab/runner/config/config.json content
[32;1m$ ls -la /root/.ssh[0;m
total 4
drwxr-xr-x    3 root     root            96 May 21 07:27 .
drwx------    1 root     root          4096 May 21 09:04 ..
-rw-r--r--    1 root     root             0 May 21 07:27 id
[32;1m$ ls -la /root/.m2[0;m
total 12
drwxr-xr-x    2 root     root          4096 May 21 09:04 .
drwx------    1 root     root          4096 May 21 09:04 ..
-rw-r--r--    1 root     root            44 May 21 07:28 settings.xml
[32;1m$ cat /root/.m2/settings.xml[0;m
/tmp/gitlab/runner/mvn/settings.xml content
section_end:1558429451:build_script
[0Ksection_start:1558429451:after_script
[0Ksection_end:1558429453:after_script
[0Ksection_start:1558429453:archive_cache
[0Ksection_end:1558429455:archive_cache
[0Ksection_start:1558429455:upload_artifacts_on_success
[0Ksection_end:1558429457:upload_artifacts_on_success
[0K[32;1mJob succeeded
[0;m

Does this MR meet the acceptance criteria?

  • Documentation created/updated
  • Added tests for this feature/bug
  • In case of conflicts with master - branch was rebased

What are the relevant issue numbers?

Closes #4250 (closed)

Edited by Steve Xuereb

Merge request reports

Loading