From d3da412a74b5dffbba3d5478c8ab583be7ed0268 Mon Sep 17 00:00:00 2001 From: Razvan Laurus Date: Tue, 23 Aug 2022 20:29:21 +0200 Subject: [PATCH] feat: add support for compose flags Add support for options (eg: --profile) to be passed to docker-compose. --- .github/workflows/main.yml | 5 +++++ action.yml | 4 ++++ docker/docker-compose.yml | 2 ++ main.js | 11 +++++++---- post.js | 8 ++++++-- utils.js | 7 +++---- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8371df..b19f9f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,3 +20,8 @@ jobs: with: compose-file: "./docker/docker-compose.yml" down-flags: "--volumes" + - uses: ./ + with: + compose-file: "./docker/docker-compose.yml" + compose-flags: "--profile profile-1" + down-flags: "--volumes" diff --git a/action.yml b/action.yml index 6b1e865..ee1f4c2 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ inputs: description: "relative path to compose file" required: false default: "./docker-compose.yml" + compose-flags: # id of input + description: "additional options to pass to `docker-compose` command" + required: false + default: "" down-flags: # id of input description: "additional options to pass to `docker-compose down` command" required: false diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 567bb2d..6cb6c1e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,6 +9,8 @@ services: volumes: - test_volume:/test:Z helloworld2: + profiles: [profile-1] image: hello-world helloworld3: + profiles: [profile-2] image: hello-world diff --git a/main.js b/main.js index 565364a..a9a30f1 100644 --- a/main.js +++ b/main.js @@ -11,10 +11,13 @@ try { return; } - const services = core.getMultilineInput("services", { required: false }); - - const upFlagsString = core.getInput("up-flags"); - const options = utils.getOptions(composeFile, upFlagsString); + const services = core.getMultilineInput("services", { required: false });; + const options = { + config: composeFile, + log: true, + composeOptions: utils.parseFlags(core.getInput("compose-flags")), + commandOptions: utils.parseFlags(core.getInput("up-flags")) + }; const promise = services.length > 0 diff --git a/post.js b/post.js index 7c4693a..23301ba 100644 --- a/post.js +++ b/post.js @@ -10,8 +10,12 @@ try { return; } - const downFlagsString = core.getInput("down-flags"); - const options = utils.getOptions(composeFile, downFlagsString); + const options = { + config: composeFile, + log: true, + composeOptions: utils.parseFlags(core.getInput("compose-flags")), + commandOptions: utils.parseFlags(core.getInput("up-flags")) + }; compose.down(options).then( () => { diff --git a/utils.js b/utils.js index 740610e..13451b1 100644 --- a/utils.js +++ b/utils.js @@ -1,8 +1,7 @@ -module.exports.getOptions = (composeFile, flags) => { - const options = { config: composeFile, log: true }; +module.exports.parseFlags = (flags) => { if (flags != null && typeof flags == "string" && flags.length > 0) { - options["commandOptions"] = flags.split(" "); + return flags.split(" "); } - return options; + return []; };