mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-14 16:43:07 +08:00
Compare commits
5 Commits
d3ad8ec3be
...
b2d60131ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2d60131ea | ||
|
|
ca5588083a | ||
|
|
d24334d10a | ||
|
|
0807b14987 | ||
|
|
765986dd3e |
@ -1,4 +1,5 @@
|
||||
<!-- markdownlint-disable-next-line first-line-heading -->
|
||||
<!-- markdownlint-disable first-line-heading -->
|
||||
|
||||
### Example Using environment variables
|
||||
|
||||
```yaml
|
||||
|
||||
5
.github/ghadocs/examples/2_services.md
vendored
5
.github/ghadocs/examples/2_services.md
vendored
@ -1,7 +1,8 @@
|
||||
<!-- 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
|
||||
Perform `docker compose up` to some given service instead of all of them
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
|
||||
7
.github/ghadocs/examples/3_up-flags.md
vendored
7
.github/ghadocs/examples/3_up-flags.md
vendored
@ -1,7 +1,8 @@
|
||||
<!-- 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
|
||||
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
|
||||
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/).
|
||||
|
||||
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.
|
||||
|
||||
7
.github/ghadocs/examples/5_compose-flags.md
vendored
7
.github/ghadocs/examples/5_compose-flags.md
vendored
@ -1,9 +1,10 @@
|
||||
<!-- 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
|
||||
Specify flags to pass to the `docker compose` command. Default is none. A full
|
||||
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
|
||||
steps:
|
||||
|
||||
18
.github/workflows/__check-action.yml
vendored
18
.github/workflows/__check-action.yml
vendored
@ -254,3 +254,21 @@ jobs:
|
||||
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
|
||||
exit 1
|
||||
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"
|
||||
|
||||
56
README.md
56
README.md
@ -12,14 +12,18 @@
|
||||
<!-- 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 -->
|
||||
|
||||
</div>
|
||||
<!-- 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 -->
|
||||
|
||||
@ -30,16 +34,16 @@ This action runs your docker-compose file and clean up before action finished
|
||||
|
||||
### 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.
|
||||
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
|
||||
|
||||
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.
|
||||
On post hook, the action will run `docker compose down` to clean up the services.
|
||||
In [debug mode](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging), 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 -->
|
||||
|
||||
@ -52,21 +56,21 @@ Some extra options can be passed to the `docker-compose down` command using the
|
||||
# Default: ./docker-compose.yml
|
||||
compose-file: ""
|
||||
|
||||
# Description: Services to perform docker-compose up.
|
||||
# Description: Services to perform docker compose up.
|
||||
#
|
||||
services: ""
|
||||
|
||||
# Description: Additional options to pass to `docker-compose up` command.
|
||||
# Description: Additional options to pass to `docker compose up` command.
|
||||
#
|
||||
# Default:
|
||||
up-flags: ""
|
||||
|
||||
# Description: Additional options to pass to `docker-compose down` command.
|
||||
# Description: Additional options to pass to `docker compose down` command.
|
||||
#
|
||||
# Default:
|
||||
down-flags: ""
|
||||
|
||||
# Description: Additional options to pass to `docker-compose` command.
|
||||
# Description: Additional options to pass to `docker compose` command.
|
||||
#
|
||||
# Default:
|
||||
compose-flags: ""
|
||||
@ -82,7 +86,7 @@ Some extra options can be passed to the `docker-compose down` command using the
|
||||
compose-version: ""
|
||||
|
||||
# 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 }}
|
||||
github-token: ""
|
||||
@ -97,13 +101,13 @@ Some extra options can be passed to the `docker-compose down` command using the
|
||||
| **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>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>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>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>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>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>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 -->
|
||||
<!-- start outputs -->
|
||||
@ -125,14 +129,14 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run docker-compose
|
||||
- name: Run docker compose
|
||||
uses: hoverkraft-tech/compose-action@v2.0.1
|
||||
with:
|
||||
compose-file: "./docker/docker-compose.yml"
|
||||
|
||||
- name: Execute tests in the running services
|
||||
run: |
|
||||
docker-compose exec test-app pytest
|
||||
docker compose exec test-app pytest
|
||||
```
|
||||
|
||||
<!-- start [.github/ghadocs/examples/] -->
|
||||
@ -152,7 +156,7 @@ steps:
|
||||
|
||||
### 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
|
||||
steps:
|
||||
@ -168,24 +172,24 @@ steps:
|
||||
|
||||
### 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
|
||||
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`
|
||||
|
||||
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
|
||||
want persistent volumes to be deleted as well during cleanup. A full list of
|
||||
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`
|
||||
|
||||
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
|
||||
[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
|
||||
steps:
|
||||
|
||||
15
action.yml
15
action.yml
@ -1,28 +1,31 @@
|
||||
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(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
|
||||
default: "./docker-compose.yml"
|
||||
services:
|
||||
description: "Services to perform docker-compose up."
|
||||
description: "Services to perform docker compose up."
|
||||
required: false
|
||||
up-flags:
|
||||
description: "Additional options to pass to `docker-compose up` command."
|
||||
description: "Additional options to pass to `docker compose up` command."
|
||||
required: false
|
||||
default: ""
|
||||
down-flags:
|
||||
description: "Additional options to pass to `docker-compose down` command."
|
||||
description: "Additional options to pass to `docker compose down` command."
|
||||
required: false
|
||||
default: ""
|
||||
compose-flags:
|
||||
description: "Additional options to pass to `docker-compose` command."
|
||||
description: "Additional options to pass to `docker compose` command."
|
||||
required: false
|
||||
default: ""
|
||||
cwd:
|
||||
@ -36,7 +39,7 @@ inputs:
|
||||
If "latest", it will install the latest version.
|
||||
required: false
|
||||
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 }}
|
||||
required: false
|
||||
|
||||
|
||||
15
dist/index.js
generated
vendored
15
dist/index.js
generated
vendored
@ -33172,11 +33172,13 @@ 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,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
}
|
||||
@ -33312,12 +33314,16 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ composeFiles, composeFlags, cwd, }) {
|
||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||
return {
|
||||
config: composeFiles,
|
||||
log: true,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => debug(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -33338,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";
|
||||
@ -33351,6 +33358,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
||||
class InputService {
|
||||
getInputs() {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
@ -33361,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) => {
|
||||
|
||||
17
dist/post.js
generated
vendored
17
dist/post.js
generated
vendored
@ -26335,20 +26335,24 @@ 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,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
if (error) {
|
||||
loggerService.debug("docker compose error:\n" + error);
|
||||
}
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
await dockerComposeService.down({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose is down");
|
||||
}
|
||||
@ -26399,12 +26403,16 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ composeFiles, composeFlags, cwd, }) {
|
||||
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
|
||||
return {
|
||||
config: composeFiles,
|
||||
log: true,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => debug(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -26425,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";
|
||||
@ -26438,6 +26447,7 @@ exports.COMPOSE_VERSION_LATEST = "latest";
|
||||
class InputService {
|
||||
getInputs() {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
@ -26448,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) => {
|
||||
|
||||
7
package-lock.json
generated
7
package-lock.json
generated
@ -3216,10 +3216,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-key": "^3.1.0",
|
||||
"shebang-command": "^2.0.0",
|
||||
|
||||
@ -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,11 +60,13 @@ describe("run", () => {
|
||||
});
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
@ -72,6 +75,7 @@ describe("run", () => {
|
||||
it("should bring up docker compose services", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -87,11 +91,13 @@ describe("run", () => {
|
||||
|
||||
// Assert
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: ["web"],
|
||||
debug: debugMock,
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@ -102,6 +108,7 @@ describe("run", () => {
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -125,6 +132,7 @@ describe("run", () => {
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
|
||||
@ -36,11 +36,13 @@ 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,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
} catch (error) {
|
||||
|
||||
@ -25,6 +25,7 @@ describe("index", () => {
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -48,17 +49,19 @@ 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: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
|
||||
@ -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,17 +47,21 @@ describe("run", () => {
|
||||
|
||||
// Assert
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
||||
@ -69,6 +74,7 @@ describe("run", () => {
|
||||
it("should log docker composer errors if any", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -94,14 +100,18 @@ describe("run", () => {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
|
||||
@ -129,6 +139,7 @@ describe("run", () => {
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
@ -152,6 +163,7 @@ describe("run", () => {
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
|
||||
@ -16,10 +16,12 @@ 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,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
@ -29,10 +31,12 @@ 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,
|
||||
downFlags: inputs.downFlags,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
|
||||
loggerService.info("docker compose is down");
|
||||
|
||||
@ -24,6 +24,7 @@ describe("post", () => {
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
@ -42,17 +43,21 @@ describe("post", () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
|
||||
|
||||
@ -25,11 +25,13 @@ describe("DockerComposeService", () => {
|
||||
describe("up", () => {
|
||||
it("should call up with correct options", async () => {
|
||||
const upInputs: UpInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
@ -38,18 +40,50 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
log: true,
|
||||
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),
|
||||
});
|
||||
});
|
||||
|
||||
it("should call up with specific services", async () => {
|
||||
const upInputs: UpInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
upFlags: ["--build"],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
@ -58,8 +92,12 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
commandOptions: ["--build"],
|
||||
config: ["docker-compose.yml"],
|
||||
log: true,
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -67,10 +105,12 @@ describe("DockerComposeService", () => {
|
||||
describe("down", () => {
|
||||
it("should call down with correct options", async () => {
|
||||
const downInputs: DownInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: [],
|
||||
composeFlags: [],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.down(downInputs);
|
||||
@ -79,19 +119,26 @@ describe("DockerComposeService", () => {
|
||||
composeOptions: [],
|
||||
commandOptions: ["--volumes", "--remove-orphans"],
|
||||
config: [],
|
||||
log: true,
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("logs", () => {
|
||||
it("should call logs with correct options", async () => {
|
||||
const debugMock = jest.fn();
|
||||
const logsInputs: LogsInputs = {
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: debugMock,
|
||||
};
|
||||
|
||||
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
||||
@ -101,9 +148,13 @@ describe("DockerComposeService", () => {
|
||||
expect(dockerCompose.logs).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
log: true,
|
||||
cwd: "/current/working/dir",
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
follow: false,
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,9 +9,11 @@ import {
|
||||
import { Inputs } from "./input.service";
|
||||
|
||||
type OptionsInputs = {
|
||||
dockerFlags: Inputs["dockerFlags"];
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
debug: (message: string) => void;
|
||||
};
|
||||
|
||||
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
|
||||
@ -60,15 +62,21 @@ export class DockerComposeService {
|
||||
}
|
||||
|
||||
private getCommonOptions({
|
||||
dockerFlags,
|
||||
composeFiles,
|
||||
composeFlags,
|
||||
cwd,
|
||||
debug,
|
||||
}: OptionsInputs): IDockerComposeOptions {
|
||||
return {
|
||||
config: composeFiles,
|
||||
log: true,
|
||||
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