From 41bd5b12bd47fcaa735e2b895237665f43a2fa70 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 23 Apr 2021 09:54:17 -0400 Subject: [PATCH] Add `down-options` configuration option This new, optional configuration parameter allows for the specification of flags to be passed to the `docker-compose down` command. This is primarily intended to be used for passing the `--volumes` flag whith instructs docker-compose to also delete persistent volumes. --- .github/workflows/main.yml | 1 + README.md | 5 +++++ action.yml | 4 ++++ post.js | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fdaa739..4b0a4f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,3 +9,4 @@ jobs: - uses: isbang/compose-action@v0.1 with: compose-file: './docker/docker-compose.yml' + down-options: '--volumes' diff --git a/README.md b/README.md index 311ff4b..bccf368 100644 --- a/README.md +++ b/README.md @@ -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"`. +### `down-options` + +**Optional** Options to pass to the `docker-compose down` command during cleanup. Default is none. Primarily used to pass the `--volumes` flag if you want persistent volumes to be deleted as well during cleanup. + + ## Example usage ```yaml diff --git a/action.yml b/action.yml index d922ce3..95b24a7 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ inputs: description: 'relative path to compose file' required: false default: './docker-compose.yml' + down-options: # id of input + description: 'additional options to pass to `docker-compose down` command' + required: false + default: '' runs: using: 'node12' main: 'main.js' diff --git a/post.js b/post.js index f786de3..063761a 100644 --- a/post.js +++ b/post.js @@ -4,13 +4,14 @@ const fs = require('fs'); try { const composeFile = core.getInput('compose-file'); + const downOptions = core.getInput('down-options'); if (!fs.existsSync(composeFile)) { console.log(`${composeFile} not exists`); return } - compose.down({ config: composeFile, log: true }) + compose.down({ config: composeFile, log: true, commandOptions: downOptions }) .then( () => { console.log('compose removed')}, err => { core.setFailed(`compose down failed ${err}`)}