From 41bd5b12bd47fcaa735e2b895237665f43a2fa70 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 23 Apr 2021 09:54:17 -0400 Subject: [PATCH 1/5] 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}`)} From 63dffdd9f8fbc818a9ce118a425a32affd151a3e Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 23 Apr 2021 10:11:44 -0400 Subject: [PATCH 2/5] Split parameter --- post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post.js b/post.js index 063761a..163f531 100644 --- a/post.js +++ b/post.js @@ -4,7 +4,7 @@ const fs = require('fs'); try { const composeFile = core.getInput('compose-file'); - const downOptions = core.getInput('down-options'); + const downOptions = core.getInput('down-options').split(" "); if (!fs.existsSync(composeFile)) { console.log(`${composeFile} not exists`); From 4ee978ae61bdefee380d9d4fbb7a3b936b2a8f54 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 23 Apr 2021 10:25:03 -0400 Subject: [PATCH 3/5] Break out assembly of dict --- post.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/post.js b/post.js index 163f531..4b3ccb9 100644 --- a/post.js +++ b/post.js @@ -4,14 +4,19 @@ const fs = require('fs'); try { const composeFile = core.getInput('compose-file'); - const downOptions = core.getInput('down-options').split(" "); + const downOptionsString = core.getInput('down-options'); + + if (downOptionsString.length > 0) + let options = { config: composeFile, log: true, commandOptions: downOptionsString.split(" ") }; + else + let options = { config: composeFile, log: true}; if (!fs.existsSync(composeFile)) { console.log(`${composeFile} not exists`); return } - compose.down({ config: composeFile, log: true, commandOptions: downOptions }) + compose.down(options) .then( () => { console.log('compose removed')}, err => { core.setFailed(`compose down failed ${err}`)} From 9b11ac16a82450b178521ae165c7dfdbe5322ab3 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 23 Apr 2021 10:30:32 -0400 Subject: [PATCH 4/5] Fix dict assembly --- post.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/post.js b/post.js index 4b3ccb9..994865f 100644 --- a/post.js +++ b/post.js @@ -6,10 +6,9 @@ try { const composeFile = core.getInput('compose-file'); const downOptionsString = core.getInput('down-options'); + let options = { config: composeFile, log: true}; if (downOptionsString.length > 0) - let options = { config: composeFile, log: true, commandOptions: downOptionsString.split(" ") }; - else - let options = { config: composeFile, log: true}; + options['commandOptions'] = downOptionsString.split(" "); if (!fs.existsSync(composeFile)) { console.log(`${composeFile} not exists`); From 95610cce4b299c7587eda7b4af76d6861d23f614 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Sat, 24 Apr 2021 09:24:22 -0400 Subject: [PATCH 5/5] Clarify option name, add test volume to docker-compose.yml file --- .github/workflows/main.yml | 2 +- README.md | 4 ++-- action.yml | 2 +- docker/docker-compose.yml | 6 ++++++ post.js | 6 +++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b0a4f2..cac8fe0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,4 +9,4 @@ jobs: - uses: isbang/compose-action@v0.1 with: compose-file: './docker/docker-compose.yml' - down-options: '--volumes' + down-flags: '--volumes' diff --git a/README.md b/README.md index bccf368..0413137 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ 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` +### `down-flags` -**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. +**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 diff --git a/action.yml b/action.yml index 95b24a7..86209d1 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ inputs: description: 'relative path to compose file' required: false default: './docker-compose.yml' - down-options: # id of input + down-flags: # id of input description: 'additional options to pass to `docker-compose down` command' required: false default: '' diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 690e07f..9d5a4d6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,4 +1,10 @@ version: "3.8" + +volumes: + test_volume: {} + services: helloworld: image: hello-world + volumes: + - test_volume:/test:Z diff --git a/post.js b/post.js index 994865f..186b84c 100644 --- a/post.js +++ b/post.js @@ -4,11 +4,11 @@ const fs = require('fs'); try { const composeFile = core.getInput('compose-file'); - const downOptionsString = core.getInput('down-options'); + const downFlagsString = core.getInput('down-flags'); let options = { config: composeFile, log: true}; - if (downOptionsString.length > 0) - options['commandOptions'] = downOptionsString.split(" "); + if (downFlagsString.length > 0) + options['commandOptions'] = downFlagsString.split(" "); if (!fs.existsSync(composeFile)) { console.log(`${composeFile} not exists`);