Skip to content

Resolve "support all options from `docker-compose.yml` in gitlab runner services"

What does this MR do and why?

Currently, the only way to pass environment variables to a Docker/Kubernetes service during CI is to provide them inside the job's variables. This MR adds the possibility to declare an additional set of variables for the services, making them closer to the docker-compose spec.

Please note that it's my very first time using Ruby so there might be some issues that I'd be glad to fix with your help.

How to set up and validate locally

  1. Setup a new project

  2. Create a new .gitlab-ci.yml file with the following contents

    image: busybox:latest
    
    variables:
       GIT_STRATEGY: none
    
    stages:
       - build
    
    Build With A Service And Some Variables:
       stage: build
       image: curlimages/curl
       services:
       - name: ealen/echo-server:latest
         alias: echo-server
         variables:
           PORT: 5000
           ENABLE__ENVIRONMENT: 'true'
           ENV_VAR_FOR_SERVICE: "This is a variable passed to the service"
       script:
         - curl echo-server:5000/?echo_env_body=ENV_VAR_FOR_SERVICE
    
    Build With A Service And No Variables:
       stage: build
       image: curlimages/curl
       services:
       - name: ealen/echo-server:latest
         alias: echo-server
       script:
         - curl echo-server:80/
    
    Build Without A Service:
       stage: build
       image: busybox:latest
       script:
         - echo "Build Without A Service"
  3. The CI file is correctly validated by the linter

  4. It can also be tested by building and using a runner with the code from gitlab-runner!3158 (closed)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #23671

Edited by Matija Čupić

Merge request reports