Skip to content

Commit

Permalink
fix: print docker compose output to debug only
Browse files Browse the repository at this point in the history
Signed-off-by: Emilien Escalle <[email protected]>
  • Loading branch information
neilime committed Jan 30, 2025
1 parent 765986d commit a8b866b
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/__check-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,22 @@ jobs:
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
exit 1
fi
test-action-with-postgres-service:
runs-on: ubuntu-latest
name: Test with postgres service
steps:
- uses: actions/checkout@v4

- name: Act
uses: ./
with:
compose-file: "./test/docker-compose-postgres.yml"
up-flags: "--quiet-pull"
down-flags: "--timeout 5"

- name: "Assert: postgres service is running"
run: |
docker compose -f ./test/docker-compose.yml ps
docker compose -f ./test/docker-compose.yml ps | grep test-service-postgres || (echo "Service test-service-postgres is not running" && exit 1)
5 changes: 3 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dist/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/index-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: [],
debug: debugMock,
});

expect(setFailedMock).not.toHaveBeenCalled();
Expand Down Expand Up @@ -92,6 +93,7 @@ describe("run", () => {
cwd: "/current/working/dir",
upFlags: [],
services: ["web"],
debug: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
});
Expand Down
1 change: 1 addition & 0 deletions src/index-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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) {
Expand Down
1 change: 1 addition & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("index", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
});

expect(setFailedMock).not.toHaveBeenCalled();
Expand Down
4 changes: 4 additions & 0 deletions src/post-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});

expect(downMock).toHaveBeenCalledWith({
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});

expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
Expand Down Expand Up @@ -95,13 +97,15 @@ describe("run", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});

expect(downMock).toHaveBeenCalledWith({
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});

expect(debugMock).toHaveBeenCalledWith("docker compose error:\ntest logs error");
Expand Down
2 changes: 2 additions & 0 deletions src/post-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function run(): Promise<void> {
composeFlags: inputs.composeFlags,
cwd: inputs.cwd,
services: inputs.services,
debug: loggerService.debug,
});

if (error) {
Expand All @@ -33,6 +34,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");
Expand Down
2 changes: 2 additions & 0 deletions src/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ describe("post", () => {
composeFlags: [],
cwd: "/current/working/dir",
services: [],
debug: debugMock,
});

expect(downMock).toHaveBeenCalledWith({
composeFiles: ["docker-compose.yml"],
composeFlags: [],
cwd: "/current/working/dir",
downFlags: [],
debug: debugMock,
});

expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
Expand Down
13 changes: 9 additions & 4 deletions src/services/docker-compose.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
debug: jest.fn(),
};

await service.up(upInputs);
Expand All @@ -38,8 +39,8 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: [],
config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});

Expand All @@ -50,6 +51,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
upFlags: ["--build"],
cwd: "/current/working/dir",
debug: jest.fn(),
};

await service.up(upInputs);
Expand All @@ -58,8 +60,8 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: ["--build"],
config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir",
callback: expect.any(Function),
});
});
});
Expand All @@ -71,6 +73,7 @@ describe("DockerComposeService", () => {
composeFlags: [],
downFlags: ["--volumes", "--remove-orphans"],
cwd: "/current/working/dir",
debug: jest.fn(),
};

await service.down(downInputs);
Expand All @@ -79,19 +82,21 @@ describe("DockerComposeService", () => {
composeOptions: [],
commandOptions: ["--volumes", "--remove-orphans"],
config: [],
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 = {
composeFiles: ["docker-compose.yml"],
services: ["helloworld2", "helloworld3"],
composeFlags: [],
cwd: "/current/working/dir",
debug: debugMock,
};

logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
Expand All @@ -101,9 +106,9 @@ describe("DockerComposeService", () => {
expect(dockerCompose.logs).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
composeOptions: [],
config: ["docker-compose.yml"],
log: true,
cwd: "/current/working/dir",
follow: false,
callback: expect.any(Function),
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/services/docker-compose.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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"] };
Expand Down Expand Up @@ -63,12 +64,13 @@ export class DockerComposeService {
composeFiles,
composeFlags,
cwd,
debug,
}: OptionsInputs): IDockerComposeOptions {
return {
config: composeFiles,
log: true,
composeOptions: composeFlags,
cwd: cwd,
callback: (chunk) => debug(chunk.toString()),

Check warning on line 73 in src/services/docker-compose.service.ts

View check run for this annotation

Codecov / codecov/patch

src/services/docker-compose.service.ts#L73

Added line #L73 was not covered by tests
};
}
}
5 changes: 5 additions & 0 deletions test/docker-compose-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
test-service-postgres:
image: postgres
environment:
POSTGRES_PASSWORD: example

0 comments on commit a8b866b

Please sign in to comment.