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 |
@ -41,7 +41,7 @@ Some extra options can be passed to the `docker compose up` command using the `u
|
||||
### 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.
|
||||
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.
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: "Docker Compose Action"
|
||||
description: "This action runs your compose file and clean up before action finished"
|
||||
description: "This action runs your compose file(s) and clean up before action finished"
|
||||
author: "Hoverkraft"
|
||||
branding:
|
||||
icon: anchor
|
||||
|
||||
5
dist/index.js
generated
vendored
5
dist/index.js
generated
vendored
@ -33178,6 +33178,7 @@ async function run() {
|
||||
cwd: inputs.cwd,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
}
|
||||
@ -33313,12 +33314,12 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ dockerFlags, 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,
|
||||
|
||||
6
dist/post.js
generated
vendored
6
dist/post.js
generated
vendored
@ -26340,6 +26340,7 @@ async function run() {
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
if (error) {
|
||||
loggerService.debug("docker compose error:\n" + error);
|
||||
@ -26351,6 +26352,7 @@ async function run() {
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose is down");
|
||||
}
|
||||
@ -26401,12 +26403,12 @@ class DockerComposeService {
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
getCommonOptions({ dockerFlags, 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,
|
||||
|
||||
@ -66,6 +66,7 @@ describe("run", () => {
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
@ -96,6 +97,7 @@ describe("run", () => {
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: ["web"],
|
||||
debug: debugMock,
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@ -42,6 +42,7 @@ export async function run(): Promise<void> {
|
||||
cwd: inputs.cwd,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
} catch (error) {
|
||||
|
||||
@ -61,6 +61,7 @@ describe("index", () => {
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
|
||||
@ -52,6 +52,7 @@ describe("run", () => {
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
@ -60,6 +61,7 @@ describe("run", () => {
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
||||
@ -100,6 +102,7 @@ describe("run", () => {
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
@ -108,6 +111,7 @@ describe("run", () => {
|
||||
cwd: "/current/working/dir",
|
||||
dockerFlags: [],
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
|
||||
|
||||
@ -21,6 +21,7 @@ export async function run(): Promise<void> {
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
@ -35,6 +36,7 @@ export async function run(): Promise<void> {
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
debug: loggerService.debug,
|
||||
});
|
||||
|
||||
loggerService.info("docker compose is down");
|
||||
|
||||
@ -48,6 +48,7 @@ describe("post", () => {
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
@ -56,6 +57,7 @@ describe("post", () => {
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
debug: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
|
||||
|
||||
@ -31,6 +31,7 @@ describe("DockerComposeService", () => {
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
@ -43,8 +44,8 @@ describe("DockerComposeService", () => {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
log: true,
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
@ -56,6 +57,7 @@ describe("DockerComposeService", () => {
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
@ -68,8 +70,8 @@ describe("DockerComposeService", () => {
|
||||
executablePath: "docker",
|
||||
options: ["--context", "dev"],
|
||||
},
|
||||
log: true,
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
@ -81,6 +83,7 @@ describe("DockerComposeService", () => {
|
||||
composeFlags: [],
|
||||
upFlags: ["--build"],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.up(upInputs);
|
||||
@ -90,11 +93,11 @@ describe("DockerComposeService", () => {
|
||||
commandOptions: ["--build"],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
log: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -107,6 +110,7 @@ describe("DockerComposeService", () => {
|
||||
composeFlags: [],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
cwd: "/current/working/dir",
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
await service.down(downInputs);
|
||||
@ -119,20 +123,22 @@ describe("DockerComposeService", () => {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
log: true,
|
||||
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" });
|
||||
@ -142,13 +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),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -13,6 +13,7 @@ type OptionsInputs = {
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
debug: (message: string) => void;
|
||||
};
|
||||
|
||||
export type UpInputs = OptionsInputs & { upFlags: Inputs["upFlags"]; services: Inputs["services"] };
|
||||
@ -65,12 +66,13 @@ export class DockerComposeService {
|
||||
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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user