/cache volume is always added to volumes list

Summary

When adding additional volumes via register --docker-volume, /cache is still added, even if a different volume for /cache is submitted.

Steps to reproduce

run the register command in --non-interactive mode and append --docker-volumes /srv/gitlab-runner/cache:/cache

check the created config.toml

volumes = ["/srv/gitlab-runner/cache:/cache", "/cache"]

What is the current bug behavior?

see "steps to reproduce"

What is the expected correct behavior?

gitlab-runner either automatically detects that /cache is already provided in a volume and doesn't add it a second time, or (since this might be hard to detect) at least offers a switch that disables automatically adding this volume, maybe with a warning attached that the user then must provide the volume mount point manually.

Relevant logs and/or screenshots

The offending code seems to be at https://gitlab.com/gitlab-org/gitlab-runner/blob/master/commands/register.go#L108

s.Docker.Volumes = append(s.Docker.Volumes, "/cache")

There are no checks if it is even necessary and no way to disable this.

Possible fixes

  • Manually edit the config file after generation, removing the "/cache" entry (my current workaround, not a good solution)
  • Add a switch to give a more precise location for the "/cache" volume.
  • Add a switch to disable automatically adding "/cache" to the volumes list.
  • Automatically detect if a "/cache" volume is provided already by --docker-volumes and don't add "/cache" in these cases.
Edited by Alessio Caiazza