testcontainers 9.0.1 → 9.1.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 +79 -0
- package/dist/docker-compose-environment/docker-compose-environment.js +1 -1
- package/dist/generic-container/generic-container.js +2 -2
- package/dist/generic-container/started-generic-container.js +1 -1
- package/dist/http-wait-strategy.d.ts +27 -0
- package/dist/http-wait-strategy.js +107 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/startup-check-strategy.d.ts +8 -0
- package/dist/startup-check-strategy.js +30 -0
- package/dist/wait-for-container.d.ts +1 -1
- package/dist/wait-for-container.js +2 -2
- package/dist/wait-strategy.d.ts +4 -5
- package/dist/wait-strategy.js +3 -2
- package/dist/wait.d.ts +2 -0
- package/dist/wait.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -832,6 +832,85 @@ const container = await new GenericContainer("redis")
|
|
|
832
832
|
.start();
|
|
833
833
|
```
|
|
834
834
|
|
|
835
|
+
### HTTP
|
|
836
|
+
|
|
837
|
+
Default behaviour of waiting for a 200 response:
|
|
838
|
+
|
|
839
|
+
```javascript
|
|
840
|
+
const { GenericContainer, Wait } = require("testcontainers");
|
|
841
|
+
|
|
842
|
+
const container = await new GenericContainer("redis")
|
|
843
|
+
.withExposedPorts(6379)
|
|
844
|
+
.withWaitStrategy(Wait.forHttp("/health", 8080))
|
|
845
|
+
.start();
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
Specify status code:
|
|
849
|
+
|
|
850
|
+
```javascript
|
|
851
|
+
.withWaitStrategy(Wait.forHttp("/health", 8080)
|
|
852
|
+
.forStatusCode(201))
|
|
853
|
+
|
|
854
|
+
.withWaitStrategy(Wait.forHttp("/health", 8080)
|
|
855
|
+
.forStatusCodeMatching(statusCode => statusCode === 201))
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
Specify response body:
|
|
859
|
+
|
|
860
|
+
```javascript
|
|
861
|
+
.withWaitStrategy(Wait.forHttp("/health", 8080)
|
|
862
|
+
.forResponsePredicate(response => response === "OK"))
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
Customise the request:
|
|
866
|
+
|
|
867
|
+
```javascript
|
|
868
|
+
.withWaitStrategy(Wait.forHttp("/health", 8080)
|
|
869
|
+
.withMethod("POST")
|
|
870
|
+
.withHeaders({ X_CUSTOM_VALUE: "custom" })
|
|
871
|
+
.withBasicCredentials("username", "password")
|
|
872
|
+
.withReadTimeout(10000))
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
Use TLS:
|
|
876
|
+
|
|
877
|
+
```javascript
|
|
878
|
+
.withWaitStrategy(Wait.forHttp("/health", 8443)
|
|
879
|
+
.useTls())
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
Allow insecure TLS:
|
|
883
|
+
|
|
884
|
+
```javascript
|
|
885
|
+
.withWaitStrategy(Wait.forHttp("/health", 8443)
|
|
886
|
+
.useTls()
|
|
887
|
+
.insecureTls())
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
### Other Startup Strategies
|
|
891
|
+
|
|
892
|
+
If none of these options meet your requirements, you can create your own subclass of `StartupCheckStrategy`:
|
|
893
|
+
|
|
894
|
+
```javascript
|
|
895
|
+
const Dockerode = require("dockerode");
|
|
896
|
+
const {
|
|
897
|
+
GenericContainer,
|
|
898
|
+
StartupCheckStrategy,
|
|
899
|
+
StartupStatus
|
|
900
|
+
} = require("testcontainers");
|
|
901
|
+
|
|
902
|
+
class ReadyAfterDelayWaitStrategy extends StartupCheckStrategy {
|
|
903
|
+
public checkStartupState(dockerClient: Dockerode, containerId: string): Promise<StartupStatus> {
|
|
904
|
+
return new Promise((resolve) => setTimeout(() => resolve("SUCCESS"), 3000));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
const container = await new GenericContainer("redis")
|
|
909
|
+
.withExposedPorts(6379)
|
|
910
|
+
.withWaitStrategy(new ReadyAfterDelayWaitStrategy())
|
|
911
|
+
.start();
|
|
912
|
+
```
|
|
913
|
+
|
|
835
914
|
## Authentication
|
|
836
915
|
|
|
837
916
|
Testcontainers will automatically pick up and use credentials from `$HOME/.docker/config.json`, using
|
|
@@ -108,7 +108,7 @@ class DockerComposeEnvironment {
|
|
|
108
108
|
const waitStrategy = (this.waitStrategy[containerName] ? this.waitStrategy[containerName] : (0, wait_strategy_1.defaultWaitStrategy)(host, container)).withStartupTimeout(this.startupTimeout);
|
|
109
109
|
try {
|
|
110
110
|
logger_1.log.info(`Waiting for container ${containerName} to be ready`);
|
|
111
|
-
yield (0, wait_for_container_1.waitForContainer)(container, waitStrategy, boundPorts);
|
|
111
|
+
yield (0, wait_for_container_1.waitForContainer)(container, waitStrategy, host, boundPorts);
|
|
112
112
|
logger_1.log.info(`Container ${containerName} is ready`);
|
|
113
113
|
}
|
|
114
114
|
catch (err) {
|
|
@@ -123,7 +123,7 @@ class GenericContainer {
|
|
|
123
123
|
const boundPorts = bound_ports_1.BoundPorts.fromInspectResult(inspectResult).filter(this.ports);
|
|
124
124
|
const host = (yield (0, docker_client_1.dockerClient)()).host;
|
|
125
125
|
const waitStrategy = ((_a = this.waitStrategy) !== null && _a !== void 0 ? _a : (0, wait_strategy_1.defaultWaitStrategy)(host, startedContainer)).withStartupTimeout(this.startupTimeout);
|
|
126
|
-
yield (0, wait_for_container_1.waitForContainer)(startedContainer, waitStrategy, boundPorts);
|
|
126
|
+
yield (0, wait_for_container_1.waitForContainer)(startedContainer, waitStrategy, host, boundPorts);
|
|
127
127
|
return new started_generic_container_1.StartedGenericContainer(startedContainer, host, inspectResult, boundPorts, inspectResult.name, waitStrategy);
|
|
128
128
|
});
|
|
129
129
|
}
|
|
@@ -163,7 +163,7 @@ class GenericContainer {
|
|
|
163
163
|
const boundPorts = bound_ports_1.BoundPorts.fromInspectResult(inspectResult).filter(this.ports);
|
|
164
164
|
const host = (yield (0, docker_client_1.dockerClient)()).host;
|
|
165
165
|
const waitStrategy = ((_a = this.waitStrategy) !== null && _a !== void 0 ? _a : (0, wait_strategy_1.defaultWaitStrategy)(host, container)).withStartupTimeout(this.startupTimeout);
|
|
166
|
-
yield (0, wait_for_container_1.waitForContainer)(container, waitStrategy, boundPorts);
|
|
166
|
+
yield (0, wait_for_container_1.waitForContainer)(container, waitStrategy, host, boundPorts);
|
|
167
167
|
const startedContainer = new started_generic_container_1.StartedGenericContainer(container, host, inspectResult, boundPorts, inspectResult.name, waitStrategy);
|
|
168
168
|
if (this.postStart) {
|
|
169
169
|
yield this.postStart(startedContainer, inspectResult, boundPorts);
|
|
@@ -40,7 +40,7 @@ class StartedGenericContainer {
|
|
|
40
40
|
yield (0, restart_container_1.restartContainer)(this.container, resolvedOptions);
|
|
41
41
|
this.inspectResult = yield (0, inspect_container_1.inspectContainer)(this.container);
|
|
42
42
|
this.boundPorts = bound_ports_1.BoundPorts.fromInspectResult(this.inspectResult).filter(Array.from(this.boundPorts.iterator()).map((port) => port[0]));
|
|
43
|
-
yield (0, wait_for_container_1.waitForContainer)(this.container, this.waitStrategy, this.boundPorts);
|
|
43
|
+
yield (0, wait_for_container_1.waitForContainer)(this.container, this.waitStrategy, this.host, this.boundPorts);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
stopContainer(options = {}) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Dockerode from "dockerode";
|
|
2
|
+
import { BoundPorts } from "./bound-ports";
|
|
3
|
+
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
4
|
+
export declare class HttpWaitStrategy extends AbstractWaitStrategy {
|
|
5
|
+
private readonly path;
|
|
6
|
+
private readonly port;
|
|
7
|
+
private protocol;
|
|
8
|
+
private method;
|
|
9
|
+
private headers;
|
|
10
|
+
private predicates;
|
|
11
|
+
private _allowInsecure;
|
|
12
|
+
private readTimeout;
|
|
13
|
+
constructor(path: string, port: number);
|
|
14
|
+
forStatusCode(statusCode: number): HttpWaitStrategy;
|
|
15
|
+
forStatusCodeMatching(predicate: (statusCode: number) => boolean): HttpWaitStrategy;
|
|
16
|
+
forResponsePredicate(predicate: (response: string) => boolean): HttpWaitStrategy;
|
|
17
|
+
withMethod(method: string): HttpWaitStrategy;
|
|
18
|
+
withHeaders(headers: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
}): HttpWaitStrategy;
|
|
21
|
+
withBasicCredentials(username: string, password: string): HttpWaitStrategy;
|
|
22
|
+
withReadTimeout(readTimeout: number): HttpWaitStrategy;
|
|
23
|
+
usingTls(): HttpWaitStrategy;
|
|
24
|
+
allowInsecure(): HttpWaitStrategy;
|
|
25
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
26
|
+
private getAgent;
|
|
27
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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.HttpWaitStrategy = void 0;
|
|
16
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
17
|
+
const retry_strategy_1 = require("./retry-strategy");
|
|
18
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
19
|
+
const https_1 = __importDefault(require("https"));
|
|
20
|
+
class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
21
|
+
constructor(path, port) {
|
|
22
|
+
super();
|
|
23
|
+
this.protocol = "http";
|
|
24
|
+
this.method = "GET";
|
|
25
|
+
this.headers = {};
|
|
26
|
+
this.predicates = [];
|
|
27
|
+
this._allowInsecure = false;
|
|
28
|
+
this.readTimeout = 1000;
|
|
29
|
+
this.path = path;
|
|
30
|
+
this.port = port;
|
|
31
|
+
}
|
|
32
|
+
forStatusCode(statusCode) {
|
|
33
|
+
this.predicates.push((response) => __awaiter(this, void 0, void 0, function* () { return response.status === statusCode; }));
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
forStatusCodeMatching(predicate) {
|
|
37
|
+
this.predicates.push((response) => __awaiter(this, void 0, void 0, function* () { return predicate(response.status); }));
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
forResponsePredicate(predicate) {
|
|
41
|
+
this.predicates.push((response) => __awaiter(this, void 0, void 0, function* () { return predicate(yield response.text()); }));
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
withMethod(method) {
|
|
45
|
+
this.method = method;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
withHeaders(headers) {
|
|
49
|
+
this.headers = Object.assign(Object.assign({}, this.headers), headers);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
withBasicCredentials(username, password) {
|
|
53
|
+
const base64Encoded = Buffer.from(`${username}:${password}`).toString("base64");
|
|
54
|
+
this.headers = Object.assign(Object.assign({}, this.headers), { Authorization: `Bearer ${base64Encoded}` });
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
withReadTimeout(readTimeout) {
|
|
58
|
+
this.readTimeout = readTimeout;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
usingTls() {
|
|
62
|
+
this.protocol = "https";
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
allowInsecure() {
|
|
66
|
+
this._allowInsecure = true;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
waitUntilReady(container, host, boundPorts) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
yield new retry_strategy_1.IntervalRetryStrategy(this.readTimeout).retryUntil(() => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
const url = `${this.protocol}://${host}:${boundPorts.getBinding(this.port)}${this.path}`;
|
|
74
|
+
return yield (0, node_fetch_1.default)(url, {
|
|
75
|
+
method: this.method,
|
|
76
|
+
timeout: this.readTimeout,
|
|
77
|
+
headers: this.headers,
|
|
78
|
+
agent: this.getAgent(),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (_a) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}), (response) => {
|
|
85
|
+
if (response === undefined) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
else if (!this.predicates.length) {
|
|
89
|
+
return response.ok;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return this.predicates.every((predicate) => predicate(response));
|
|
93
|
+
}
|
|
94
|
+
}, () => {
|
|
95
|
+
throw new Error(`URL ${this.path} not accessible after ${this.startupTimeout}ms for ${container.id}`);
|
|
96
|
+
}, this.startupTimeout);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getAgent() {
|
|
100
|
+
if (this._allowInsecure) {
|
|
101
|
+
return new https_1.default.Agent({
|
|
102
|
+
rejectUnauthorized: false,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.HttpWaitStrategy = HttpWaitStrategy;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { StoppedDockerComposeEnvironment } from "./docker-compose-environment/st
|
|
|
8
8
|
export { DownedDockerComposeEnvironment } from "./docker-compose-environment/downed-docker-compose-environment";
|
|
9
9
|
export { Network, StartedNetwork, StoppedNetwork } from "./network";
|
|
10
10
|
export { Wait } from "./wait";
|
|
11
|
+
export { StartupCheckStrategy, StartupStatus } from "./startup-check-strategy";
|
|
11
12
|
export { PullPolicy, DefaultPullPolicy, AlwaysPullPolicy } from "./pull-policy";
|
|
12
13
|
export { PostgreSqlContainer, StartedPostgreSqlContainer } from "./modules/postgresql/postgresql-container";
|
|
13
14
|
export { KafkaContainer, StartedKafkaContainer } from "./modules/kafka/kafka-container";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StartedMongoDBContainer = exports.MongoDBContainer = exports.StartedNatsContainer = exports.NatsContainer = exports.StartedMySqlContainer = exports.MySqlContainer = exports.StartedElasticsearchContainer = exports.ElasticsearchContainer = exports.StartedArangoContainer = exports.ArangoDBContainer = exports.StartedNeo4jContainer = exports.Neo4jContainer = exports.StartedKafkaContainer = exports.KafkaContainer = exports.StartedPostgreSqlContainer = exports.PostgreSqlContainer = exports.AlwaysPullPolicy = exports.DefaultPullPolicy = exports.Wait = exports.StoppedNetwork = exports.StartedNetwork = exports.Network = exports.DownedDockerComposeEnvironment = exports.StoppedDockerComposeEnvironment = exports.StartedDockerComposeEnvironment = exports.DockerComposeEnvironment = exports.TestContainers = exports.GenericContainerBuilder = exports.GenericContainer = void 0;
|
|
3
|
+
exports.StartedMongoDBContainer = exports.MongoDBContainer = exports.StartedNatsContainer = exports.NatsContainer = exports.StartedMySqlContainer = exports.MySqlContainer = exports.StartedElasticsearchContainer = exports.ElasticsearchContainer = exports.StartedArangoContainer = exports.ArangoDBContainer = exports.StartedNeo4jContainer = exports.Neo4jContainer = exports.StartedKafkaContainer = exports.KafkaContainer = exports.StartedPostgreSqlContainer = exports.PostgreSqlContainer = exports.AlwaysPullPolicy = exports.DefaultPullPolicy = exports.StartupCheckStrategy = exports.Wait = exports.StoppedNetwork = exports.StartedNetwork = exports.Network = exports.DownedDockerComposeEnvironment = exports.StoppedDockerComposeEnvironment = exports.StartedDockerComposeEnvironment = exports.DockerComposeEnvironment = exports.TestContainers = exports.GenericContainerBuilder = exports.GenericContainer = void 0;
|
|
4
4
|
var generic_container_1 = require("./generic-container/generic-container");
|
|
5
5
|
Object.defineProperty(exports, "GenericContainer", { enumerable: true, get: function () { return generic_container_1.GenericContainer; } });
|
|
6
6
|
var generic_container_builder_1 = require("./generic-container/generic-container-builder");
|
|
@@ -21,6 +21,8 @@ Object.defineProperty(exports, "StartedNetwork", { enumerable: true, get: functi
|
|
|
21
21
|
Object.defineProperty(exports, "StoppedNetwork", { enumerable: true, get: function () { return network_1.StoppedNetwork; } });
|
|
22
22
|
var wait_1 = require("./wait");
|
|
23
23
|
Object.defineProperty(exports, "Wait", { enumerable: true, get: function () { return wait_1.Wait; } });
|
|
24
|
+
var startup_check_strategy_1 = require("./startup-check-strategy");
|
|
25
|
+
Object.defineProperty(exports, "StartupCheckStrategy", { enumerable: true, get: function () { return startup_check_strategy_1.StartupCheckStrategy; } });
|
|
24
26
|
var pull_policy_1 = require("./pull-policy");
|
|
25
27
|
Object.defineProperty(exports, "DefaultPullPolicy", { enumerable: true, get: function () { return pull_policy_1.DefaultPullPolicy; } });
|
|
26
28
|
Object.defineProperty(exports, "AlwaysPullPolicy", { enumerable: true, get: function () { return pull_policy_1.AlwaysPullPolicy; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractWaitStrategy } from "./wait-strategy";
|
|
2
|
+
import Dockerode from "dockerode";
|
|
3
|
+
import { BoundPorts } from "./bound-ports";
|
|
4
|
+
export declare type StartupStatus = "PENDING" | "SUCCESS" | "FAIL";
|
|
5
|
+
export declare abstract class StartupCheckStrategy extends AbstractWaitStrategy {
|
|
6
|
+
abstract checkStartupState(dockerClient: Dockerode, containerId: string): Promise<StartupStatus>;
|
|
7
|
+
waitUntilReady(container: Dockerode.Container, host: string, ports: BoundPorts): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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.StartupCheckStrategy = void 0;
|
|
13
|
+
const wait_strategy_1 = require("./wait-strategy");
|
|
14
|
+
const retry_strategy_1 = require("./retry-strategy");
|
|
15
|
+
const docker_client_1 = require("./docker/docker-client");
|
|
16
|
+
class StartupCheckStrategy extends wait_strategy_1.AbstractWaitStrategy {
|
|
17
|
+
waitUntilReady(container, host, ports) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { dockerode } = yield (0, docker_client_1.dockerClient)();
|
|
20
|
+
const startupStatus = yield new retry_strategy_1.IntervalRetryStrategy(1000).retryUntil(() => __awaiter(this, void 0, void 0, function* () { return yield this.checkStartupState(dockerode, container.id); }), (startupStatus) => startupStatus === "SUCCESS" || startupStatus === "FAIL", () => new Error(`Container not accessible after ${this.startupTimeout}ms for ${container.id}`), this.startupTimeout);
|
|
21
|
+
if (startupStatus instanceof Error) {
|
|
22
|
+
throw startupStatus;
|
|
23
|
+
}
|
|
24
|
+
else if (startupStatus === "FAIL") {
|
|
25
|
+
throw new Error(`Container failed to start for ${container.id}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.StartupCheckStrategy = StartupCheckStrategy;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import Dockerode from "dockerode";
|
|
2
2
|
import { BoundPorts } from "./bound-ports";
|
|
3
3
|
import { WaitStrategy } from "./wait-strategy";
|
|
4
|
-
export declare const waitForContainer: (container: Dockerode.Container, waitStrategy: WaitStrategy, boundPorts: BoundPorts) => Promise<void>;
|
|
4
|
+
export declare const waitForContainer: (container: Dockerode.Container, waitStrategy: WaitStrategy, host: string, boundPorts: BoundPorts) => Promise<void>;
|
|
@@ -13,10 +13,10 @@ exports.waitForContainer = void 0;
|
|
|
13
13
|
const logger_1 = require("./logger");
|
|
14
14
|
const stop_container_1 = require("./docker/functions/container/stop-container");
|
|
15
15
|
const remove_container_1 = require("./docker/functions/container/remove-container");
|
|
16
|
-
const waitForContainer = (container, waitStrategy, boundPorts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const waitForContainer = (container, waitStrategy, host, boundPorts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
logger_1.log.debug(`Waiting for container to be ready: ${container.id}`);
|
|
18
18
|
try {
|
|
19
|
-
yield waitStrategy.waitUntilReady(container, boundPorts);
|
|
19
|
+
yield waitStrategy.waitUntilReady(container, host, boundPorts);
|
|
20
20
|
logger_1.log.info("Container is ready");
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
package/dist/wait-strategy.d.ts
CHANGED
|
@@ -2,19 +2,19 @@ import { BoundPorts } from "./bound-ports";
|
|
|
2
2
|
import { PortCheck } from "./port-check";
|
|
3
3
|
import Dockerode from "dockerode";
|
|
4
4
|
export interface WaitStrategy {
|
|
5
|
-
waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts): Promise<void>;
|
|
5
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
6
6
|
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
7
7
|
}
|
|
8
|
-
declare abstract class AbstractWaitStrategy implements WaitStrategy {
|
|
8
|
+
export declare abstract class AbstractWaitStrategy implements WaitStrategy {
|
|
9
9
|
protected startupTimeout: number;
|
|
10
|
-
abstract waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts): Promise<void>;
|
|
10
|
+
abstract waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
11
11
|
withStartupTimeout(startupTimeout: number): WaitStrategy;
|
|
12
12
|
}
|
|
13
13
|
export declare class HostPortWaitStrategy extends AbstractWaitStrategy {
|
|
14
14
|
private readonly hostPortCheck;
|
|
15
15
|
private readonly internalPortCheck;
|
|
16
16
|
constructor(hostPortCheck: PortCheck, internalPortCheck: PortCheck);
|
|
17
|
-
waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts): Promise<void>;
|
|
17
|
+
waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts): Promise<void>;
|
|
18
18
|
private waitForHostPorts;
|
|
19
19
|
private waitForInternalPorts;
|
|
20
20
|
private waitForPort;
|
|
@@ -29,4 +29,3 @@ export declare class HealthCheckWaitStrategy extends AbstractWaitStrategy {
|
|
|
29
29
|
waitUntilReady(container: Dockerode.Container): Promise<void>;
|
|
30
30
|
}
|
|
31
31
|
export declare const defaultWaitStrategy: (host: string, container: Dockerode.Container) => HostPortWaitStrategy;
|
|
32
|
-
export {};
|
package/dist/wait-strategy.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.defaultWaitStrategy = exports.HealthCheckWaitStrategy = exports.LogWaitStrategy = exports.HostPortWaitStrategy = void 0;
|
|
15
|
+
exports.defaultWaitStrategy = exports.HealthCheckWaitStrategy = exports.LogWaitStrategy = exports.HostPortWaitStrategy = exports.AbstractWaitStrategy = void 0;
|
|
16
16
|
const byline_1 = __importDefault(require("byline"));
|
|
17
17
|
const logger_1 = require("./logger");
|
|
18
18
|
const port_check_1 = require("./port-check");
|
|
@@ -28,13 +28,14 @@ class AbstractWaitStrategy {
|
|
|
28
28
|
return this;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
exports.AbstractWaitStrategy = AbstractWaitStrategy;
|
|
31
32
|
class HostPortWaitStrategy extends AbstractWaitStrategy {
|
|
32
33
|
constructor(hostPortCheck, internalPortCheck) {
|
|
33
34
|
super();
|
|
34
35
|
this.hostPortCheck = hostPortCheck;
|
|
35
36
|
this.internalPortCheck = internalPortCheck;
|
|
36
37
|
}
|
|
37
|
-
waitUntilReady(container, boundPorts) {
|
|
38
|
+
waitUntilReady(container, host, boundPorts) {
|
|
38
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
yield Promise.all([this.waitForHostPorts(container, boundPorts), this.waitForInternalPorts(container, boundPorts)]);
|
|
40
41
|
});
|
package/dist/wait.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Log, WaitStrategy } from "./wait-strategy";
|
|
2
|
+
import { HttpWaitStrategy } from "./http-wait-strategy";
|
|
2
3
|
export declare class Wait {
|
|
3
4
|
static forLogMessage(message: Log | RegExp): WaitStrategy;
|
|
4
5
|
static forHealthCheck(): WaitStrategy;
|
|
6
|
+
static forHttp(path: string, port: number): HttpWaitStrategy;
|
|
5
7
|
}
|
package/dist/wait.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Wait = void 0;
|
|
4
4
|
const wait_strategy_1 = require("./wait-strategy");
|
|
5
|
+
const http_wait_strategy_1 = require("./http-wait-strategy");
|
|
5
6
|
class Wait {
|
|
6
7
|
static forLogMessage(message) {
|
|
7
8
|
return new wait_strategy_1.LogWaitStrategy(message);
|
|
@@ -9,5 +10,8 @@ class Wait {
|
|
|
9
10
|
static forHealthCheck() {
|
|
10
11
|
return new wait_strategy_1.HealthCheckWaitStrategy();
|
|
11
12
|
}
|
|
13
|
+
static forHttp(path, port) {
|
|
14
|
+
return new http_wait_strategy_1.HttpWaitStrategy(path, port);
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
exports.Wait = Wait;
|