testcontainers 7.22.0 → 7.22.1-beta.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/dist/docker-compose/default-docker-compose-options.js +1 -2
- package/dist/docker-compose/docker-compose-options.d.ts +1 -0
- package/dist/docker-compose/functions/container-name-resolver.d.ts +1 -1
- package/dist/docker-compose/functions/container-name-resolver.js +4 -5
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -2
- package/dist/docker-compose-environment/docker-compose-environment.js +18 -10
- package/dist/reaper.d.ts +1 -0
- package/dist/reaper.js +6 -1
- package/dist/registry-auth-locator/credential-provider.js +1 -1
- package/package.json +1 -1
|
@@ -12,7 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.defaultDockerComposeOptions = void 0;
|
|
15
|
-
const session_id_1 = require("../docker/session-id");
|
|
16
15
|
const defaultDockerComposeOptions = (_a) => {
|
|
17
16
|
var { env = {} } = _a, options = __rest(_a, ["env"]);
|
|
18
17
|
return {
|
|
@@ -20,7 +19,7 @@ const defaultDockerComposeOptions = (_a) => {
|
|
|
20
19
|
cwd: options.filePath,
|
|
21
20
|
config: options.files,
|
|
22
21
|
commandOptions: options.commandOptions,
|
|
23
|
-
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME:
|
|
22
|
+
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }), env),
|
|
24
23
|
};
|
|
25
24
|
};
|
|
26
25
|
exports.defaultDockerComposeOptions = defaultDockerComposeOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const resolveContainerName: (containerName: string) => string;
|
|
1
|
+
export declare const resolveContainerName: (projectName: string, containerName: string) => string;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveContainerName = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return containerName.substring(`/${session_id_1.sessionId}_`.length);
|
|
4
|
+
const resolveContainerName = (projectName, containerName) => {
|
|
5
|
+
if (containerName.includes(projectName)) {
|
|
6
|
+
return containerName.substring(`/${projectName}_`.length);
|
|
8
7
|
}
|
|
9
8
|
else if (containerName.startsWith("/")) {
|
|
10
9
|
return containerName.substring(1);
|
|
11
10
|
}
|
|
12
11
|
else {
|
|
13
|
-
throw new Error(`Unable to resolve container name for container name: "${containerName}",
|
|
12
|
+
throw new Error(`Unable to resolve container name for container name: "${containerName}", project name: "${projectName}"`);
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
exports.resolveContainerName = resolveContainerName;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { WaitStrategy } from "../wait-strategy";
|
|
2
|
+
import { Uuid } from "../uuid";
|
|
2
3
|
import { EnvKey, EnvValue } from "../docker/types";
|
|
3
4
|
import { StartedDockerComposeEnvironment } from "./started-docker-compose-environment";
|
|
4
5
|
export declare class DockerComposeEnvironment {
|
|
5
|
-
private readonly
|
|
6
|
+
private readonly composeFilePath;
|
|
7
|
+
private readonly composeFiles;
|
|
8
|
+
private projectName;
|
|
6
9
|
private build;
|
|
7
10
|
private recreate;
|
|
8
11
|
private env;
|
|
9
12
|
private waitStrategy;
|
|
10
13
|
private startupTimeout;
|
|
11
|
-
constructor(composeFilePath: string, composeFiles: string | string[]);
|
|
14
|
+
constructor(composeFilePath: string, composeFiles: string | string[], uuid?: Uuid);
|
|
12
15
|
withBuild(): this;
|
|
13
16
|
withEnv(key: EnvKey, value: EnvValue): this;
|
|
14
17
|
withNoRecreate(): this;
|
|
@@ -17,6 +17,7 @@ const logger_1 = require("../logger");
|
|
|
17
17
|
const port_check_1 = require("../port-check");
|
|
18
18
|
const wait_strategy_1 = require("../wait-strategy");
|
|
19
19
|
const reaper_1 = require("../reaper");
|
|
20
|
+
const uuid_1 = require("../uuid");
|
|
20
21
|
const list_containers_1 = require("../docker/functions/container/list-containers");
|
|
21
22
|
const get_container_1 = require("../docker/functions/container/get-container");
|
|
22
23
|
const docker_host_1 = require("../docker/docker-host");
|
|
@@ -25,15 +26,16 @@ const container_logs_1 = require("../docker/functions/container/container-logs")
|
|
|
25
26
|
const started_docker_compose_environment_1 = require("./started-docker-compose-environment");
|
|
26
27
|
const docker_compose_down_1 = require("../docker-compose/functions/docker-compose-down");
|
|
27
28
|
const docker_compose_up_1 = require("../docker-compose/functions/docker-compose-up");
|
|
28
|
-
const session_id_1 = require("../docker/session-id");
|
|
29
29
|
class DockerComposeEnvironment {
|
|
30
|
-
constructor(composeFilePath, composeFiles) {
|
|
30
|
+
constructor(composeFilePath, composeFiles, uuid = new uuid_1.RandomUuid()) {
|
|
31
31
|
this.build = false;
|
|
32
32
|
this.recreate = true;
|
|
33
33
|
this.env = {};
|
|
34
34
|
this.waitStrategy = {};
|
|
35
35
|
this.startupTimeout = 60000;
|
|
36
|
-
this.
|
|
36
|
+
this.composeFilePath = composeFilePath;
|
|
37
|
+
this.composeFiles = composeFiles;
|
|
38
|
+
this.projectName = `testcontainers-${uuid.nextUuid()}`;
|
|
37
39
|
}
|
|
38
40
|
withBuild() {
|
|
39
41
|
this.build = true;
|
|
@@ -45,6 +47,7 @@ class DockerComposeEnvironment {
|
|
|
45
47
|
}
|
|
46
48
|
withNoRecreate() {
|
|
47
49
|
this.recreate = false;
|
|
50
|
+
this.projectName = "testcontainers-node";
|
|
48
51
|
return this;
|
|
49
52
|
}
|
|
50
53
|
withWaitStrategy(containerName, waitStrategy) {
|
|
@@ -57,8 +60,13 @@ class DockerComposeEnvironment {
|
|
|
57
60
|
}
|
|
58
61
|
up(services) {
|
|
59
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
logger_1.log.info(`Starting DockerCompose environment`);
|
|
61
|
-
yield reaper_1.ReaperInstance.getInstance();
|
|
63
|
+
logger_1.log.info(`Starting DockerCompose environment: ${this.projectName}`);
|
|
64
|
+
(yield reaper_1.ReaperInstance.getInstance()).addProject(this.projectName);
|
|
65
|
+
const options = {
|
|
66
|
+
filePath: this.composeFilePath,
|
|
67
|
+
files: this.composeFiles,
|
|
68
|
+
projectName: this.projectName,
|
|
69
|
+
};
|
|
62
70
|
const commandOptions = [];
|
|
63
71
|
if (this.build) {
|
|
64
72
|
commandOptions.push("--build");
|
|
@@ -66,8 +74,8 @@ class DockerComposeEnvironment {
|
|
|
66
74
|
if (!this.recreate) {
|
|
67
75
|
commandOptions.push("--no-recreate");
|
|
68
76
|
}
|
|
69
|
-
yield docker_compose_up_1.dockerComposeUp(Object.assign(Object.assign({},
|
|
70
|
-
const startedContainers = (yield list_containers_1.listContainers()).filter((container) => container.Labels["com.docker.compose.project"] ===
|
|
77
|
+
yield docker_compose_up_1.dockerComposeUp(Object.assign(Object.assign({}, options), { commandOptions, env: this.env }), services);
|
|
78
|
+
const startedContainers = (yield list_containers_1.listContainers()).filter((container) => container.Labels["com.docker.compose.project"] === this.projectName);
|
|
71
79
|
const startedContainerNames = startedContainers.reduce((containerNames, startedContainer) => [
|
|
72
80
|
...containerNames,
|
|
73
81
|
startedContainer.Names.join(", "),
|
|
@@ -75,7 +83,7 @@ class DockerComposeEnvironment {
|
|
|
75
83
|
logger_1.log.info(`Started the following containers: ${startedContainerNames.join(", ")}`);
|
|
76
84
|
const startedGenericContainers = (yield Promise.all(startedContainers.map((startedContainer) => __awaiter(this, void 0, void 0, function* () {
|
|
77
85
|
const container = get_container_1.getContainerById(startedContainer.Id);
|
|
78
|
-
const containerName = container_name_resolver_1.resolveContainerName(startedContainer.Names[0]);
|
|
86
|
+
const containerName = container_name_resolver_1.resolveContainerName(this.projectName, startedContainer.Names[0]);
|
|
79
87
|
(yield container_logs_1.containerLogs(container))
|
|
80
88
|
.on("data", (data) => logger_1.containerLog.trace(`${containerName}: ${data}`))
|
|
81
89
|
.on("err", (data) => logger_1.containerLog.error(`${containerName}: ${data}`));
|
|
@@ -89,7 +97,7 @@ class DockerComposeEnvironment {
|
|
|
89
97
|
catch (err) {
|
|
90
98
|
logger_1.log.error(`Container ${containerName} failed to be ready: ${err}`);
|
|
91
99
|
try {
|
|
92
|
-
yield docker_compose_down_1.dockerComposeDown(
|
|
100
|
+
yield docker_compose_down_1.dockerComposeDown(options);
|
|
93
101
|
}
|
|
94
102
|
catch (_a) {
|
|
95
103
|
logger_1.log.warn(`Failed to stop DockerCompose environment after failed up`);
|
|
@@ -102,7 +110,7 @@ class DockerComposeEnvironment {
|
|
|
102
110
|
return Object.assign(Object.assign({}, map), { [containerName]: startedGenericContainer });
|
|
103
111
|
}, {});
|
|
104
112
|
logger_1.log.info(`DockerCompose environment started: ${Object.keys(startedGenericContainers).join(", ")}`);
|
|
105
|
-
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers,
|
|
113
|
+
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, options);
|
|
106
114
|
});
|
|
107
115
|
}
|
|
108
116
|
getBoundPorts(containerInfo) {
|
package/dist/reaper.d.ts
CHANGED
package/dist/reaper.js
CHANGED
|
@@ -21,6 +21,9 @@ class RealReaper {
|
|
|
21
21
|
this.container = container;
|
|
22
22
|
this.socket = socket;
|
|
23
23
|
}
|
|
24
|
+
addProject(projectName) {
|
|
25
|
+
this.socket.write(`label=com.docker.compose.project=${projectName}\r\n`);
|
|
26
|
+
}
|
|
24
27
|
getContainerId() {
|
|
25
28
|
return this.container.getId();
|
|
26
29
|
}
|
|
@@ -29,6 +32,9 @@ class RealReaper {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
class DisabledReaper {
|
|
35
|
+
addProject() {
|
|
36
|
+
// noop
|
|
37
|
+
}
|
|
32
38
|
stop() {
|
|
33
39
|
// noop
|
|
34
40
|
}
|
|
@@ -97,7 +103,6 @@ class ReaperInstance {
|
|
|
97
103
|
socket.connect(port, host, () => {
|
|
98
104
|
logger_1.log.debug(`Connected to Reaper ${container.getId()}`);
|
|
99
105
|
socket.write(`label=org.testcontainers.session-id=${session_id_1.sessionId}\r\n`);
|
|
100
|
-
socket.write(`label=com.docker.compose.project=${session_id_1.sessionId}\r\n`);
|
|
101
106
|
const reaper = new RealReaper(container, socket);
|
|
102
107
|
resolve(reaper);
|
|
103
108
|
});
|
|
@@ -55,7 +55,7 @@ class CredentialProvider {
|
|
|
55
55
|
}
|
|
56
56
|
runCredentialProvider(registry, providerName) {
|
|
57
57
|
return new Promise((resolve) => {
|
|
58
|
-
const sink = child_process_1.spawn(providerName, ["get"]);
|
|
58
|
+
const sink = child_process_1.spawn(providerName, ["get"], { shell: process.platform === "win32" });
|
|
59
59
|
const chunks = [];
|
|
60
60
|
sink.stdout.on("data", (chunk) => chunks.push(chunk));
|
|
61
61
|
sink.on("close", (code) => {
|