testcontainers 8.13.2 → 8.15.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/functions/container/exec-container.d.ts +7 -1
- package/dist/docker/functions/container/exec-container.js +3 -11
- package/dist/generic-container/started-generic-container.d.ts +2 -2
- package/dist/generic-container/started-generic-container.js +3 -2
- package/dist/log-system-diagnostics.js +1 -1
- package/dist/port-check.d.ts +3 -0
- package/dist/port-check.js +29 -2
- package/dist/test-container.d.ts +6 -1
- package/package.json +1 -1
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { Command, ExecResult } from "../../types";
|
|
2
2
|
import Dockerode from "dockerode";
|
|
3
|
-
|
|
3
|
+
declare type ExecContainerOptions = {
|
|
4
|
+
tty: boolean;
|
|
5
|
+
stdin: boolean;
|
|
6
|
+
detach: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const execContainer: (container: Dockerode.Container, command: Command[], options: ExecContainerOptions) => Promise<ExecResult>;
|
|
9
|
+
export {};
|
|
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.execContainer = void 0;
|
|
13
13
|
const logger_1 = require("../../../logger");
|
|
14
|
-
const execContainer = (container, command) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const execContainer = (container, command, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
try {
|
|
16
16
|
const exec = yield container.exec({
|
|
17
17
|
Cmd: command,
|
|
18
18
|
AttachStdout: true,
|
|
19
19
|
AttachStderr: true,
|
|
20
20
|
});
|
|
21
|
-
const stream = yield startExec(exec);
|
|
21
|
+
const stream = yield startExec(exec, options);
|
|
22
22
|
const chunks = [];
|
|
23
23
|
stream.on("data", (chunk) => chunks.push(chunk));
|
|
24
24
|
const exitCode = yield waitForExec(exec);
|
|
@@ -31,16 +31,8 @@ const execContainer = (container, command) => __awaiter(void 0, void 0, void 0,
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
exports.execContainer = execContainer;
|
|
34
|
-
const startExec = (exec) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const startExec = (exec, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
try {
|
|
36
|
-
const options = {
|
|
37
|
-
Detach: false,
|
|
38
|
-
Tty: true,
|
|
39
|
-
stream: true,
|
|
40
|
-
stdin: true,
|
|
41
|
-
stdout: true,
|
|
42
|
-
stderr: true,
|
|
43
|
-
};
|
|
44
36
|
const stream = yield exec.start(options);
|
|
45
37
|
stream.setEncoding("utf-8");
|
|
46
38
|
return stream;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { RestartOptions, StartedTestContainer, StopOptions, StoppedTestContainer } from "../test-container";
|
|
2
|
+
import { RestartOptions, StartedTestContainer, StopOptions, ExecOptions, StoppedTestContainer } from "../test-container";
|
|
3
3
|
import Dockerode from "dockerode";
|
|
4
4
|
import { Command, ContainerName, ExecResult, Host, Id as ContainerId, Labels } from "../docker/types";
|
|
5
5
|
import { InspectResult } from "../docker/functions/container/inspect-container";
|
|
@@ -27,6 +27,6 @@ export declare class StartedGenericContainer implements StartedTestContainer {
|
|
|
27
27
|
getNetworkNames(): string[];
|
|
28
28
|
getNetworkId(networkName: string): string;
|
|
29
29
|
getIpAddress(networkName: string): string;
|
|
30
|
-
exec(command: Command[]): Promise<ExecResult>;
|
|
30
|
+
exec(command: Command[], options?: Partial<ExecOptions>): Promise<ExecResult>;
|
|
31
31
|
logs(): Promise<Readable>;
|
|
32
32
|
}
|
|
@@ -96,8 +96,9 @@ class StartedGenericContainer {
|
|
|
96
96
|
getIpAddress(networkName) {
|
|
97
97
|
return this.inspectResult.networkSettings[networkName].ipAddress;
|
|
98
98
|
}
|
|
99
|
-
exec(command) {
|
|
100
|
-
|
|
99
|
+
exec(command, options = {}) {
|
|
100
|
+
const resolvedOptions = Object.assign({ stdin: true, detach: false, tty: true }, options);
|
|
101
|
+
return (0, exec_container_1.execContainer)(this.container, command, resolvedOptions);
|
|
101
102
|
}
|
|
102
103
|
logs() {
|
|
103
104
|
return (0, container_logs_1.containerLogs)(this.container);
|
|
@@ -37,7 +37,7 @@ const getDockerComposeInfo = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
|
-
logger_1.log.
|
|
40
|
+
logger_1.log.info(`Unable to detect docker-compose version, is it installed? ${err}`);
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
});
|
package/dist/port-check.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare class HostPortCheck implements PortCheck {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class InternalPortCheck implements PortCheck {
|
|
13
13
|
private readonly container;
|
|
14
|
+
private isDistroless;
|
|
15
|
+
private commandOutputs;
|
|
14
16
|
constructor(container: Dockerode.Container);
|
|
15
17
|
isBound(port: Port): Promise<boolean>;
|
|
18
|
+
private commandOutputsKey;
|
|
16
19
|
}
|
package/dist/port-check.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.InternalPortCheck = exports.HostPortCheck = void 0;
|
|
13
13
|
const net_1 = require("net");
|
|
14
14
|
const exec_container_1 = require("./docker/functions/container/exec-container");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
15
16
|
class HostPortCheck {
|
|
16
17
|
constructor(host) {
|
|
17
18
|
this.host = host;
|
|
@@ -40,6 +41,8 @@ exports.HostPortCheck = HostPortCheck;
|
|
|
40
41
|
class InternalPortCheck {
|
|
41
42
|
constructor(container) {
|
|
42
43
|
this.container = container;
|
|
44
|
+
this.isDistroless = false;
|
|
45
|
+
this.commandOutputs = new Set();
|
|
43
46
|
}
|
|
44
47
|
isBound(port) {
|
|
45
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -49,9 +52,33 @@ class InternalPortCheck {
|
|
|
49
52
|
["/bin/sh", "-c", `nc -vz -w 1 localhost ${port}`],
|
|
50
53
|
["/bin/bash", "-c", `</dev/tcp/localhost/${port}`],
|
|
51
54
|
];
|
|
52
|
-
const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command)));
|
|
53
|
-
|
|
55
|
+
const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command, { stdin: true, detach: false, tty: true })));
|
|
56
|
+
const isBound = commandResults.some((result) => result.exitCode === 0);
|
|
57
|
+
if (!isBound) {
|
|
58
|
+
const shellExists = commandResults.some((result) => result.exitCode !== 126);
|
|
59
|
+
if (!shellExists) {
|
|
60
|
+
if (!this.isDistroless) {
|
|
61
|
+
this.isDistroless = true;
|
|
62
|
+
logger_1.log.error(`The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy for container ${this.container.id}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
commandResults
|
|
67
|
+
.map((result) => (Object.assign(Object.assign({}, result), { output: result.output.trim() })))
|
|
68
|
+
.filter((result) => result.exitCode !== 126 && result.output.length > 0)
|
|
69
|
+
.forEach((result) => {
|
|
70
|
+
if (!this.commandOutputs.has(this.commandOutputsKey(result.output))) {
|
|
71
|
+
logger_1.log.trace(`Port check result for container ${this.container.id} exit code ${result.exitCode}: ${result.output}`);
|
|
72
|
+
this.commandOutputs.add(this.commandOutputsKey(result.output));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return isBound;
|
|
54
78
|
});
|
|
55
79
|
}
|
|
80
|
+
commandOutputsKey(output) {
|
|
81
|
+
return `${this.container.id}:${output}`;
|
|
82
|
+
}
|
|
56
83
|
}
|
|
57
84
|
exports.InternalPortCheck = InternalPortCheck;
|
package/dist/test-container.d.ts
CHANGED
|
@@ -30,6 +30,11 @@ export interface StopOptions {
|
|
|
30
30
|
timeout: number;
|
|
31
31
|
removeVolumes: boolean;
|
|
32
32
|
}
|
|
33
|
+
export interface ExecOptions {
|
|
34
|
+
tty: boolean;
|
|
35
|
+
detach: boolean;
|
|
36
|
+
stdin: boolean;
|
|
37
|
+
}
|
|
33
38
|
export interface StartedTestContainer {
|
|
34
39
|
stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
|
|
35
40
|
restart(options?: Partial<RestartOptions>): Promise<void>;
|
|
@@ -41,7 +46,7 @@ export interface StartedTestContainer {
|
|
|
41
46
|
getNetworkNames(): string[];
|
|
42
47
|
getNetworkId(networkName: string): string;
|
|
43
48
|
getIpAddress(networkName: string): string;
|
|
44
|
-
exec(command: Command[]): Promise<ExecResult>;
|
|
49
|
+
exec(command: Command[], options?: Partial<ExecOptions>): Promise<ExecResult>;
|
|
45
50
|
logs(): Promise<Readable>;
|
|
46
51
|
}
|
|
47
52
|
export interface StoppedTestContainer {
|