Skip to content

Expand container related options before they are used

What does this MR do?

Ths MR ensures all container related options are expanded before they are used. Specifically, the following options are expanded

  • Build
    • image.name
    • image.alias
    • services.name
    • services.alias
  • Docker Executor
    • image
    • helper-image
    • services.name
    • services.alias
    • container-labels
  • Kubernetes Executor
    • image
    • helper-image
    • services.name
    • services.alias
    • kubernetesOptions.image.name
    • kubernetesOptions.image.alias
    • kubernetesOptions.services.image.name
    • kubernetesOptions.services.image.alias

Note that some of these options we already being expanded before this MR, but only at the point of use in a piecemeal fashion, which lead to #29499 (closed)

I chose the executor's Prepare method a hook to trigger the expansion as it seemed like a reasonable and safe place.

Why was this MR needed?

Over in #29499 (closed), Services failed to start because the services' image names and aliases where specified as variables, and those options were not expanded uniformly. Having container related options point to variables is allowed for many options, so we must support it uniformly for all container options.

What's the best way to test this MR?

There are three combinations to tests, where container options point to variables in:

  1. job/pipeline config
  2. docker executor runner config
  3. kubernetes executor runner config

Pipeline Config

stages
  - build

variables:
  DB_SERVICE: postgres:latest
  DB_SERVICE_ALIAS: db
  POSTGRES_PASSWORD: password
  IMAGE: alpine:latest

compile:
  stage: build
  image:
    name: $IMAGE
  services:
    - name: $DB_SERVICE
      alias: $DB_SERVICE_ALIAS,shaba
  script:
    - ping $DB_SERVICE_ALIAS -w 5
    - ping shaba -w 5

Docker Executor Config

Here there are two variations:

  1. The Variables are defined in .gitlab-ci.yaml
  2. The variables are defined in the runner config

The relevant variables are: DB_SERVICE = "postgres:latest" DB_SERVICE_ALIAS = "db" POSTGRES_PASSWORD = "password" IMAGE = "alpine:latest"

In both cases, the simplified version of the above job can be used:

stages
  - build

compile:
  stage: build
  script:
    - ping $DB_SERVICE_ALIAS -w 5
    - ping shaba -w 5
...
[[runners]]
  ...
  executor = "docker"
  [runners.docker]
    image = "$IMAGE"
    [[runners.docker.services]]
      name = "$DB_SERVICE"
      alias = "$DB_SERVICE_ALIAS"

Kubernetes Executor Config

This is identical to the docker executor case above, but the relevant executor config is:

...
[[runners]]
  ...
  executor = "kubernetes"
  [runners.kubernetes]
    ...
    image = "$IMAGE"
    [[runners.kubernetes.services]]
      name = "$DB_SERVICE"
      alias = "$DB_SERVICE_ALIAS"

What are the relevant issue numbers?

closes #29499 (closed)

Notes

  • Best reviewed commit at a time
  • Still working on unit and integration tests, but has been tested manually. tests added.
Edited by Axel von Bertoldi

Merge request reports