testcontainers 9.3.0 → 9.5.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/package.json +17 -17
- package/dist/src/docker/docker-client.js +2 -45
- package/dist/src/docker/functions/container/exec-container.d.ts +1 -7
- package/dist/src/docker/functions/container/exec-container.js +4 -4
- package/dist/src/docker/resolve-host.d.ts +6 -0
- package/dist/src/docker/resolve-host.js +60 -0
- package/dist/src/docker/rootless-unix-socket-strategy.d.ts +2 -1
- package/dist/src/docker/rootless-unix-socket-strategy.js +10 -2
- package/dist/src/docker-compose/default-docker-compose-options.js +12 -0
- package/dist/src/docker-compose/functions/docker-compose-pull.d.ts +2 -0
- package/dist/src/docker-compose/functions/docker-compose-pull.js +35 -0
- package/dist/src/docker-compose/functions/docker-compose-up.js +2 -2
- package/dist/src/docker-compose-environment/docker-compose-environment.d.ts +4 -1
- package/dist/src/docker-compose-environment/docker-compose-environment.js +17 -5
- package/dist/src/dockerfile-parser.js +2 -1
- package/dist/src/generic-container/create-container-options.d.ts +3 -0
- package/dist/src/generic-container/create-container-options.js +18 -0
- package/dist/src/generic-container/generic-container.d.ts +17 -26
- package/dist/src/generic-container/generic-container.js +80 -83
- package/dist/src/generic-container/started-generic-container.d.ts +5 -3
- package/dist/src/generic-container/started-generic-container.js +13 -6
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +2 -2
- package/dist/src/modules/abstract-started-container.d.ts +2 -0
- package/dist/src/modules/abstract-started-container.js +10 -1
- package/dist/src/modules/arangodb/arangodb-container.js +1 -1
- package/dist/src/modules/elasticsearch/elasticsearch-container.js +7 -1
- package/dist/src/modules/kafka/kafka-container.d.ts +2 -3
- package/dist/src/modules/kafka/kafka-container.js +8 -8
- package/dist/src/modules/mongodb/mongodb-container.d.ts +1 -1
- package/dist/src/modules/mongodb/mongodb-container.js +2 -2
- package/dist/src/modules/mysql/mysql-container.js +1 -1
- package/dist/src/modules/nats/nats-container.js +4 -2
- package/dist/src/modules/neo4j/neo4j-container.js +1 -1
- package/dist/src/modules/postgresql/postgresql-container.js +2 -2
- package/dist/src/port-check.js +1 -1
- package/dist/src/reaper.js +1 -1
- package/dist/src/test-container.d.ts +1 -1
- package/dist/src/type-guards.d.ts +2 -0
- package/dist/src/type-guards.js +6 -4
- package/dist/src/wait-for-container.d.ts +1 -1
- package/dist/src/wait-strategy/default-wait-strategy.d.ts +3 -0
- package/dist/src/wait-strategy/default-wait-strategy.js +7 -0
- package/dist/src/wait-strategy/health-check-wait-strategy.d.ts +5 -0
- package/dist/src/wait-strategy/health-check-wait-strategy.js +31 -0
- package/dist/src/wait-strategy/host-port-wait-strategy.d.ts +13 -0
- package/dist/src/wait-strategy/host-port-wait-strategy.js +54 -0
- package/dist/src/{http-wait-strategy.d.ts → wait-strategy/http-wait-strategy.d.ts} +1 -1
- package/dist/src/{http-wait-strategy.js → wait-strategy/http-wait-strategy.js} +1 -1
- package/dist/src/wait-strategy/log-wait-strategy.d.ts +10 -0
- package/dist/src/wait-strategy/log-wait-strategy.js +67 -0
- package/dist/src/wait-strategy/shell-wait-strategy.d.ts +7 -0
- package/dist/src/wait-strategy/shell-wait-strategy.js +35 -0
- package/dist/src/{startup-check-strategy.js → wait-strategy/startup-check-strategy.js} +2 -2
- package/dist/src/wait-strategy/wait-strategy.d.ts +11 -0
- package/dist/src/wait-strategy/wait-strategy.js +13 -0
- package/dist/src/{wait.d.ts → wait-strategy/wait.d.ts} +4 -1
- package/dist/src/wait-strategy/wait.js +22 -0
- package/package.json +17 -17
- package/dist/src/wait-strategy.d.ts +0 -32
- package/dist/src/wait-strategy.js +0 -137
- package/dist/src/wait.js +0 -17
- /package/dist/src/{startup-check-strategy.d.ts → wait-strategy/startup-check-strategy.d.ts} +0 -0
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.StartedPostgreSqlContainer = exports.PostgreSqlContainer = void 0;
|
|
13
13
|
const generic_container_1 = require("../../generic-container/generic-container");
|
|
14
14
|
const abstract_started_container_1 = require("../abstract-started-container");
|
|
15
|
-
const wait_1 = require("../../wait");
|
|
15
|
+
const wait_1 = require("../../wait-strategy/wait");
|
|
16
16
|
const POSTGRES_PORT = 5432;
|
|
17
17
|
class PostgreSqlContainer extends generic_container_1.GenericContainer {
|
|
18
18
|
constructor(image = "postgres:13.3-alpine") {
|
|
@@ -38,7 +38,7 @@ class PostgreSqlContainer extends generic_container_1.GenericContainer {
|
|
|
38
38
|
start: { get: () => super.start }
|
|
39
39
|
});
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
this.withExposedPorts(...(this.hasExposedPorts ? this.
|
|
41
|
+
this.withExposedPorts(...(this.hasExposedPorts ? this.opts.exposedPorts : [POSTGRES_PORT]))
|
|
42
42
|
.withEnvironment({
|
|
43
43
|
POSTGRES_DB: this.database,
|
|
44
44
|
POSTGRES_USER: this.username,
|
package/dist/src/port-check.js
CHANGED
|
@@ -52,7 +52,7 @@ class InternalPortCheck {
|
|
|
52
52
|
["/bin/sh", "-c", `nc -vz -w 1 localhost ${port}`],
|
|
53
53
|
["/bin/bash", "-c", `</dev/tcp/localhost/${port}`],
|
|
54
54
|
];
|
|
55
|
-
const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command,
|
|
55
|
+
const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command, false)));
|
|
56
56
|
const isBound = commandResults.some((result) => result.exitCode === 0);
|
|
57
57
|
if (!isBound && logger_1.log.enabled()) {
|
|
58
58
|
const shellExists = commandResults.some((result) => result.exitCode !== 126);
|
package/dist/src/reaper.js
CHANGED
|
@@ -17,7 +17,7 @@ const session_id_1 = require("./docker/session-id");
|
|
|
17
17
|
const images_1 = require("./images");
|
|
18
18
|
const port_1 = require("./port");
|
|
19
19
|
const labels_1 = require("./labels");
|
|
20
|
-
const wait_1 = require("./wait");
|
|
20
|
+
const wait_1 = require("./wait-strategy/wait");
|
|
21
21
|
const retry_strategy_1 = require("./retry-strategy");
|
|
22
22
|
const get_remote_docker_unix_socket_path_1 = require("./docker/get-remote-docker-unix-socket-path");
|
|
23
23
|
const docker_client_1 = require("./docker/docker-client");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { PortWithOptionalBinding } from "./port";
|
|
3
3
|
import { PullPolicy } from "./pull-policy";
|
|
4
|
-
import { WaitStrategy } from "./wait-strategy";
|
|
4
|
+
import { WaitStrategy } from "./wait-strategy/wait-strategy";
|
|
5
5
|
import { Readable } from "stream";
|
|
6
6
|
import { ExecResult, ExtraHost, TmpFs, Labels, Ulimits, BindMount, FileToCopy, ContentToCopy, Environment, ResourcesQuota } from "./docker/types";
|
|
7
7
|
import { StartedNetwork } from "./network";
|
package/dist/src/type-guards.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDefined = void 0;
|
|
4
|
-
const isDefined = (value) =>
|
|
5
|
-
return value !== undefined;
|
|
6
|
-
};
|
|
3
|
+
exports.isNotEmptyString = exports.isEmptyString = exports.isDefined = void 0;
|
|
4
|
+
const isDefined = (value) => value !== undefined;
|
|
7
5
|
exports.isDefined = isDefined;
|
|
6
|
+
const isEmptyString = (value) => value.trim() === "";
|
|
7
|
+
exports.isEmptyString = isEmptyString;
|
|
8
|
+
const isNotEmptyString = (value) => !(0, exports.isEmptyString)(value);
|
|
9
|
+
exports.isNotEmptyString = isNotEmptyString;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import Dockerode from "dockerode";
|
|
2
2
|
import { BoundPorts } from "./bound-ports";
|
|
3
|
-
import { WaitStrategy } from "./wait-strategy";
|
|
3
|
+
import { WaitStrategy } from "./wait-strategy/wait-strategy";
|
|
4
4
|
export declare const waitForContainer: (container: Dockerode.Container, waitStrategy: WaitStrategy, host: string, boundPorts: BoundPorts, startTime?: Date) => Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultWaitStrategy = void 0;
|
|
4
|
+
const host_port_wait_strategy_1 = require("./host-port-wait-strategy");
|
|
5
|
+
const port_check_1 = require("../port-check");
|
|
6
|
+
const defaultWaitStrategy = (host, container) => new host_port_wait_strategy_1.HostPortWaitStrategy(new port_check_1.HostPortCheck(host), new port_check_1.InternalPortCheck(container));
|
|
7
|
+
exports.defaultWaitStrategy = defaultWaitStrategy;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthCheckWaitStrategy = void 0;
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const retry_strategy_1 = require("../retry-strategy");
|
|
15
|
+
const inspect_container_1 = require("../docker/functions/container/inspect-container");
|
|
16
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
17
|
+
class HealthCheckWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
18
|
+
waitUntilReady(container) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
logger_1.log.debug(`Waiting for health check for ${container.id}`);
|
|
21
|
+
const status = yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => __awaiter(this, void 0, void 0, function* () { return (yield (0, inspect_container_1.inspectContainer)(container)).healthCheckStatus; }), (healthCheckStatus) => healthCheckStatus === "healthy" || healthCheckStatus === "unhealthy", () => {
|
|
22
|
+
const timeout = this.startupTimeout;
|
|
23
|
+
throw new Error(`Health check not healthy after ${timeout}ms for ${container.id}`);
|
|
24
|
+
}, this.startupTimeout);
|
|
25
|
+
if (status !== "healthy") {
|
|
26
|
+
throw new Error(`Health check failed: ${status} for ${container.id}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.HealthCheckWaitStrategy = HealthCheckWaitStrategy;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PortCheck } from "../port-check";
|
|
2
|
+
import Dockerode from "dockerode";
|
|
3
|
+
import { BoundPorts } from "../bound-ports";
|
|
4
|
+
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
5
|
+
export declare class HostPortWaitStrategy extends AbstractWaitStrategy {
|
|
6
|
+
private readonly hostPortCheck;
|
|
7
|
+
private readonly internalPortCheck;
|
|
8
|
+
constructor(hostPortCheck: PortCheck, internalPortCheck: PortCheck);
|
|
9
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
10
|
+
private waitForHostPorts;
|
|
11
|
+
private waitForInternalPorts;
|
|
12
|
+
private waitForPort;
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HostPortWaitStrategy = void 0;
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const retry_strategy_1 = require("../retry-strategy");
|
|
15
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
16
|
+
class HostPortWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
17
|
+
constructor(hostPortCheck, internalPortCheck) {
|
|
18
|
+
super();
|
|
19
|
+
this.hostPortCheck = hostPortCheck;
|
|
20
|
+
this.internalPortCheck = internalPortCheck;
|
|
21
|
+
}
|
|
22
|
+
waitUntilReady(container, host, boundPorts) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
yield Promise.all([this.waitForHostPorts(container, boundPorts), this.waitForInternalPorts(container, boundPorts)]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
waitForHostPorts(container, boundPorts) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
for (const [, hostPort] of boundPorts.iterator()) {
|
|
30
|
+
logger_1.log.debug(`Waiting for host port ${hostPort} for ${container.id}`);
|
|
31
|
+
yield this.waitForPort(container, hostPort, this.hostPortCheck);
|
|
32
|
+
logger_1.log.debug(`Host port ${hostPort} ready for ${container.id}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
waitForInternalPorts(container, boundPorts) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
for (const [internalPort] of boundPorts.iterator()) {
|
|
39
|
+
logger_1.log.debug(`Waiting for internal port ${internalPort} for ${container.id}`);
|
|
40
|
+
yield this.waitForPort(container, internalPort, this.internalPortCheck);
|
|
41
|
+
logger_1.log.debug(`Internal port ${internalPort} ready for ${container.id}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
waitForPort(container, port, portCheck) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => portCheck.isBound(port), (isBound) => isBound, () => {
|
|
48
|
+
const timeout = this.startupTimeout;
|
|
49
|
+
throw new Error(`Port ${port} not bound after ${timeout}ms for ${container.id}`);
|
|
50
|
+
}, this.startupTimeout);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.HostPortWaitStrategy = HostPortWaitStrategy;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dockerode from "dockerode";
|
|
2
|
-
import { BoundPorts } from "
|
|
2
|
+
import { BoundPorts } from "../bound-ports";
|
|
3
3
|
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
4
4
|
export declare class HttpWaitStrategy extends AbstractWaitStrategy {
|
|
5
5
|
private readonly path;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HttpWaitStrategy = void 0;
|
|
16
16
|
const wait_strategy_1 = require("./wait-strategy");
|
|
17
|
-
const retry_strategy_1 = require("
|
|
17
|
+
const retry_strategy_1 = require("../retry-strategy");
|
|
18
18
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
19
19
|
const https_1 = __importDefault(require("https"));
|
|
20
20
|
class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Dockerode from "dockerode";
|
|
2
|
+
import { BoundPorts } from "../bound-ports";
|
|
3
|
+
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
4
|
+
export type Log = string;
|
|
5
|
+
export declare class LogWaitStrategy extends AbstractWaitStrategy {
|
|
6
|
+
private readonly message;
|
|
7
|
+
private readonly times;
|
|
8
|
+
constructor(message: Log | RegExp, times: number);
|
|
9
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LogWaitStrategy = void 0;
|
|
16
|
+
const logger_1 = require("../logger");
|
|
17
|
+
const container_logs_1 = require("../docker/functions/container/container-logs");
|
|
18
|
+
const byline_1 = __importDefault(require("byline"));
|
|
19
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
20
|
+
class LogWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
21
|
+
constructor(message, times) {
|
|
22
|
+
super();
|
|
23
|
+
this.message = message;
|
|
24
|
+
this.times = times;
|
|
25
|
+
}
|
|
26
|
+
waitUntilReady(container, host, boundPorts, startTime) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
logger_1.log.debug(`Waiting for log message "${this.message}" for ${container.id}`);
|
|
29
|
+
const stream = yield (0, container_logs_1.containerLogs)(container, { since: startTime });
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const startupTimeout = this.startupTimeout;
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
33
|
+
const message = `Log message "${this.message}" not received after ${startupTimeout}ms for ${container.id}`;
|
|
34
|
+
logger_1.log.error(message);
|
|
35
|
+
reject(new Error(message));
|
|
36
|
+
}, startupTimeout);
|
|
37
|
+
const comparisonFn = (line) => {
|
|
38
|
+
if (this.message instanceof RegExp) {
|
|
39
|
+
return this.message.test(line);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return line.includes(this.message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let count = 0;
|
|
46
|
+
const lineProcessor = (line) => {
|
|
47
|
+
if (comparisonFn(line)) {
|
|
48
|
+
if (++count === this.times) {
|
|
49
|
+
stream.destroy();
|
|
50
|
+
clearTimeout(timeout);
|
|
51
|
+
resolve();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
(0, byline_1.default)(stream)
|
|
56
|
+
.on("data", lineProcessor)
|
|
57
|
+
.on("err", lineProcessor)
|
|
58
|
+
.on("end", () => {
|
|
59
|
+
stream.destroy();
|
|
60
|
+
clearTimeout(timeout);
|
|
61
|
+
reject(new Error(`Log stream ended and message "${this.message}" was not received for ${container.id}`));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.LogWaitStrategy = LogWaitStrategy;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Dockerode from "dockerode";
|
|
2
|
+
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
3
|
+
export declare class ShellWaitStrategy extends AbstractWaitStrategy {
|
|
4
|
+
private readonly command;
|
|
5
|
+
constructor(command: string);
|
|
6
|
+
waitUntilReady(container: Dockerode.Container): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ShellWaitStrategy = void 0;
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
15
|
+
const retry_strategy_1 = require("../retry-strategy");
|
|
16
|
+
const exec_container_1 = require("../docker/functions/container/exec-container");
|
|
17
|
+
class ShellWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
18
|
+
constructor(command) {
|
|
19
|
+
super();
|
|
20
|
+
this.command = command;
|
|
21
|
+
}
|
|
22
|
+
waitUntilReady(container) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
logger_1.log.debug(`Waiting for successful shell command ${this.command} for ${container.id}`);
|
|
25
|
+
yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { exitCode } = yield (0, exec_container_1.execContainer)(container, ["/bin/sh", "-c", this.command], false);
|
|
27
|
+
return exitCode;
|
|
28
|
+
}), (exitCode) => exitCode === 0, () => {
|
|
29
|
+
const timeout = this.startupTimeout;
|
|
30
|
+
throw new Error(`Shell command not successful after ${timeout}ms for ${container.id}`);
|
|
31
|
+
}, this.startupTimeout);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ShellWaitStrategy = ShellWaitStrategy;
|
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.StartupCheckStrategy = void 0;
|
|
13
13
|
const wait_strategy_1 = require("./wait-strategy");
|
|
14
|
-
const retry_strategy_1 = require("
|
|
15
|
-
const docker_client_1 = require("
|
|
14
|
+
const retry_strategy_1 = require("../retry-strategy");
|
|
15
|
+
const docker_client_1 = require("../docker/docker-client");
|
|
16
16
|
class StartupCheckStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
17
17
|
waitUntilReady(container) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BoundPorts } from "../bound-ports";
|
|
2
|
+
import Dockerode from "dockerode";
|
|
3
|
+
export interface WaitStrategy {
|
|
4
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
5
|
+
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class AbstractWaitStrategy implements WaitStrategy {
|
|
8
|
+
protected startupTimeout: number;
|
|
9
|
+
abstract waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
10
|
+
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractWaitStrategy = void 0;
|
|
4
|
+
class AbstractWaitStrategy {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.startupTimeout = 60000;
|
|
7
|
+
}
|
|
8
|
+
withStartupTimeout(startupTimeout) {
|
|
9
|
+
this.startupTimeout = startupTimeout;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AbstractWaitStrategy = AbstractWaitStrategy;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WaitStrategy } from "./wait-strategy";
|
|
2
2
|
import { HttpWaitStrategy } from "./http-wait-strategy";
|
|
3
|
+
import { Log } from "./log-wait-strategy";
|
|
4
|
+
import { ShellWaitStrategy } from "./shell-wait-strategy";
|
|
3
5
|
export declare class Wait {
|
|
4
6
|
static forLogMessage(message: Log | RegExp, times?: number): WaitStrategy;
|
|
5
7
|
static forHealthCheck(): WaitStrategy;
|
|
6
8
|
static forHttp(path: string, port: number): HttpWaitStrategy;
|
|
9
|
+
static forSuccessfulCommand(command: string): ShellWaitStrategy;
|
|
7
10
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Wait = void 0;
|
|
4
|
+
const http_wait_strategy_1 = require("./http-wait-strategy");
|
|
5
|
+
const health_check_wait_strategy_1 = require("./health-check-wait-strategy");
|
|
6
|
+
const log_wait_strategy_1 = require("./log-wait-strategy");
|
|
7
|
+
const shell_wait_strategy_1 = require("./shell-wait-strategy");
|
|
8
|
+
class Wait {
|
|
9
|
+
static forLogMessage(message, times = 1) {
|
|
10
|
+
return new log_wait_strategy_1.LogWaitStrategy(message, times);
|
|
11
|
+
}
|
|
12
|
+
static forHealthCheck() {
|
|
13
|
+
return new health_check_wait_strategy_1.HealthCheckWaitStrategy();
|
|
14
|
+
}
|
|
15
|
+
static forHttp(path, port) {
|
|
16
|
+
return new http_wait_strategy_1.HttpWaitStrategy(path, port);
|
|
17
|
+
}
|
|
18
|
+
static forSuccessfulCommand(command) {
|
|
19
|
+
return new shell_wait_strategy_1.ShellWaitStrategy(command);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Wait = Wait;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testcontainers",
|
|
3
3
|
"author": "Cristian Greco",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.5.0",
|
|
5
5
|
"main": "dist/src/index",
|
|
6
6
|
"types": "dist/src/index",
|
|
7
7
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@balena/dockerignore": "^1.0.2",
|
|
40
40
|
"@types/archiver": "^5.3.2",
|
|
41
|
-
"@types/dockerode": "^3.3.
|
|
41
|
+
"@types/dockerode": "^3.3.16",
|
|
42
42
|
"archiver": "^5.3.1",
|
|
43
43
|
"async-lock": "^1.4.0",
|
|
44
44
|
"byline": "^5.0.0",
|
|
@@ -56,33 +56,33 @@
|
|
|
56
56
|
"@types/async-lock": "^1.4.0",
|
|
57
57
|
"@types/byline": "^4.2.33",
|
|
58
58
|
"@types/debug": "4.1.7",
|
|
59
|
-
"@types/jest": "^29.
|
|
60
|
-
"@types/node": "^18.11
|
|
61
|
-
"@types/node-fetch": "^2.6.
|
|
59
|
+
"@types/jest": "^29.5.0",
|
|
60
|
+
"@types/node": "^18.15.11",
|
|
61
|
+
"@types/node-fetch": "^2.6.3",
|
|
62
62
|
"@types/pg": "^8.6.6",
|
|
63
63
|
"@types/properties-reader": "^2.1.1",
|
|
64
64
|
"@types/tar-fs": "^2.0.1",
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
66
|
-
"@typescript-eslint/parser": "^5.
|
|
67
|
-
"arangojs": "^8.
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
66
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
67
|
+
"arangojs": "^8.2.0",
|
|
68
68
|
"cross-env": "^7.0.3",
|
|
69
|
-
"eslint": "^8.
|
|
70
|
-
"eslint-config-prettier": "^8.
|
|
69
|
+
"eslint": "^8.37.0",
|
|
70
|
+
"eslint-config-prettier": "^8.8.0",
|
|
71
71
|
"eslint-plugin-prettier": "^4.2.1",
|
|
72
72
|
"husky": "^8.0.3",
|
|
73
73
|
"jest": "^29.5.0",
|
|
74
74
|
"kafkajs": "^2.2.4",
|
|
75
|
-
"lint-staged": "^13.0
|
|
76
|
-
"mongoose": "^6.
|
|
75
|
+
"lint-staged": "^13.2.0",
|
|
76
|
+
"mongoose": "^6.10.4",
|
|
77
77
|
"mysql2": "^2.3.3",
|
|
78
|
-
"nats": "^2.
|
|
79
|
-
"neo4j-driver": "^5.
|
|
80
|
-
"pg": "^8.
|
|
81
|
-
"prettier": "^2.7
|
|
78
|
+
"nats": "^2.13.1",
|
|
79
|
+
"neo4j-driver": "^5.6.0",
|
|
80
|
+
"pg": "^8.10.0",
|
|
81
|
+
"prettier": "^2.8.7",
|
|
82
82
|
"rimraf": "^3.0.2",
|
|
83
83
|
"ts-jest": "^29.0.5",
|
|
84
84
|
"ts-node": "^10.9.1",
|
|
85
|
-
"typescript": "^4.
|
|
85
|
+
"typescript": "^4.9.5",
|
|
86
86
|
"wait-for-expect": "^3.0.2"
|
|
87
87
|
},
|
|
88
88
|
"lint-staged": {
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BoundPorts } from "./bound-ports";
|
|
2
|
-
import { PortCheck } from "./port-check";
|
|
3
|
-
import Dockerode from "dockerode";
|
|
4
|
-
export interface WaitStrategy {
|
|
5
|
-
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
6
|
-
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class AbstractWaitStrategy implements WaitStrategy {
|
|
9
|
-
protected startupTimeout: number;
|
|
10
|
-
abstract waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
11
|
-
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
12
|
-
}
|
|
13
|
-
export declare class HostPortWaitStrategy extends AbstractWaitStrategy {
|
|
14
|
-
private readonly hostPortCheck;
|
|
15
|
-
private readonly internalPortCheck;
|
|
16
|
-
constructor(hostPortCheck: PortCheck, internalPortCheck: PortCheck);
|
|
17
|
-
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
18
|
-
private waitForHostPorts;
|
|
19
|
-
private waitForInternalPorts;
|
|
20
|
-
private waitForPort;
|
|
21
|
-
}
|
|
22
|
-
export type Log = string;
|
|
23
|
-
export declare class LogWaitStrategy extends AbstractWaitStrategy {
|
|
24
|
-
private readonly message;
|
|
25
|
-
private readonly times;
|
|
26
|
-
constructor(message: Log | RegExp, times: number);
|
|
27
|
-
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
export declare class HealthCheckWaitStrategy extends AbstractWaitStrategy {
|
|
30
|
-
waitUntilReady(container: Dockerode.Container): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
export declare const defaultWaitStrategy: (host: string, container: Dockerode.Container) => HostPortWaitStrategy;
|