mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-10 22:53:06 +08:00
feat: add docker flags input
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
parent
5bc973d473
commit
2c587abdb1
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example Using environment variables
|
||||
|
||||
```yaml
|
||||
|
||||
3
.github/ghadocs/examples/2_services.md
vendored
3
.github/ghadocs/examples/2_services.md
vendored
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example using `services`
|
||||
|
||||
Perform `docker compose up` to some given service instead of all of them
|
||||
|
||||
3
.github/ghadocs/examples/3_up-flags.md
vendored
3
.github/ghadocs/examples/3_up-flags.md
vendored
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example using `up-flags`
|
||||
|
||||
Specify flags to pass to the `docker compose up`. Default is none. Can be used
|
||||
|
||||
3
.github/ghadocs/examples/4_down-flags.md
vendored
3
.github/ghadocs/examples/4_down-flags.md
vendored
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example using `down-flags`
|
||||
|
||||
Specify flags to pass to the `docker-compose down` command during cleanup.
|
||||
|
||||
3
.github/ghadocs/examples/5_compose-flags.md
vendored
3
.github/ghadocs/examples/5_compose-flags.md
vendored
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example using `compose-flags`
|
||||
|
||||
Specify flags to pass to the `docker compose` command. Default is none. A full
|
||||
|
||||
1
.github/workflows/__check-action.yml
vendored
1
.github/workflows/__check-action.yml
vendored
@ -269,5 +269,6 @@ jobs:
|
||||
- name: Act
|
||||
uses: ./
|
||||
with:
|
||||
docker-flags: "--context test-context"
|
||||
compose-file: "./test/docker-compose.yml"
|
||||
compose-version: "latest"
|
||||
|
||||
@ -12,7 +12,11 @@
|
||||
<!-- end title -->
|
||||
<!-- start badges -->
|
||||
|
||||
<a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/v/release/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20tag" /></a><a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/release-date/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20date" /></a><img src="https://img.shields.io/github/last-commit/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Commit" /><a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Fissues"><img src="https://img.shields.io/github/issues/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Open%20Issues" /></a><img src="https://img.shields.io/github/downloads/hoverkraft-tech/compose-action/total?logo=github&style=flat-square" alt="Downloads" />
|
||||
<a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/v/release/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20tag" /></a>
|
||||
<a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Freleases%2Flatest"><img src="https://img.shields.io/github/release-date/hoverkraft-tech/compose-action?display_name=tag&sort=semver&logo=github&style=flat-square" alt="Release%20by%20date" /></a>
|
||||
<img src="https://img.shields.io/github/last-commit/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Commit" />
|
||||
<a href="https%3A%2F%2Fgithub.com%2Fhoverkraft-tech%2Fcompose-action%2Fissues"><img src="https://img.shields.io/github/issues/hoverkraft-tech/compose-action?logo=github&style=flat-square" alt="Open%20Issues" /></a>
|
||||
<img src="https://img.shields.io/github/downloads/hoverkraft-tech/compose-action/total?logo=github&style=flat-square" alt="Downloads" />
|
||||
|
||||
<!-- end badges -->
|
||||
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
name: "Docker Compose Action"
|
||||
description: "This action runs your compose file and clean up before action finished"
|
||||
description: "This action runs your compose file(s) and clean up before action finished"
|
||||
author: "Hoverkraft"
|
||||
branding:
|
||||
icon: anchor
|
||||
color: gray-dark
|
||||
|
||||
inputs:
|
||||
docker-flags:
|
||||
description: "Additional options to pass to `docker` command."
|
||||
required: false
|
||||
compose-file:
|
||||
description: "Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd)."
|
||||
required: false
|
||||
|
||||
12
dist/index.js
generated
vendored
12
dist/index.js
generated
vendored
@ -33172,6 +33172,7 @@ async function run() {
|
||||
loggerService.info(`docker compose version: ${installedVersion}`);
|
||||
loggerService.info("Bringing up docker compose service(s)");
|
||||
await dockerComposeService.up({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
@ -33313,12 +33314,16 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ composeFiles, composeFlags, cwd, debug, }) {
|
||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||
return {
|
||||
config: composeFiles,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => debug(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -33339,6 +33344,7 @@ const fs_1 = __nccwpck_require__(9896);
|
||||
const path_1 = __nccwpck_require__(6928);
|
||||
var InputNames;
|
||||
(function (InputNames) {
|
||||
InputNames["DockerFlags"] = "docker-flags";
|
||||
InputNames["ComposeFile"] = "compose-file";
|
||||
InputNames["Services"] = "services";
|
||||
InputNames["ComposeFlags"] = "compose-flags";
|
||||
@ -33352,6 +33358,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
||||
class InputService {
|
||||
getInputs() {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
@ -33362,6 +33369,9 @@ class InputService {
|
||||
githubToken: this.getGithubToken(),
|
||||
};
|
||||
}
|
||||
getDockerFlags() {
|
||||
return this.parseFlags((0, core_1.getInput)(InputNames.DockerFlags));
|
||||
}
|
||||
getComposeFiles() {
|
||||
const cwd = this.getCwd();
|
||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||
|
||||
13
dist/post.js
generated
vendored
13
dist/post.js
generated
vendored
@ -26335,6 +26335,7 @@ async function run() {
|
||||
const dockerComposeService = new docker_compose_service_1.DockerComposeService();
|
||||
const inputs = inputService.getInputs();
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
@ -26346,6 +26347,7 @@ async function run() {
|
||||
}
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
await dockerComposeService.down({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
@ -26401,12 +26403,16 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ composeFiles, composeFlags, cwd, debug, }) {
|
||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||
return {
|
||||
config: composeFiles,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => debug(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -26427,6 +26433,7 @@ const fs_1 = __nccwpck_require__(9896);
|
||||
const path_1 = __nccwpck_require__(6928);
|
||||
var InputNames;
|
||||
(function (InputNames) {
|
||||
InputNames["DockerFlags"] = "docker-flags";
|
||||
InputNames["ComposeFile"] = "compose-file";
|
||||
InputNames["Services"] = "services";
|
||||
InputNames["ComposeFlags"] = "compose-flags";
|
||||
@ -26440,6 +26447,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
||||
class InputService {
|
||||
getInputs() {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
@ -26450,6 +26458,9 @@ class InputService {
|
||||
githubToken: this.getGithubToken(),
|
||||
};
|
||||
}
|
||||
getDockerFlags() {
|
||||
return this.parseFlags((0, core_1.getInput)(InputNames.DockerFlags));
|
||||
}
|
||||
getComposeFiles() {
|
||||
const cwd = this.getCwd();
|
||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
||||
|
||||
@ -28,6 +28,7 @@ describe("run", () => {
|
||||
it("should install docker compose with specified version", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -49,7 +50,7 @@ describe("run", () => {
|
||||
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
|
||||
);
|
||||
|
||||
expect(installMock).toHaveBeenCalledWith({
|
||||
@ -59,6 +60,7 @@ describe("run", () => {
|
||||
});
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
@ -73,6 +75,7 @@ describe("run", () => {
|
||||
it("should bring up docker compose services", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -88,6 +91,7 @@ describe("run", () => {
|
||||
|
||||
// Assert
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
@ -104,6 +108,7 @@ describe("run", () => {
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -127,6 +132,7 @@ describe("run", () => {
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
|
||||
@ -36,6 +36,7 @@ export async function run(): Promise<void> {
|
||||
|
||||
loggerService.info("Bringing up docker compose service(s)");
|
||||
await dockerComposeService.up({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
|
||||
@ -25,6 +25,7 @@ describe("index", () => {
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -48,12 +49,13 @@ describe("index", () => {
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null}'
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null}'
|
||||
);
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
|
||||
@ -27,6 +27,7 @@ describe("run", () => {
|
||||
it("should bring down docker compose service(s) and log output", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -46,6 +47,7 @@ describe("run", () => {
|
||||
|
||||
// Assert
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
@ -54,6 +56,7 @@ describe("run", () => {
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
@ -71,6 +74,7 @@ describe("run", () => {
|
||||
it("should log docker composer errors if any", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -96,6 +100,7 @@ describe("run", () => {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
@ -104,6 +109,7 @@ describe("run", () => {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
@ -133,6 +139,7 @@ describe("run", () => {
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -156,6 +163,7 @@ describe("run", () => {
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
|
||||
@ -16,6 +16,7 @@ export async function run(): Promise<void> {
|
||||
const inputs = inputService.getInputs();
|
||||
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
@ -30,6 +31,7 @@ export async function run(): Promise<void> {
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
|
||||
await dockerComposeService.down({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
|
||||
@ -24,6 +24,7 @@ describe("post", () => {
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -42,6 +43,7 @@ describe("post", () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
@ -50,6 +52,7 @@ describe("post", () => {
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
|
||||
@ -25,6 +25,7 @@ describe("DockerComposeService", () => {
|
||||
describe("up", () => {
|
||||
it("should call up with correct options", async () => {
|
||||
const upInputs: UpInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -39,6 +40,36 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it("should call up with specific docker flags", async () => {
|
||||
const upInputs: UpInputs = {
|
||||
dockerFlags: ["--context", "dev"],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: ["--context", "dev"],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
@ -46,6 +77,7 @@ describe("DockerComposeService", () => {
|
||||
|
||||
it("should call up with specific services", async () => {
|
||||
const upInputs: UpInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
@ -62,6 +94,10 @@ describe("DockerComposeService", () => {
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -69,6 +105,7 @@ describe("DockerComposeService", () => {
|
||||
describe("down", () => {
|
||||
it("should call down with correct options", async () => {
|
||||
const downInputs: DownInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: [],
|
||||
composeFlags: [],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
@ -82,6 +119,10 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
commandOptions: ["--volumes", "--remove-orphans"],
|
||||
config: [],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
@ -92,6 +133,7 @@ describe("DockerComposeService", () => {
|
||||
it("should call logs with correct options", async () => {
|
||||
const debugMock = jest.fn();
|
||||
const logsInputs: LogsInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
@ -107,6 +149,10 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
follow: false,
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
import { Inputs } from "./input.service";
|
||||
|
||||
type OptionsInputs = {
|
||||
dockerFlags: Inputs["dockerFlags"];
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
@ -61,6 +62,7 @@ export class DockerComposeService {
|
||||
}
|
||||
|
||||
private getCommonOptions({
|
||||
dockerFlags,
|
||||
composeFiles,
|
||||
composeFlags,
|
||||
cwd,
|
||||
@ -71,6 +73,10 @@ export class DockerComposeService {
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => debug(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,53 @@ describe("InputService", () => {
|
||||
});
|
||||
|
||||
describe("getInputs", () => {
|
||||
describe("docker-flags", () => {
|
||||
it("should return given docker-flags input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.DockerFlags:
|
||||
return "docker-flag1 docker-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual(["docker-flag1", "docker-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no docker-flags input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composeFiles", () => {
|
||||
it("should return given composeFiles input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
|
||||
@ -3,6 +3,7 @@ import { existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
export type Inputs = {
|
||||
dockerFlags: string[];
|
||||
composeFiles: string[];
|
||||
services: string[];
|
||||
composeFlags: string[];
|
||||
@ -14,6 +15,7 @@ export type Inputs = {
|
||||
};
|
||||
|
||||
export enum InputNames {
|
||||
DockerFlags = "docker-flags",
|
||||
ComposeFile = "compose-file",
|
||||
Services = "services",
|
||||
ComposeFlags = "compose-flags",
|
||||
@ -29,6 +31,7 @@ export const COMPOSE_VERSION_LATEST = "latest";
|
||||
export class InputService {
|
||||
getInputs(): Inputs {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
@ -40,6 +43,10 @@ export class InputService {
|
||||
};
|
||||
}
|
||||
|
||||
private getDockerFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.DockerFlags));
|
||||
}
|
||||
|
||||
private getComposeFiles(): string[] {
|
||||
const cwd = this.getCwd();
|
||||
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user