Compare commits

...

3 Commits

Author SHA1 Message Date
Emilien Escalle
d3ad8ec3be feat: add docker flags input
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-01-21 22:01:57 +01:00
Emilien Escalle
49c8cfd612 fix: npm security issue 2025-01-21 16:28:09 +00:00
Emilien Escalle
99df94c183 docs; use docker compose wording instead of docker-compose 2025-01-21 16:27:29 +00:00
21 changed files with 228 additions and 49 deletions

View File

@ -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

View File

@ -1,7 +1,8 @@
<!-- 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
```yaml ```yaml
steps: steps:

View File

@ -1,7 +1,8 @@
<!-- 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
to pass the `--build` flag, for example, if you want persistent volumes to be to pass the `--build` flag, for example, if you want persistent volumes to be
deleted as well during cleanup. A full list of flags can be found in the deleted as well during cleanup. A full list of flags can be found in the
[docker-compose up documentation](https://docs.docker.com/compose/reference/up/). [docker compose up documentation](https://docs.docker.com/compose/reference/up/).

View File

@ -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.

View File

@ -1,9 +1,10 @@
<!-- 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
list of flags can be found in the list of flags can be found in the
[docker-compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help). [docker compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help).
```yaml ```yaml
steps: steps:

View File

@ -254,3 +254,21 @@ jobs:
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version" echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1 exit 1
fi fi
test-action-with-docker-context:
runs-on: ubuntu-latest
name: Test with docker context
steps:
- uses: actions/checkout@v4
- name: Set up Docker
uses: docker/setup-docker-action@v4
with:
context: test-context
- name: Act
uses: ./
with:
docker-flags: "--context test-context"
compose-file: "./test/docker-compose.yml"
compose-version: "latest"

View File

@ -12,14 +12,18 @@
<!-- 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 -->
</div> </div>
<!-- start description --> <!-- start description -->
This action runs your docker-compose file and clean up before action finished This action runs your [docker compose](https://docs.docker.com/reference/compose-file/) file and clean up before action finished
<!-- end description --> <!-- end description -->
@ -30,16 +34,16 @@ This action runs your docker-compose file and clean up before action finished
### Action ### Action
The action will run `docker-compose up` to start the services defined in the given compose file(s). The action will run `docker compose up` to start the services defined in the given compose file(s).
The compose file(s) can be specified using the `compose-file` input. The compose file(s) can be specified using the `compose-file` input.
Some extra options can be passed to the `docker-compose up` command using the `up-flags` input. Some extra options can be passed to the `docker compose up` command using the `up-flags` input.
### Post hook ### Post hook
On post hook, the action will run `docker-compose down` to clean up the services. On post hook, the action will run `docker compose down` to clean up the services.
In debug mode, the logs of the running services are printed before the cleanup. In debug mode, the logs of the running services are printed before the cleanup.
Some extra options can be passed to the `docker-compose down` command using the `down-flags` input. Some extra options can be passed to the `docker compose down` command using the `down-flags` input.
<!-- start usage --> <!-- start usage -->
@ -52,21 +56,21 @@ Some extra options can be passed to the `docker-compose down` command using the
# Default: ./docker-compose.yml # Default: ./docker-compose.yml
compose-file: "" compose-file: ""
# Description: Services to perform docker-compose up. # Description: Services to perform docker compose up.
# #
services: "" services: ""
# Description: Additional options to pass to `docker-compose up` command. # Description: Additional options to pass to `docker compose up` command.
# #
# Default: # Default:
up-flags: "" up-flags: ""
# Description: Additional options to pass to `docker-compose down` command. # Description: Additional options to pass to `docker compose down` command.
# #
# Default: # Default:
down-flags: "" down-flags: ""
# Description: Additional options to pass to `docker-compose` command. # Description: Additional options to pass to `docker compose` command.
# #
# Default: # Default:
compose-flags: "" compose-flags: ""
@ -82,7 +86,7 @@ Some extra options can be passed to the `docker-compose down` command using the
compose-version: "" compose-version: ""
# Description: The GitHub token used to create an authenticated client (to fetch # Description: The GitHub token used to create an authenticated client (to fetch
# the latest version of docker-compose). # the latest version of docker compose).
# #
# Default: ${{ github.token }} # Default: ${{ github.token }}
github-token: "" github-token: ""
@ -97,13 +101,13 @@ Some extra options can be passed to the `docker-compose down` command using the
| **Input** | **Description** | **Default** | **Required** | | **Input** | **Description** | **Default** | **Required** |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ | | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ | ------------ |
| <code>compose-file</code> | Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd). | <code>./docker-compose.yml</code> | **false** | | <code>compose-file</code> | Path to compose file(s). It can be a list of files. It can be absolute or relative to the current working directory (cwd). | <code>./docker-compose.yml</code> | **false** |
| <code>services</code> | Services to perform docker-compose up. | | **false** | | <code>services</code> | Services to perform docker compose up. | | **false** |
| <code>up-flags</code> | Additional options to pass to <code>docker-compose up</code> command. | | **false** | | <code>up-flags</code> | Additional options to pass to <code>docker compose up</code> command. | | **false** |
| <code>down-flags</code> | Additional options to pass to <code>docker-compose down</code> command. | | **false** | | <code>down-flags</code> | Additional options to pass to <code>docker compose down</code> command. | | **false** |
| <code>compose-flags</code> | Additional options to pass to <code>docker-compose</code> command. | | **false** | | <code>compose-flags</code> | Additional options to pass to <code>docker compose</code> command. | | **false** |
| <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** | | <code>cwd</code> | Current working directory | <code>${{ github.workspace }}</code> | **false** |
| <code>compose-version</code> | Compose version to use.<br />If null (default), it will use the current installed version.<br />If "latest", it will install the latest version. | | **false** | | <code>compose-version</code> | Compose version to use.<br />If null (default), it will use the current installed version.<br />If "latest", it will install the latest version. | | **false** |
| <code>github-token</code> | The GitHub token used to create an authenticated client (to fetch the latest version of docker-compose). | <code>${{ github.token }}</code> | **false** | | <code>github-token</code> | The GitHub token used to create an authenticated client (to fetch the latest version of docker compose). | <code>${{ github.token }}</code> | **false** |
<!-- end inputs --> <!-- end inputs -->
<!-- start outputs --> <!-- start outputs -->
@ -125,14 +129,14 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Run docker-compose - name: Run docker compose
uses: hoverkraft-tech/compose-action@v2.0.1 uses: hoverkraft-tech/compose-action@v2.0.1
with: with:
compose-file: "./docker/docker-compose.yml" compose-file: "./docker/docker-compose.yml"
- name: Execute tests in the running services - name: Execute tests in the running services
run: | run: |
docker-compose exec test-app pytest docker compose exec test-app pytest
``` ```
<!-- start [.github/ghadocs/examples/] --> <!-- start [.github/ghadocs/examples/] -->
@ -152,7 +156,7 @@ steps:
### 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
```yaml ```yaml
steps: steps:
@ -168,24 +172,24 @@ steps:
### 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
to pass the `--build` flag, for example, if you want persistent volumes to be to pass the `--build` flag, for example, if you want persistent volumes to be
deleted as well during cleanup. A full list of flags can be found in the deleted as well during cleanup. A full list of flags can be found in the
[docker-compose up documentation](https://docs.docker.com/compose/reference/up/). [docker compose up documentation](https://docs.docker.com/compose/reference/up/).
### 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.
Default is none. Can be used to pass the `--volumes` flag, for example, if you Default is none. Can be used to pass the `--volumes` flag, for example, if you
want persistent volumes to be deleted as well during cleanup. A full list of want persistent volumes to be deleted as well during cleanup. A full list of
flags can be found in the flags can be found in the
[docker-compose down documentation](https://docs.docker.com/compose/reference/down/). [docker compose down documentation](https://docs.docker.com/compose/reference/down/).
### 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
list of flags can be found in the list of flags can be found in the
[docker-compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help). [docker compose documentation](https://docs.docker.com/compose/reference/#command-options-overview-and-help).
```yaml ```yaml
steps: steps:

View File

@ -1,28 +1,31 @@
name: "Docker Compose Action" name: "Docker Compose Action"
description: "This action runs your docker-compose file and clean up before action finished" description: "This action runs your compose file 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
default: "./docker-compose.yml" default: "./docker-compose.yml"
services: services:
description: "Services to perform docker-compose up." description: "Services to perform docker compose up."
required: false required: false
up-flags: up-flags:
description: "Additional options to pass to `docker-compose up` command." description: "Additional options to pass to `docker compose up` command."
required: false required: false
default: "" default: ""
down-flags: down-flags:
description: "Additional options to pass to `docker-compose down` command." description: "Additional options to pass to `docker compose down` command."
required: false required: false
default: "" default: ""
compose-flags: compose-flags:
description: "Additional options to pass to `docker-compose` command." description: "Additional options to pass to `docker compose` command."
required: false required: false
default: "" default: ""
cwd: cwd:
@ -36,7 +39,7 @@ inputs:
If "latest", it will install the latest version. If "latest", it will install the latest version.
required: false required: false
github-token: github-token:
description: The GitHub token used to create an authenticated client (to fetch the latest version of docker-compose). description: The GitHub token used to create an authenticated client (to fetch the latest version of docker compose).
default: ${{ github.token }} default: ${{ github.token }}
required: false required: false

12
dist/index.js generated vendored
View File

@ -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,
@ -33312,12 +33313,16 @@ class DockerComposeService {
output: out, output: out,
}; };
} }
getCommonOptions({ composeFiles, composeFlags, cwd, }) { getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
return { return {
config: composeFiles, config: composeFiles,
log: true, log: true,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
executable: {
executablePath: "docker",
options: dockerFlags,
},
}; };
} }
} }
@ -33338,6 +33343,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";
@ -33351,6 +33357,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(),
@ -33361,6 +33368,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
View File

