Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compose & run v2 of compose #9

Closed
strazto opened this issue Jun 4, 2024 · 3 comments · Fixed by #13
Closed

Update compose & run v2 of compose #9

strazto opened this issue Jun 4, 2024 · 3 comments · Fixed by #13

Comments

@strazto
Copy link

strazto commented Jun 4, 2024

The current version of docker-compose is 0.23.5 :

"docker-compose": "^0.23.5"

Nevermind, it was actually the docker-compose binary on my runner

This version only supports the docker-compose v1 spec.

The latest version of the npm docker-compose supports v2, since v0.24.0

The compose spec added compose-spec/compose-spec#340 a yaml tag for resetting values in an override, for example

# docker-compose.base.yaml
services:
    db:
        # ... 
        build:
            context: db
        ports:
            - "5432:5432" 
        volumes:
            - aggregator-data:/var/lib/postgresql/data
# docker-compose.e2e.yaml
services:
    playwright:
      build:
        context: .
        dockerfile: ./Dockerfile.playwright
    # Disable ports
    db:
      ports: !reset []
      volumes: !reset []

This is useful in CI, as I want to use my compose stack to run e2e tests, and disable portforwarding + persistence so I can run multiple compose stacks in parallel on the same runner, ie:

name: E2E Test Stack
on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  test:
    timeout-minutes: 60
    runs-on:
      - self-hosted
      - builder
    steps:
    - uses: actions/checkout@v3
    - uses: adambirds/docker-compose-action@v1.3.0
      env:
        # Isolate different compose projects
        COMPOSE_PROJECT_NAME: "e2e-${{ github.run_id }}"
      with:
        compose-file: |
          docker-compose.base.yaml
          docker-compose.e2e.yaml
        test-container: playwright
        test-command: npx playwright test

Note that in the above, I disabled concurrency within the same branch, but the workflow may run concurrently for different branches.

Currently, I get the following error:

compose up failed {"exitCode":1,"err":"yaml.constructor.ConstructorError: could not determine a constructor for the tag '!reset'\n  in \"./docker-compose.e2e.yaml\", line 10, column 14\n","out":""}

I believe that using (or allowing) the v2 bindings may allow us to use new feature from the spec

Update - This can run docker-compose v2, however, the machine running this needs to alias docker-compose to the plugin binary.

A good enough way is to symlink it, https://stackoverflow.com/a/76909275/9238801

ln -f -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
@strazto
Copy link
Author

strazto commented Jun 4, 2024

For now, I'll just copy/paste my base config and edit out the port / volume bindings, but this would be ideal

@adambirds
Copy link
Owner

@strazto i'll take a look at all your suggestions in the next couple of weeks. But busy due to moving house but will get to when I can.

@mdugas
Copy link

mdugas commented Aug 8, 2024

GitHub made a breaking change on July 29th that rolled out from then until Aug 2, removing Compose v1 (docker-compose). (I believe this is what is causing issue #12 that was submitted today)

actions/runner-images#9692

Would you be open to have someone submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants