buildkite-plugins / docker-compose-buildkite-plugin

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

Dependency containers run twice when using service_completed_successfully #365

Closed xzyfer closed 1 year ago

xzyfer commented 1 year ago

When using the service_completed_successfully in docker-compose.yaml with the dependencies: true the dependency container can run multiple due to use of scale=0.

services:
  testrunner:
    build: .
    depends_on:
      seeder:
        condition: service_completed_successfully
      db:
        condition: service_started

  seeder:
    image: alpine:latest
    command: ['sh', 'seeder.sh']
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres
    healthcheck:
      test: psql -e "SELECT 1;"
      interval: 10s
      timeout: 10s
      retries: 5

When this plugin starts the dependencies using the before, it execute the seeder container

docker-compose up -d --scale "testrunner=0" testrunner

When it then runs the service container which has a condition: service_completed_successfully on the seeder container, it results in the seedercontainer running a second time.

This is behaviour is unexpected and problematic for containers that aren't re-entrant. It's also appears multiple execution behaviour is racey as it doesn't happen for every run.

Is it possible to remove the --scale "testrunner=0" behaviour when dependencies: true or at least make it possible to disable via configuration? I understand for backwards compatibility reasons changing the existing default behaviour may be problematic, and condition: service_completed_successfully is relatively new feature.

toote commented 1 year ago

@xzyfer that is indeed an interesting use case... I had a written out explanation as to how your use-case was unique and an outlier and when I went in to link up the parts of the code to back up everything I said I realized you were right.

I am thinking of adding a new option so that you can optionally turn off the part of the code that starts dependencies before the main container (with a warning as that may cause logs to be quite messy or errors)

xzyfer commented 1 year ago

I appreciate your thoroughness.