@ -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,
@ -26345,6 +26346,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,
@ -26399,12 +26401,16 @@ class DockerComposeService {
output: out, output: out,
}; };
} }
getCommonOptions({ composeFiles, composeFlags, cwd, }) { getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
return { return {
config: composeFiles, config: composeFiles,
log: true, log: true,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
executable: {
executablePath: "docker",
options: dockerFlags,
},
}; };
} }
} }
@ -26425,6 +26431,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";
@ -26438,6 +26445,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(),
@ -26448,6 +26456,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) => {

7
package-lock.json generated
View File

@ -3216,10 +3216,11 @@
} }
}, },
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.3", "version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"path-key": "^3.1.0", "path-key": "^3.1.0",
"shebang-command": "^2.0.0", "shebang-command": "^2.0.0",

View File

@ -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",
@ -72,6 +74,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: [],
@ -87,6 +90,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",
@ -102,6 +106,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: [],
@ -125,6 +130,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: [],

View File

@ -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,

View File

@ -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: [],

View File

@ -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",
@ -53,6 +55,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",
@ -69,6 +72,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: [],
@ -94,6 +98,7 @@ describe("run", () => {
composeFiles: ["docker-compose.yml"], composeFiles: ["docker-compose.yml"],
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
dockerFlags: [],
services: [], services: [],
}); });
@ -101,6 +106,7 @@ describe("run", () => {
composeFiles: ["docker-compose.yml"], composeFiles: ["docker-compose.yml"],
composeFlags: [], composeFlags: [],
cwd: "/current/working/dir", cwd: "/current/working/dir",
dockerFlags: [],
downFlags: [], downFlags: [],
}); });
@ -129,6 +135,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: [],
@ -152,6 +159,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: [],

