Skip to content

Fix `--docker-services` flag in register command

What does this MR do?

Fix docker services regression flag to keep backword compatibility.

Why was this MR needed?

In !1673 (merged) we introduced a new configuration struct for how services are defined for the Docker executor. This breaks the --docker-services that can be used to specify a service on Docker. To generate those flags we use gitlab.com/ayufan/golang-cli-helpers to marshal and unmarshal them, but it doesn't support structs and can't be made to support structs easily since it would need to change the format.

Introduce a transformer called DockerServiceTransformer which will be used as the flag and will take the old input and transforms it into the new input. It does this be string parsing the output of the struct marshaling in https://gitlab.com/gitlab-org/gitlab-runner/blob/9b9e1babc8102c6e92cd47c65c3ca90dd73e7cf7/vendor/gitlab.com/ayufan/golang-cli-helpers/convert.go#L97-118. ee13c563

How to test

  • Register a new Runner with register --non-interactive --url http://127.0.0.1:3000/ --registration-token "TOKEN" --executor "docker" --docker-image "alpine:3.11" --description "detelme" --docker-services "postgres:12-alpine" -c ~/Downloads/delete.toml

  • The following config.toml should be saved in ~/Downloads/delete.toml

    config.toml
    concurrent = 1
    check_interval = 0
    
    [session_server]
      session_timeout = 1800
    
    [[runners]]
      name = "detelme"
      url = "http://127.0.0.1:3000/"
      token = "HA4v3F9S2JZty1jyMZ45"
      executor = "docker"
      [runners.custom_build_dir]
      [runners.cache]
        [runners.cache.s3]
        [runners.cache.gcs]
      [runners.docker]
        tls_verify = false
        image = "alpine:3.11"
        privileged = false
        disable_entrypoint_overwrite = false
        oom_kill_disable = false
        disable_cache = false
        volumes = ["/cache"]
        shm_size = 0
    
        [[runners.docker.services]]
          name = "postgres:12-alpine"
  • Run a job and check that the service is available and running.

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 #6389 (closed)

Edited by Steve Xuereb

Merge request reports