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 service label build options #429

Closed jquick closed 6 months ago

jquick commented 6 months ago

It would be really handy to be able to add service labels in the pipeline. This change allows labels to be defined for build or run.

This will add any defined labels to the compose override and those will be merged accordingly. Small example:

docker-compose.yml

services:
  app:
    build:
      context: .
      labels:
        - dev.pardot.docker.image-metadata=test-metadata

pipeline.yml

      - ${DOCKER_COMPOSE_PLUGIN}:
          build: app
          labels: 
            - dev.pardot.docker.test=test
            - dev.pardot.docker.test2=test2

image labels after build:

      "Labels": {
        "com.docker.compose.project": "buildkite018dd7eac0554b8eb556b2b206b874d0",
        "com.docker.compose.service": "app",
        "com.docker.compose.version": "2.12.2",
        "dev.pardot.docker.image-metadata": "test-metadata",
        "dev.pardot.docker.test": "test",
        "dev.pardot.docker.test2": "test2"
      }

Testing

I've done some basic Buldkite builds with different combinations of labels and cache_from.

Use Case

Our users setup their own compose files. As owners we want to ensure that every image is built with specific labels.

jquick commented 6 months ago

Thanks @toote! I really appreciate your feedback and help. I think I have addressed the style issues and ran a few builds on the new logic and it looks to work as expected. Since we are splitting out run/build I think having build-labels and the current run-labels should be sufficient for most cases.