Service dependency support

Description

When configuring multiple services for a CI/CD job, it is common for services to have dependencies on one another. For example, a backend service may require a database service to be fully operational before it can start. Currently, there is no built-in way in GitLab CI to explicitly declare such dependencies and control the startup order of services.

Proposal

Introduce a mechanism to allow services to declare dependencies using a depends_on attribute (similar to Docker Compose). This would ensure that a service only starts after all its dependencies are running and healthy.

Example Usage:

e2e:
  services:
    - my-db
    - name: my-backend
      depends_on:
        - my-db
  script:
    - ...

In the example above, the my-backend service will not start until the my-db service is up and its healthcheck has succeeded.

Implementation Plan

In GitLab:

  • Introduce a feature flag, e.g., ci_service_dependencies, to gate this feature.
  • Add support for specifying a depends_on string array for services in .gitlab-ci.yml.
  • Expose the depends_on attribute in the API model for communication with the runner.

In GitLab Runner:

  • Update the API model to support deserializing the new depends_on attribute.
  • Modify service orchestration logic to:
    • Respect the declared dependencies,
    • Start services in the correct order,
    • Wait for successful healthchecks of dependencies before starting dependent services.

Please review the proposed implementation plan and let me know if you have any feedback or suggestions. Once approved, I’d like to begin working on this feature.

none