This action provides support for running docker compose with enforced cleanup after the job finished.
Requires docker-compose
to be installed and available on the PATH
.
Uses the following github context environment variables to generate unique docker-compose project names:
GITHUB_REPOSITORY
GITHUB_RUN_ID
GITHUB_RUN_NUMBER
Name | default | required | description |
---|---|---|---|
composeFile | docker-compose.yml |
no | The path to the docker-compose file(s) to use, relative to the workspace. In multiple docker-compose files case, add them as multiline yaml value using the ` |
serviceName | yes | The name of the service to use defined in the compose file. | |
composeCommand | up |
no | One of up or run as the main compose command to execute. |
composeArguments | --abort-on-container-exit |
no | Option flags passed to the compose command. |
runCommand | no | Command to run in the container when composeCommand is 'run'; ignored otherwise. | |
build | false | no | Explicitly build the service image before running. Implies pull before build. |
push | on:push | no | When to push the built image to the registry. 'on:push' means when the trigger event it a push to the branch. Otherwise true/false. Only runs if 'build' is true. |
Name | description |
---|---|
container_id | The docker ID of the service container run. |
- Run
docker-compose -p <project> pull <service>
- If
build
istrue
:- Run
docker-compose -p <project> build <service>
- Run
- Run the main command:
- For
up
command, rundocker-compose -p <project> up <args> <service>
- For
run
command, rundocker-compose -p <project> run <args> <service> <run-command>
- For
- As a post-build step, do cleanup:
- If
build
istrue
andpush
resolves totrue
:- Run
docker-compose -p <project> push <service>
- Ignore failures of this command to continue with cleanup
- Run
- Run
docker-compose -p <project> down --remove-orphans --volumes
- Ignore failures of this command to continue with cleanup
- Run
docker-compose -p <project> rm -f
- Ignore failures of this command to continue with cleanup
- If any errors were encountered during cleanup, fail the build.
- If
name: Test with compose
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Test with docker-compose
uses: smartlyio/docker-compose-action@v1
with:
composeFile: |
docker-compose.yml
docker-compose.ci.yml
serviceName: test
build: true
push: "on:push"
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build && npm run package
Run the tests ✔️
$ npm test
PASS ./compose.test.js
✓ ...
...