Merge pull request #3 from thorrak/main

Add `down-options` configuration option
This commit is contained in:
Bang 2021-04-25 11:53:33 +09:00 committed by GitHub
commit 66c8a4ba71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 1 deletions

View File

@ -9,3 +9,4 @@ jobs:
- uses: isbang/compose-action@v0.1 - uses: isbang/compose-action@v0.1
with: with:
compose-file: './docker/docker-compose.yml' compose-file: './docker/docker-compose.yml'
down-flags: '--volumes'

View File

@ -8,6 +8,11 @@ This action runs your docker-compose file and clean up before action finished.
**Optional** The name of the compose file. Default `"./docker-compose.yml"`. **Optional** The name of the compose file. Default `"./docker-compose.yml"`.
### `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](https://docs.docker.com/compose/reference/down/).
## Example usage ## Example usage
```yaml ```yaml

View File

@ -5,6 +5,10 @@ inputs:
description: 'relative path to compose file' description: 'relative path to compose file'
required: false required: false
default: './docker-compose.yml' default: './docker-compose.yml'
down-flags: # id of input
description: 'additional options to pass to `docker-compose down` command'
required: false
default: ''
runs: runs:
using: 'node12' using: 'node12'
main: 'main.js' main: 'main.js'

View File

@ -1,4 +1,10 @@
version: "3.8" version: "3.8"
volumes:
test_volume: {}
services: services:
helloworld: helloworld:
image: hello-world image: hello-world
volumes:
- test_volume:/test:Z

View File

@ -4,13 +4,18 @@ const fs = require('fs');
try { try {
const composeFile = core.getInput('compose-file'); const composeFile = core.getInput('compose-file');
const downFlagsString = core.getInput('down-flags');
let options = { config: composeFile, log: true};
if (downFlagsString.length > 0)
options['commandOptions'] = downFlagsString.split(" ");
if (!fs.existsSync(composeFile)) { if (!fs.existsSync(composeFile)) {
console.log(`${composeFile} not exists`); console.log(`${composeFile} not exists`);
return return
} }
compose.down({ config: composeFile, log: true }) compose.down(options)
.then( .then(
() => { console.log('compose removed')}, () => { console.log('compose removed')},
err => { core.setFailed(`compose down failed ${err}`)} err => { core.setFailed(`compose down failed ${err}`)}