Giter Club home page Giter Club logo

docker-compose-action's Introduction

Docker Compose Action

This action runs your docker-compose file, allows you to run tests and cleans up before action finished.

Inputs

compose-file

Optional The name of the compose file. Default "./docker-compose.yml".

It can be a list of files:

compose-file: |
  docker-compose.yml
  docker-compose.ci.yml

services

Optional Just perform docker-compose up to one service instead of all of them

up-flags

Optional Used to specify flags to pass to the docker-compose up. Default is none. Can be used to pass the --build flag, for example, if you want persistent volumes to be deleted as well during cleanup. A full list of flags can be found in the docker-compose up documentation.

down-flags

Optional Used to specify flags to pass to the docker-compose down command during cleanup. Default is none. Can be used to pass the --volumes flag, for example, if you want persistent volumes to be deleted as well during cleanup. A full list of flags can be found in the docker-compose down documentation.

compose-flags

Optional Used to specify flags to pass to the docker-compose command. Default is none. A full list of flags can be found in the docker-compose documentation.

test-container

Optional Used to specify the container to run the tests in. Default is none. If not specified, no tests will be run.

test-command

Optional Used to specify the command to run the tests with. Default is none. If not specified, no tests will be run.

Example usage

steps:
  # need checkout before using docker-compose-action
  - uses: actions/checkout@v3
  - uses: adambirds/[email protected]
    with:
      compose-file: "./docker/docker-compose.yml"
      down-flags: "--volumes"
      services: |
        helloworld2
        helloworld3
      test-container: helloworld
      test-command: "npm test"

Using environment variables

steps:
  - uses: actions/checkout@v3
  - uses: adambirds/[email protected]
    with:
      compose-file: "./docker/docker-compose.yml"
    env:
      CUSTOM_VARIABLE: "test"

Run tests on multiple containers

steps:
  - uses: actions/checkout@v3
  - uses: adambirds/[email protected]
    with:
      compose-file: "./docker/docker-compose.yml"
      test-container: "container1"
      test-command: "npm test"

  - uses: adambirds/[email protected]
    with:
      compose-file: "./docker/docker-compose.yml"
      test-container: "container2"
      test-command: "npm test"

  - uses: adambirds/[email protected]
    with:
      compose-file: "./docker/docker-compose.yml"
      test-container: "container3"
      test-command: "npm test"

docker-compose-action's People

Contributors

adambirds avatar gghcode avatar isbang avatar neilime avatar oldsneerjaw avatar razvanz avatar ricglz avatar rpede avatar thorrak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

docker-compose-action's Issues

When testing locally with act tool getting error

::error::compose up failed {"errno":-2,"code":"ENOENT","syscall":"spawn docker-compose","path":"docker-compose","spawnargs":["-f","./docker-compose.yml","up","-d"]}

Here we are trying to spawn docker-compose but as per latest version it's docker compose

Make error annotation configurable

On a failed test, the error annotation is used, which is basically the error stringified.

core.setFailed(`tests failed ${JSON.stringify(err)}`);

Some test runners natively support logging errors to github action annotations, so this extra failure annotation is redundant, and noisy.

It'd be nice if it was optional

Sporadic failure with run command - not deterministic

My test command randomly fails. I have test-command: "yarn run test". Which works - but not always. It will fail, then I re-run failed jobs and it passes (with no code change).

When it fails, it says jest is not found (what I run my tests via).

Here's some output:

compose started
testContainer app
testCommand yarn run test
yarn run v1.22.19
$ NODE_ENV=TESTING jest --detectOpenHandles
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

/bin/sh: jest: not found
error Command failed with exit code 127.

Error: tests failed {"exitCode":127,"err":"/bin/sh: jest: not found\nerror Command failed with exit code 127.\n","out":"yarn run v1.22.19\n$ NODE_ENV=TESTING jest --detectOpenHandles\ninfo Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.\n"}

And here's my innocuous test script (from within a package.json file):
"test": "NODE_ENV=TESTING jest --detectOpenHandles",

And here's the whole task runner:

  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: adambirds/[email protected]
        with:
          compose-file: "./docker-compose-test.yml"
          down-flags: "--volumes"
          test-container: app
          test-command: "yarn run test"
          ```

Any idea what could be causing this, or how to address?

Failure with no output if test container does not have a running service

For the following:

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/[email protected]
      env:
        # Isolate different compose projects
        COMPOSE_PROJECT_NAME: "e2e-${{ github.run_id }}"
      with:
        compose-file: |
          docker-compose.no-bind.yaml
          docker-compose.e2e.yaml
        test-container: playwright
        test-command: npm run 'test:e2e'

I get the following logs (after creating the whole stack incl. the playwright container)

compose started
testContainer playwright
testCommand npm run 'test:e2e'
Error: tests failed {"exitCode":1,"err":"","out":""}

playwright dockerfile:

FROM mcr.microsoft.com/playwright:v1.44.1-jammy

WORKDIR /app
ADD package.json package-lock.json .

RUN npm ci

ADD playwright.config.ts .
ADD tests ./tests
# docker-compose.e2e.yaml

services:
    playwright:
      #image: mcr.microsoft.com/playwright:v1.44.1-jammy
      build:
        context: .
        dockerfile: ./Dockerfile.playwright

I suspect its because you use docker.exec for running the test command, and my playwright container doesn't have an ongoing entrypoint, so terminates immediately.

const test = compose.exec(testContainer, testCommand, {

the test container should not be required to have a running entry point IMO, maybe can use .run instead or allow config to allow .run

Update compose & run v2 of compose

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/[email protected]
      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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.