Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for compose flags #7

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
volumes:
- test_volume:/test:Z
helloworld2:
profiles: [profile-1]
image: hello-world
helloworld3:
profiles: [profile-2]
image: hello-world
11 changes: 7 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() => {
Expand Down
7 changes: 3 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
@@ -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 [];
};