buildkite-plugins / docker-compose-buildkite-plugin

🐳⚡️ Run build scripts, and build + push images, w/ Docker Compose
MIT License
171 stars 138 forks source link

Add metadata key prefix to support builds with independent clusters/registries #432

Closed donbobka closed 6 days ago

donbobka commented 5 months ago

In scenarios where agent clusters are isolated from each other, with each cluster responsible for building its own image and pushing it to its respective image registry, there is a potential race condition that can lead to errors during separate run/push steps. Specifically, one of the steps may attempt to pull an image from the wrong image registry due to shared metadata across all clusters.

To mitigate it and ensure that each cluster is building and running images from the correct image registry, I propose introducing a new metadata_key_prefix parameter. This parameter would allow users to specify a unique prefix for the metadata keys used by the plugin, effectively isolating the metadata for each agent cluster.

example

docker-compose.yml

version: '3.10'
service:
  app:
    build: .

pipeline.yml

steps:
  - name: ":docker: Build staging image"
    key: "build_staging"
    plugins:
      ... docker login plugin into registry ${IMAGE_REPO_STAGING} ...
      - docker-compose#v5.2.0:
          build: app
          push: app:${IMAGE_REPO_STAGING}:${BUILD_TAG}
          metadata_key_prefix: "staging"
    agents:
      queue: staging-agents

  - name: ":docker: Build production image"
    key: "build_production"
    plugins:
      ... docker login plugin into registry ${IMAGE_REPO_PRODUCTION} ...
      - docker-compose#v5.2.0:
          build: app
          push: app:${IMAGE_REPO_PRODUCTION}:${BUILD_TAG}
          metadata_key_prefix: "production"
    agents:
      queue: staging-production

  - name: ":docker: run staging image"
    key: "run_staging"
    depends_on:
      - build_staging
    plugins:
      ... docker login plugin into registry ${IMAGE_REPO_STAGING} ...
      - docker-compose#v5.2.0:
          run: app
          metadata_key_prefix: "staging"
    agents:
      queue: staging-agents

  - name: ":docker: run production image"
    key: "run_production"
    depends_on:
      - build_production
    plugins:
      ... docker login plugin into registry ${IMAGE_REPO_PRODUCTION} ...
      - docker-compose#v5.2.0:
          run: app
          metadata_key_prefix: "production"
    agents:
      queue: staging-production