Search code examples
dockergitlab-ci-runnersmb

Gitlab Runner, docker executor, deploy from linux container to CIFS share


I have a Gitlab runner that runs all kind of jobs using Docker executors (host is Ubuntu 20, guests are various Linux images). The runner runs containers as unprivileged.

I am stumped on an apparently simple requirement - I need to deploy some artifacts on a Windows machine that exposes the target path as an authenticated share (\\myserver\myapp). Nothing more than replacing files on the target with the ones on the source - a simple rsync would be fine.

Gitlab Runner does not allow specifying mounts in the CI config (see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28121), so I tried using mount.cifs, but I discovered that by default Docker does not allow mounting anything inside the container unless running privileged, which I would like to avoid.

I also tried the suggestion to use --cap-add as described at Mount SMB/CIFS share within a Docker container but they do not seem to be enough for my host, there are probably other required capabilities and I have no idea how to identify them. Also, this looks just slightly less ugly than running privileged.

Now, I do not strictly need to mount the remote folder - if there were an SMB-aware rsync command for example I would be more than happy to use that. Unfortunately I cannot install or run anything on the Windows machine (no SSH, no SCP, no FTP), I have to use the file share mechanism.

Do you have any idea on how achieve this?


Solution

  • You can use smbclient to copy files from or to a CIFS/Samba/SMB share without creating a mount:

    smbclient '//myfileserver.domain.tld/sharename' --directory dir1/subdir1 -c 'put /path/to/local/file' -U '<USERNAME>%<PASSWORD>' -W <DOMAIN_WORKGROUP>
    

    put will copy a local file to the remote share and get will copy a remote file from the share to your local system.