testcontainers 7.21.0 → 7.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/docker-compose/default-docker-compose-options.js +1 -0
- package/dist/docker-compose/docker-compose-options.d.ts +1 -0
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +7 -2
- package/dist/docker-compose-environment/docker-compose-environment.js +30 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -523,6 +523,26 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
|
|
|
523
523
|
.up();
|
|
524
524
|
```
|
|
525
525
|
|
|
526
|
+
Specify [profiles](https://docs.docker.com/compose/profiles/):
|
|
527
|
+
|
|
528
|
+
```javascript
|
|
529
|
+
const { DockerComposeEnvironment } = require("testcontainers");
|
|
530
|
+
|
|
531
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
532
|
+
.withProfiles("profile1", "profile2")
|
|
533
|
+
.up();
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Specify not to re-create containers that are already running:
|
|
537
|
+
|
|
538
|
+
```javascript
|
|
539
|
+
const { DockerComposeEnvironment } = require("testcontainers");
|
|
540
|
+
|
|
541
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
542
|
+
.withNoRecreate()
|
|
543
|
+
.up();
|
|
544
|
+
```
|
|
545
|
+
|
|
526
546
|
Bind environment variables to the docker-compose file. For example if we have the following docker-compose file:
|
|
527
547
|
|
|
528
548
|
```yaml
|
|
@@ -18,6 +18,7 @@ const defaultDockerComposeOptions = (_a) => {
|
|
|
18
18
|
log: false,
|
|
19
19
|
cwd: options.filePath,
|
|
20
20
|
config: options.files,
|
|
21
|
+
composeOptions: options.composeOptions,
|
|
21
22
|
commandOptions: options.commandOptions,
|
|
22
23
|
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }), env),
|
|
23
24
|
};
|
|
@@ -3,15 +3,20 @@ import { Uuid } from "../uuid";
|
|
|
3
3
|
import { EnvKey, EnvValue } from "../docker/types";
|
|
4
4
|
import { StartedDockerComposeEnvironment } from "./started-docker-compose-environment";
|
|
5
5
|
export declare class DockerComposeEnvironment {
|
|
6
|
-
private readonly
|
|
7
|
-
private readonly
|
|
6
|
+
private readonly composeFilePath;
|
|
7
|
+
private readonly composeFiles;
|
|
8
|
+
private projectName;
|
|
8
9
|
private build;
|
|
10
|
+
private recreate;
|
|
11
|
+
private profiles;
|
|
9
12
|
private env;
|
|
10
13
|
private waitStrategy;
|
|
11
14
|
private startupTimeout;
|
|
12
15
|
constructor(composeFilePath: string, composeFiles: string | string[], uuid?: Uuid);
|
|
13
16
|
withBuild(): this;
|
|
14
17
|
withEnv(key: EnvKey, value: EnvValue): this;
|
|
18
|
+
withProfiles(...profiles: string[]): this;
|
|
19
|
+
withNoRecreate(): this;
|
|
15
20
|
withWaitStrategy(containerName: string, waitStrategy: WaitStrategy): this;
|
|
16
21
|
withStartupTimeout(startupTimeout: number): this;
|
|
17
22
|
up(services?: Array<string>): Promise<StartedDockerComposeEnvironment>;
|
|
@@ -29,11 +29,14 @@ const docker_compose_up_1 = require("../docker-compose/functions/docker-compose-
|
|
|
29
29
|
class DockerComposeEnvironment {
|
|
30
30
|
constructor(composeFilePath, composeFiles, uuid = new uuid_1.RandomUuid()) {
|
|
31
31
|
this.build = false;
|
|
32
|
+
this.recreate = true;
|
|
33
|
+
this.profiles = [];
|
|
32
34
|
this.env = {};
|
|
33
35
|
this.waitStrategy = {};
|
|
34
36
|
this.startupTimeout = 60000;
|
|
37
|
+
this.composeFilePath = composeFilePath;
|
|
38
|
+
this.composeFiles = composeFiles;
|
|
35
39
|
this.projectName = `testcontainers-${uuid.nextUuid()}`;
|
|
36
|
-
this.options = { filePath: composeFilePath, files: composeFiles, projectName: this.projectName };
|
|
37
40
|
}
|
|
38
41
|
withBuild() {
|
|
39
42
|
this.build = true;
|
|
@@ -43,6 +46,15 @@ class DockerComposeEnvironment {
|
|
|
43
46
|
this.env[key] = value;
|
|
44
47
|
return this;
|
|
45
48
|
}
|
|
49
|
+
withProfiles(...profiles) {
|
|
50
|
+
this.profiles = profiles;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
withNoRecreate() {
|
|
54
|
+
this.recreate = false;
|
|
55
|
+
this.projectName = "testcontainers-node";
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
46
58
|
withWaitStrategy(containerName, waitStrategy) {
|
|
47
59
|
this.waitStrategy[containerName] = waitStrategy;
|
|
48
60
|
return this;
|
|
@@ -53,13 +65,26 @@ class DockerComposeEnvironment {
|
|
|
53
65
|
}
|
|
54
66
|
up(services) {
|
|
55
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
logger_1.log.info(`Starting DockerCompose environment ${this.projectName}`);
|
|
68
|
+
logger_1.log.info(`Starting DockerCompose environment: ${this.projectName}`);
|
|
57
69
|
(yield reaper_1.ReaperInstance.getInstance()).addProject(this.projectName);
|
|
70
|
+
const options = {
|
|
71
|
+
filePath: this.composeFilePath,
|
|
72
|
+
files: this.composeFiles,
|
|
73
|
+
projectName: this.projectName,
|
|
74
|
+
};
|
|
58
75
|
const commandOptions = [];
|
|
59
76
|
if (this.build) {
|
|
60
77
|
commandOptions.push("--build");
|
|
61
78
|
}
|
|
62
|
-
|
|
79
|
+
if (!this.recreate) {
|
|
80
|
+
commandOptions.push("--no-recreate");
|
|
81
|
+
}
|
|
82
|
+
const composeOptions = [];
|
|
83
|
+
this.profiles.forEach((profile) => {
|
|
84
|
+
composeOptions.push("--profile");
|
|
85
|
+
composeOptions.push(profile);
|
|
86
|
+
});
|
|
87
|
+
yield docker_compose_up_1.dockerComposeUp(Object.assign(Object.assign({}, options), { commandOptions, composeOptions, env: this.env }), services);
|
|
63
88
|
const startedContainers = (yield list_containers_1.listContainers()).filter((container) => container.Labels["com.docker.compose.project"] === this.projectName);
|
|
64
89
|
const startedContainerNames = startedContainers.reduce((containerNames, startedContainer) => [
|
|
65
90
|
...containerNames,
|
|
@@ -82,7 +107,7 @@ class DockerComposeEnvironment {
|
|
|
82
107
|
catch (err) {
|
|
83
108
|
logger_1.log.error(`Container ${containerName} failed to be ready: ${err}`);
|
|
84
109
|
try {
|
|
85
|
-
yield docker_compose_down_1.dockerComposeDown(
|
|
110
|
+
yield docker_compose_down_1.dockerComposeDown(options);
|
|
86
111
|
}
|
|
87
112
|
catch (_a) {
|
|
88
113
|
logger_1.log.warn(`Failed to stop DockerCompose environment after failed up`);
|
|
@@ -95,7 +120,7 @@ class DockerComposeEnvironment {
|
|
|
95
120
|
return Object.assign(Object.assign({}, map), { [containerName]: startedGenericContainer });
|
|
96
121
|
}, {});
|
|
97
122
|
logger_1.log.info(`DockerCompose environment started: ${Object.keys(startedGenericContainers).join(", ")}`);
|
|
98
|
-
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers,
|
|
123
|
+
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, options);
|
|
99
124
|
});
|
|
100
125
|
}
|
|
101
126
|
getBoundPorts(containerInfo) {
|