Skip to content

feat: add Docker volume driver ops

What does this MR do?

Allow the user to specify VolumeDriverOps in addition to the existing VolumeDriver config option

Why was this MR needed?

TLDR: We want to limit the allowed size that can be consumed inside a build.

Docker has the option to specify Docker driver ops. To make use of this feature, we need to add this option to Gitlab runner, which can then be specified the same way, we currently can set the VolumeDriver

Docker documentation for volume driver ops: https://docs.docker.com/engine/reference/commandline/volume_create/#driver-specific-options

Our use-case here is limiting the size of Docker volumes that are creating for every build. This is very important, if you want to limit space per build. See: https://github.com/moby/moby/pull/41330#issue-675617249

Example VolumeDriverOpt: size=1G to limit the size of the build to 1 GB.

What's the best way to test this MR?

  1. Make sure that the filesystem is xfs and the pquote mount option is specified, as mentioned in the Docker documentation

    https://docs.docker.com/engine/reference/commandline/run/#set-storage-driver-options-per-container

    For the overlay2 storage driver, the size option is only available if the backing fs is xfs and mounted with the pquota mount option. Under these conditions, user can pass any size less than the backing fs size.

    Sadly this feature to limit the size of volumes is not documented by Docker itself, but it was added here: https://github.com/moby/moby/pull/41330

  2. Add the following to your Gitlab Runner Config

    [runners.docker]
      [runners.docker.volume_driver_ops]
          "size" = "50G"
  3. Setup a new project add use this .gitlab-ci.yml file

    default:
      image: alpine:latest
      script:
        - FAILED=false
        - fallocate -l 51G bigfile || FAILED=true
        - $FAILED || exit 1
  4. Look at the successful build

    image

What are the relevant issue numbers?

Edited by Max Wittig

Merge request reports