mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-11 23:23: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
|
### Example Using environment variables
|
||||||
|
|
||||||
```yaml
|
```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`
|
### Example using `services`
|
||||||
|
|
||||||
Perform `docker compose up` to some given service instead of all of them
|
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`
|
### Example using `up-flags`
|
||||||
|
|
||||||
Specify flags to pass to the `docker compose up`. Default is none. Can be used
|
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`
|
### Example using `down-flags`
|
||||||
|
|
||||||
Specify flags to pass to the `docker-compose down` command during cleanup.
|
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`
|
### Example using `compose-flags`
|
||||||
|
|
||||||
Specify flags to pass to the `docker compose` command. Default is none. A full
|
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
|
- name: Act
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
docker-flags: "--context test-context"
|
||||||
compose-file: "./test/docker-compose.yml"
|
compose-file: "./test/docker-compose.yml"
|
||||||
compose-version: "latest"
|
compose-version: "latest"
|
||||||
|
|||||||
@ -12,7 +12,11 @@
|
|||||||
<!-- end title -->
|
<!-- end title -->
|
||||||
<!-- start badges -->
|
<!-- 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 -->
|
<!-- end badges -->
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
name: "Docker Compose Action"
|
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"
|
author: "Hoverkraft"
|
||||||
branding:
|
branding:
|
||||||
icon: anchor
|
icon: anchor
|
||||||
color: gray-dark
|
color: gray-dark
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
docker-flags:
|
||||||
|
description: "Additional options to pass to `docker` command."
|
||||||
|
required: false
|
||||||
compose-file:
|
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)."
|
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
|
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(`docker compose version: ${installedVersion}`);
|
||||||
loggerService.info("Bringing up docker compose service(s)");
|
loggerService.info("Bringing up docker compose service(s)");
|
||||||
await dockerComposeService.up({
|
await dockerComposeService.up({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
@ -33313,12 +33314,16 @@ class DockerComposeService {
|
|||||||
output: out,
|
output: out,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getCommonOptions({ composeFiles, composeFlags, cwd, debug, }) {
|
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||||
return {
|
return {
|
||||||
config: composeFiles,
|
config: composeFiles,
|
||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => debug(chunk.toString()),
|
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);
|
const path_1 = __nccwpck_require__(6928);
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
|
InputNames["DockerFlags"] = "docker-flags";
|
||||||
InputNames["ComposeFile"] = "compose-file";
|
InputNames["ComposeFile"] = "compose-file";
|
||||||
InputNames["Services"] = "services";
|
InputNames["Services"] = "services";
|
||||||
InputNames["ComposeFlags"] = "compose-flags";
|
InputNames["ComposeFlags"] = "compose-flags";
|
||||||
@ -33352,6 +33358,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
|||||||
class InputService {
|
class InputService {
|
||||||
getInputs() {
|
getInputs() {
|
||||||
return {
|
return {
|
||||||
|
dockerFlags: this.getDockerFlags(),
|
||||||
composeFiles: this.getComposeFiles(),
|
composeFiles: this.getComposeFiles(),
|
||||||
services: this.getServices(),
|
services: this.getServices(),
|
||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
@ -33362,6 +33369,9 @@ class InputService {
|
|||||||
githubToken: this.getGithubToken(),
|
githubToken: this.getGithubToken(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
getDockerFlags() {
|
||||||
|
return this.parseFlags((0, core_1.getInput)(InputNames.DockerFlags));
|
||||||
|
}
|
||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
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 dockerComposeService = new docker_compose_service_1.DockerComposeService();
|
||||||
const inputs = inputService.getInputs();
|
const inputs = inputService.getInputs();
|
||||||
const { error, output } = await dockerComposeService.logs({
|
const { error, output } = await dockerComposeService.logs({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
@ -26346,6 +26347,7 @@ async function run() {
|
|||||||
}
|
}
|
||||||
loggerService.debug("docker compose logs:\n" + output);
|
loggerService.debug("docker compose logs:\n" + output);
|
||||||
await dockerComposeService.down({
|
await dockerComposeService.down({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
@ -26401,12 +26403,16 @@ class DockerComposeService {
|
|||||||
output: out,
|
output: out,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getCommonOptions({ composeFiles, composeFlags, cwd, debug, }) {
|
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||||
return {
|
return {
|
||||||
config: composeFiles,
|
config: composeFiles,
|
||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => debug(chunk.toString()),
|
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);
|
const path_1 = __nccwpck_require__(6928);
|
||||||
var InputNames;
|
var InputNames;
|
||||||
(function (InputNames) {
|
(function (InputNames) {
|
||||||
|
InputNames["DockerFlags"] = "docker-flags";
|
||||||
InputNames["ComposeFile"] = "compose-file";
|
InputNames["ComposeFile"] = "compose-file";
|
||||||
InputNames["Services"] = "services";
|
InputNames["Services"] = "services";
|
||||||
InputNames["ComposeFlags"] = "compose-flags";
|
InputNames["ComposeFlags"] = "compose-flags";
|
||||||
@ -26440,6 +26447,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
|||||||
class InputService {
|
class InputService {
|
||||||
getInputs() {
|
getInputs() {
|
||||||
return {
|
return {
|
||||||
|
dockerFlags: this.getDockerFlags(),
|
||||||
composeFiles: this.getComposeFiles(),
|
composeFiles: this.getComposeFiles(),
|
||||||
services: this.getServices(),
|
services: this.getServices(),
|
||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
@ -26450,6 +26458,9 @@ class InputService {
|
|||||||
githubToken: this.getGithubToken(),
|
githubToken: this.getGithubToken(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
getDockerFlags() {
|
||||||
|
return this.parseFlags((0, core_1.getInput)(InputNames.DockerFlags));
|
||||||
|
}
|
||||||
getComposeFiles() {
|
getComposeFiles() {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = (0, core_1.getMultilineInput)(InputNames.ComposeFile).filter((composeFile) => {
|
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 () => {
|
it("should install docker compose with specified version", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -49,7 +50,7 @@ describe("run", () => {
|
|||||||
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
||||||
|
|
||||||
expect(debugMock).toHaveBeenCalledWith(
|
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({
|
expect(installMock).toHaveBeenCalledWith({
|
||||||
@ -59,6 +60,7 @@ describe("run", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(upMock).toHaveBeenCalledWith({
|
expect(upMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
@ -73,6 +75,7 @@ describe("run", () => {
|
|||||||
it("should bring up docker compose services", async () => {
|
it("should bring up docker compose services", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -88,6 +91,7 @@ describe("run", () => {
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(upMock).toHaveBeenCalledWith({
|
expect(upMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
@ -104,6 +108,7 @@ describe("run", () => {
|
|||||||
upMock.mockRejectedValue(error);
|
upMock.mockRejectedValue(error);
|
||||||
|
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -127,6 +132,7 @@ describe("run", () => {
|
|||||||
upMock.mockRejectedValue(error);
|
upMock.mockRejectedValue(error);
|
||||||
|
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export async function run(): Promise<void> {
|
|||||||
|
|
||||||
loggerService.info("Bringing up docker compose service(s)");
|
loggerService.info("Bringing up docker compose service(s)");
|
||||||
await dockerComposeService.up({
|
await dockerComposeService.up({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
|
|||||||
@ -25,6 +25,7 @@ describe("index", () => {
|
|||||||
|
|
||||||
it("calls run when imported", async () => {
|
it("calls run when imported", async () => {
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -48,12 +49,13 @@ describe("index", () => {
|
|||||||
// Verify that all of the functions were called correctly
|
// Verify that all of the functions were called correctly
|
||||||
expect(debugMock).toHaveBeenNthCalledWith(
|
expect(debugMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
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(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
|
||||||
|
|
||||||
expect(upMock).toHaveBeenCalledWith({
|
expect(upMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
|
|||||||
@ -27,6 +27,7 @@ describe("run", () => {
|
|||||||
it("should bring down docker compose service(s) and log output", async () => {
|
it("should bring down docker compose service(s) and log output", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -46,6 +47,7 @@ describe("run", () => {
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(logsMock).toHaveBeenCalledWith({
|
expect(logsMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
@ -54,6 +56,7 @@ describe("run", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
@ -71,6 +74,7 @@ describe("run", () => {
|
|||||||
it("should log docker composer errors if any", async () => {
|
it("should log docker composer errors if any", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -96,6 +100,7 @@ describe("run", () => {
|
|||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
|
dockerFlags: [],
|
||||||
services: [],
|
services: [],
|
||||||
debug: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
@ -104,6 +109,7 @@ describe("run", () => {
|
|||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
|
dockerFlags: [],
|
||||||
downFlags: [],
|
downFlags: [],
|
||||||
debug: debugMock,
|
debug: debugMock,
|
||||||
});
|
});
|
||||||
@ -133,6 +139,7 @@ describe("run", () => {
|
|||||||
downMock.mockRejectedValue(error);
|
downMock.mockRejectedValue(error);
|
||||||
|
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -156,6 +163,7 @@ describe("run", () => {
|
|||||||
downMock.mockRejectedValue(error);
|
downMock.mockRejectedValue(error);
|
||||||
|
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["web"],
|
services: ["web"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export async function run(): Promise<void> {
|
|||||||
const inputs = inputService.getInputs();
|
const inputs = inputService.getInputs();
|
||||||
|
|
||||||
const { error, output } = await dockerComposeService.logs({
|
const { error, output } = await dockerComposeService.logs({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
@ -30,6 +31,7 @@ export async function run(): Promise<void> {
|
|||||||
loggerService.debug("docker compose logs:\n" + output);
|
loggerService.debug("docker compose logs:\n" + output);
|
||||||
|
|
||||||
await dockerComposeService.down({
|
await dockerComposeService.down({
|
||||||
|
dockerFlags: inputs.dockerFlags,
|
||||||
composeFiles: inputs.composeFiles,
|
composeFiles: inputs.composeFiles,
|
||||||
composeFlags: inputs.composeFlags,
|
composeFlags: inputs.composeFlags,
|
||||||
cwd: inputs.cwd,
|
cwd: inputs.cwd,
|
||||||
|
|||||||
@ -24,6 +24,7 @@ describe("post", () => {
|
|||||||
|
|
||||||
it("calls run when imported", async () => {
|
it("calls run when imported", async () => {
|
||||||
getInputsMock.mockImplementation(() => ({
|
getInputsMock.mockImplementation(() => ({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -42,6 +43,7 @@ describe("post", () => {
|
|||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
expect(logsMock).toHaveBeenCalledWith({
|
expect(logsMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
@ -50,6 +52,7 @@ describe("post", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(downMock).toHaveBeenCalledWith({
|
expect(downMock).toHaveBeenCalledWith({
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
|
|||||||
@ -25,6 +25,7 @@ describe("DockerComposeService", () => {
|
|||||||
describe("up", () => {
|
describe("up", () => {
|
||||||
it("should call up with correct options", async () => {
|
it("should call up with correct options", async () => {
|
||||||
const upInputs: UpInputs = {
|
const upInputs: UpInputs = {
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: [],
|
services: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -39,6 +40,36 @@ describe("DockerComposeService", () => {
|
|||||||
composeOptions: [],
|
composeOptions: [],
|
||||||
commandOptions: [],
|
commandOptions: [],
|
||||||
config: ["docker-compose.yml"],
|
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",
|
cwd: "/current/working/dir",
|
||||||
callback: expect.any(Function),
|
callback: expect.any(Function),
|
||||||
});
|
});
|
||||||
@ -46,6 +77,7 @@ describe("DockerComposeService", () => {
|
|||||||
|
|
||||||
it("should call up with specific services", async () => {
|
it("should call up with specific services", async () => {
|
||||||
const upInputs: UpInputs = {
|
const upInputs: UpInputs = {
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["helloworld2", "helloworld3"],
|
services: ["helloworld2", "helloworld3"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -62,6 +94,10 @@ describe("DockerComposeService", () => {
|
|||||||
config: ["docker-compose.yml"],
|
config: ["docker-compose.yml"],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
callback: expect.any(Function),
|
callback: expect.any(Function),
|
||||||
|
executable: {
|
||||||
|
executablePath: "docker",
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -69,6 +105,7 @@ describe("DockerComposeService", () => {
|
|||||||
describe("down", () => {
|
describe("down", () => {
|
||||||
it("should call down with correct options", async () => {
|
it("should call down with correct options", async () => {
|
||||||
const downInputs: DownInputs = {
|
const downInputs: DownInputs = {
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: [],
|
composeFiles: [],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
downFlags: ["--volumes", "--remove-orphans"],
|
downFlags: ["--volumes", "--remove-orphans"],
|
||||||
@ -82,6 +119,10 @@ describe("DockerComposeService", () => {
|
|||||||
composeOptions: [],
|
composeOptions: [],
|
||||||
commandOptions: ["--volumes", "--remove-orphans"],
|
commandOptions: ["--volumes", "--remove-orphans"],
|
||||||
config: [],
|
config: [],
|
||||||
|
executable: {
|
||||||
|
executablePath: "docker",
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
callback: expect.any(Function),
|
callback: expect.any(Function),
|
||||||
});
|
});
|
||||||
@ -92,6 +133,7 @@ describe("DockerComposeService", () => {
|
|||||||
it("should call logs with correct options", async () => {
|
it("should call logs with correct options", async () => {
|
||||||
const debugMock = jest.fn();
|
const debugMock = jest.fn();
|
||||||
const logsInputs: LogsInputs = {
|
const logsInputs: LogsInputs = {
|
||||||
|
dockerFlags: [],
|
||||||
composeFiles: ["docker-compose.yml"],
|
composeFiles: ["docker-compose.yml"],
|
||||||
services: ["helloworld2", "helloworld3"],
|
services: ["helloworld2", "helloworld3"],
|
||||||
composeFlags: [],
|
composeFlags: [],
|
||||||
@ -107,6 +149,10 @@ describe("DockerComposeService", () => {
|
|||||||
composeOptions: [],
|
composeOptions: [],
|
||||||
config: ["docker-compose.yml"],
|
config: ["docker-compose.yml"],
|
||||||
cwd: "/current/working/dir",
|
cwd: "/current/working/dir",
|
||||||
|
executable: {
|
||||||
|
executablePath: "docker",
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
follow: false,
|
follow: false,
|
||||||
callback: expect.any(Function),
|
callback: expect.any(Function),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
import { Inputs } from "./input.service";
|
import { Inputs } from "./input.service";
|
||||||
|
|
||||||
type OptionsInputs = {
|
type OptionsInputs = {
|
||||||
|
dockerFlags: Inputs["dockerFlags"];
|
||||||
composeFiles: Inputs["composeFiles"];
|
composeFiles: Inputs["composeFiles"];
|
||||||
composeFlags: Inputs["composeFlags"];
|
composeFlags: Inputs["composeFlags"];
|
||||||
cwd: Inputs["cwd"];
|
cwd: Inputs["cwd"];
|
||||||
@ -61,6 +62,7 @@ export class DockerComposeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getCommonOptions({
|
private getCommonOptions({
|
||||||
|
dockerFlags,
|
||||||
composeFiles,
|
composeFiles,
|
||||||
composeFlags,
|
composeFlags,
|
||||||
cwd,
|
cwd,
|
||||||
@ -71,6 +73,10 @@ export class DockerComposeService {
|
|||||||
composeOptions: composeFlags,
|
composeOptions: composeFlags,
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
callback: (chunk) => debug(chunk.toString()),
|
callback: (chunk) => debug(chunk.toString()),
|
||||||
|
executable: {
|
||||||
|
executablePath: "docker",
|
||||||
|
options: dockerFlags,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,53 @@ describe("InputService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getInputs", () => {
|
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", () => {
|
describe("composeFiles", () => {
|
||||||
it("should return given composeFiles input", () => {
|
it("should return given composeFiles input", () => {
|
||||||
getMultilineInputMock.mockImplementation((inputName) => {
|
getMultilineInputMock.mockImplementation((inputName) => {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { existsSync } from "fs";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
export type Inputs = {
|
export type Inputs = {
|
||||||
|
dockerFlags: string[];
|
||||||
composeFiles: string[];
|
composeFiles: string[];
|
||||||
services: string[];
|
services: string[];
|
||||||
composeFlags: string[];
|
composeFlags: string[];
|
||||||
@ -14,6 +15,7 @@ export type Inputs = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export enum InputNames {
|
export enum InputNames {
|
||||||
|
DockerFlags = "docker-flags",
|
||||||
ComposeFile = "compose-file",
|
ComposeFile = "compose-file",
|
||||||
Services = "services",
|
Services = "services",
|
||||||
ComposeFlags = "compose-flags",
|
ComposeFlags = "compose-flags",
|
||||||
@ -29,6 +31,7 @@ export const COMPOSE_VERSION_LATEST = "latest";
|
|||||||
export class InputService {
|
export class InputService {
|
||||||
getInputs(): Inputs {
|
getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
|
dockerFlags: this.getDockerFlags(),
|
||||||
composeFiles: this.getComposeFiles(),
|
composeFiles: this.getComposeFiles(),
|
||||||
services: this.getServices(),
|
services: this.getServices(),
|
||||||
composeFlags: this.getComposeFlags(),
|
composeFlags: this.getComposeFlags(),
|
||||||
@ -40,6 +43,10 @@ export class InputService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getDockerFlags(): string[] {
|
||||||
|
return this.parseFlags(getInput(InputNames.DockerFlags));
|
||||||
|
}
|
||||||
|
|
||||||
private getComposeFiles(): string[] {
|
private getComposeFiles(): string[] {
|
||||||
const cwd = this.getCwd();
|
const cwd = this.getCwd();
|
||||||
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter((composeFile: string) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user