View File

@ -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,
@ -29,6 +30,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,

View File

@ -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",
@ -49,6 +51,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",

View File

@ -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: [],
@ -38,6 +39,35 @@ describe("DockerComposeService", () => {
composeOptions: [], composeOptions: [],
commandOptions: [], commandOptions: [],
config: ["docker-compose.yml"], config: ["docker-compose.yml"],
executable: {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
});
});
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",
};
await service.up(upInputs);
expect(upAllMock).toHaveBeenCalledWith({
composeOptions: [],
commandOptions: [],
config: ["docker-compose.yml"],
executable: {
executablePath: "docker",
options: ["--context", "dev"],
},
log: true, log: true,
cwd: "/current/working/dir", cwd: "/current/working/dir",
}); });
@ -45,6 +75,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: [],
@ -58,8 +89,12 @@ describe("DockerComposeService", () => {
composeOptions: [], composeOptions: [],
commandOptions: ["--build"], commandOptions: ["--build"],
config: ["docker-compose.yml"], config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir", cwd: "/current/working/dir",
executable: {
executablePath: "docker",
options: [],
},
log: true,
}); });
}); });
}); });
@ -67,6 +102,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"],
@ -79,6 +115,10 @@ describe("DockerComposeService", () => {
composeOptions: [], composeOptions: [],
commandOptions: ["--volumes", "--remove-orphans"], commandOptions: ["--volumes", "--remove-orphans"],
config: [], config: [],
executable: {
executablePath: "docker",
options: [],
},
log: true, log: true,
cwd: "/current/working/dir", cwd: "/current/working/dir",
}); });
@ -88,6 +128,7 @@ describe("DockerComposeService", () => {
describe("logs", () => { describe("logs", () => {
it("should call logs with correct options", async () => { it("should call logs with correct options", async () => {
const logsInputs: LogsInputs = { const logsInputs: LogsInputs = {
dockerFlags: [],
composeFiles: ["docker-compose.yml"], composeFiles: ["docker-compose.yml"],
services: ["helloworld2", "helloworld3"], services: ["helloworld2", "helloworld3"],
composeFlags: [], composeFlags: [],
@ -103,6 +144,10 @@ describe("DockerComposeService", () => {
config: ["docker-compose.yml"], config: ["docker-compose.yml"],
log: true, log: true,
cwd: "/current/working/dir", cwd: "/current/working/dir",
executable: {
executablePath: "docker",
options: [],
},
follow: false, follow: false,
}); });
}); });

View File

@ -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"];
@ -60,6 +61,7 @@ export class DockerComposeService {
} }
private getCommonOptions({ private getCommonOptions({
dockerFlags,
composeFiles, composeFiles,
composeFlags, composeFlags,
cwd, cwd,
@ -69,6 +71,10 @@ export class DockerComposeService {
log: true, log: true,
composeOptions: composeFlags, composeOptions: composeFlags,
cwd: cwd, cwd: cwd,
executable: {
executablePath: "docker",
options: dockerFlags,
},
}; };
} }
} }

View File

@ -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) => {

View File

@ -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) => {