mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-10 22:53:06 +08:00
feat: add support for compose flags (#7)
Add support for options (eg: --profile) to be passed to docker-compose.
This commit is contained in:
parent
65ecb06558
commit
ada3c6c7cd
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
main.js
11
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
|
||||
|
||||
8
post.js
8
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(
|
||||
() => {
|
||||
|
||||
7
utils.js
7
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 [];
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user