Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom compose project names #800

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/features/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
.up();
```

### With custom project name

See [project name](https://docs.docker.com/compose/project-name/).

```javascript
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
.withProjectName("test")
.up();
```

## Downing a Docker compose environment

Testcontainers by default will not wait until the environment has downed. It will simply issue the down command and return immediately. This is to save time when running tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fetch from "node-fetch";
import path from "path";
import { DockerComposeEnvironment } from "./docker-compose-environment";
import { RandomUuid } from "../common";
import { Wait } from "../wait-strategies/wait";
import { PullPolicy } from "../utils/pull-policy";
import {
Expand Down Expand Up @@ -255,4 +256,15 @@ describe("DockerComposeEnvironment", () => {

await startedEnvironment.down();
});

it("should use a custom project name if set", async () => {
const customProjectName = `custom-${new RandomUuid().nextUuid()}`;
const startedEnvironment = await new DockerComposeEnvironment(fixtures, "docker-compose.yml")
.withProjectName(customProjectName)
.up();

expect(await getRunningContainerNames()).toContain(`${customProjectName}-container-1`);

await startedEnvironment.down();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export class DockerComposeEnvironment {
return this;
}

public withProjectName(projectName: string): this {
this.projectName = projectName;
return this;
}

public async up(services?: Array<string>): Promise<StartedDockerComposeEnvironment> {
log.info(`Starting DockerCompose environment "${this.projectName}"...`);
const client = await getContainerRuntimeClient();
Expand Down
Loading