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
12 changed files with 12 additions and 35 deletions

View File

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

View File

@ -1,5 +1,5 @@
name: "Docker Compose Action"
description: "This action runs your compose file(s) and clean up before action finished"
description: "This action runs your compose file and clean up before action finished"
author: "Hoverkraft"
branding:
icon: anchor

5
dist/index.js generated vendored
View File

@ -33178,7 +33178,6 @@ async function run() {
cwd: inputs.cwd,
upFlags: inputs.upFlags,
services: inputs.services,
debug: loggerService.debug,
});
loggerService.info("docker compose service(s) are up");
}
@ -33314,12 +33313,12 @@ class DockerComposeService {
output: out,
};
}
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
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
View File

@ -26340,7 +26340,6 @@ async function run() {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
debug: loggerService.debug,
});
if (error) {
loggerService.debug("docker compose error:\n" + error);
@ -26352,7 +26351,6 @@ async function run() {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
downFlags: inputs.downFlags,
debug: loggerService.debug,
});
loggerService.info("docker compose is down");
}
@ -26403,12 +26401,12 @@ class DockerComposeService {
output: out,
};
}
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, debug, }) {
getCommonOptions({ dockerFlags, composeFiles, composeFlags, cwd, }) {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => debug(chunk.toString()),
executable: {
executablePath: "docker",
options: dockerFlags,

View File

@ -66,7 +66,6 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: [],
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
@ -97,7 +96,6 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: ["web"],
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
});

View File

@ -42,7 +42,6 @@ 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) {

View File

@ -61,7 +61,6 @@ describe("index", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();

View File

@ -52,7 +52,6 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -61,7 +60,6 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
@ -102,7 +100,6 @@ describe("run", () => {
cwd: "/current/working/dir",
dockerFlags: [],
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -111,7 +108,6 @@ describe("run", () => {
cwd: "/current/working/dir",
dockerFlags: [],
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");

View File

@ -21,7 +21,6 @@ export async function run(): Promise<void> {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
debug: loggerService.debug,
});
if (error) {
@ -36,7 +35,6 @@ export async function run(): Promise<void> {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
downFlags: inputs.downFlags,
debug: loggerService.debug,
});
loggerService.info("docker compose is down");

View File

@ -48,7 +48,6 @@ describe("post", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});
expect(downMock).toHaveBeenCalledWith({
@ -57,7 +56,6 @@ describe("post", () => {
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");

View File

@ -31,7 +31,6 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -44,8 +43,8 @@ describe("DockerComposeService", () => {
executablePath: "docker",
options: [],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
@ -57,7 +56,6 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -70,8 +68,8 @@ describe("DockerComposeService", () => {
executablePath: "docker",
options: ["--context", "dev"],
},
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
@ -83,7 +81,6 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: ["--build"],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.up(upInputs);
@ -93,11 +90,11 @@ describe("DockerComposeService", () => {
commandOptions: ["--build"],
config: ["docker-compose.yml"],
cwd: "/current/working/dir",
callback: expect.any(Function),
executable: {
executablePath: "docker",
options: [],
},
log: true,
});
});
});
@ -110,7 +107,6 @@ describe("DockerComposeService", () => {
composeFlags: [],
downFlags: ["--volumes", "--remove-orphans"],
cwd: "/current/working/dir",
debug: jest.fn(),
};
await service.down(downInputs);
@ -123,22 +119,20 @@ 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" });
@ -148,13 +142,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),
});
});
});

View File

@ -13,7 +13,6 @@ 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"] };
@ -66,13 +65,12 @@ 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,