testcontainers 7.20.5 → 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/README.md +10 -0
- package/dist/docker/functions/container/remove-container.js +12 -3
- package/dist/docker/functions/container/start-container.js +12 -3
- package/dist/docker/get-docker-host.js +1 -1
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -2
- package/dist/docker-compose-environment/docker-compose-environment.js +21 -6
- package/dist/docker-ignore.js +11 -16
- package/dist/generic-container/started-generic-container.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/modules/abstract-started-container.d.ts +1 -2
- package/dist/modules/kafka/kafka-container.js +1 -1
- package/dist/modules/mysql/mysql-container.d.ts +30 -0
- package/dist/modules/mysql/mysql-container.js +98 -0
- package/dist/reaper.js +3 -4
- package/dist/registry-auth-locator/credential-provider.js +1 -1
- package/dist/wait-strategy.js +6 -11
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -523,6 +523,16 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
|
|
|
523
523
|
.up();
|
|
524
524
|
```
|
|
525
525
|
|
|
526
|
+
Specify not to re-create containers that are already running:
|
|
527
|
+
|
|
528
|
+
```javascript
|
|
529
|
+
const { DockerComposeEnvironment } = require("testcontainers");
|
|
530
|
+
|
|
531
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
532
|
+
.withNoRecreate()
|
|
533
|
+
.up();
|
|
534
|
+
```
|
|
535
|
+
|
|
526
536
|
Bind environment variables to the docker-compose file. For example if we have the following docker-compose file:
|
|
527
537
|
|
|
528
538
|
```yaml
|
|
@@ -1,14 +1,23 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.removeContainer = void 0;
|
|
4
13
|
const logger_1 = require("../../../logger");
|
|
5
|
-
const removeContainer = (container, options) => {
|
|
14
|
+
const removeContainer = (container, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6
15
|
try {
|
|
7
|
-
|
|
16
|
+
yield container.remove({ v: options.removeVolumes });
|
|
8
17
|
}
|
|
9
18
|
catch (err) {
|
|
10
19
|
logger_1.log.error(`Failed to remove container ${container.id}: ${err}`);
|
|
11
20
|
throw err;
|
|
12
21
|
}
|
|
13
|
-
};
|
|
22
|
+
});
|
|
14
23
|
exports.removeContainer = removeContainer;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.startContainer = void 0;
|
|
4
13
|
const logger_1 = require("../../../logger");
|
|
5
|
-
const startContainer = (container) => {
|
|
14
|
+
const startContainer = (container) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6
15
|
try {
|
|
7
|
-
|
|
16
|
+
yield container.start();
|
|
8
17
|
}
|
|
9
18
|
catch (err) {
|
|
10
19
|
logger_1.log.error(`Failed to start container ${container.id}: ${err}`);
|
|
11
20
|
throw err;
|
|
12
21
|
}
|
|
13
|
-
};
|
|
22
|
+
});
|
|
14
23
|
exports.startContainer = startContainer;
|
|
@@ -55,6 +55,6 @@ const hostStrategies = (dockerode) => ({
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}),
|
|
58
|
-
CONTAINER_GATEWAY: () => __awaiter(void 0, void 0, void 0, function* () { return
|
|
58
|
+
CONTAINER_GATEWAY: () => __awaiter(void 0, void 0, void 0, function* () { return run_in_container_1.runInContainer("alpine:3.5", ["sh", "-c", "ip route|awk '/default/ { print $3 }'"]); }),
|
|
59
59
|
});
|
|
60
60
|
const isInContainer = () => fs_1.default.existsSync("/.dockerenv");
|
|
@@ -3,15 +3,18 @@ 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;
|
|
9
11
|
private env;
|
|
10
12
|
private waitStrategy;
|
|
11
13
|
private startupTimeout;
|
|
12
14
|
constructor(composeFilePath: string, composeFiles: string | string[], uuid?: Uuid);
|
|
13
15
|
withBuild(): this;
|
|
14
16
|
withEnv(key: EnvKey, value: EnvValue): this;
|
|
17
|
+
withNoRecreate(): this;
|
|
15
18
|
withWaitStrategy(containerName: string, waitStrategy: WaitStrategy): this;
|
|
16
19
|
withStartupTimeout(startupTimeout: number): this;
|
|
17
20
|
up(services?: Array<string>): Promise<StartedDockerComposeEnvironment>;
|
|
@@ -29,11 +29,13 @@ 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;
|
|
32
33
|
this.env = {};
|
|
33
34
|
this.waitStrategy = {};
|
|
34
35
|
this.startupTimeout = 60000;
|
|
36
|
+
this.composeFilePath = composeFilePath;
|
|
37
|
+
this.composeFiles = composeFiles;
|
|
35
38
|
this.projectName = `testcontainers-${uuid.nextUuid()}`;
|
|
36
|
-
this.options = { filePath: composeFilePath, files: composeFiles, projectName: this.projectName };
|
|
37
39
|
}
|
|
38
40
|
withBuild() {
|
|
39
41
|
this.build = true;
|
|
@@ -43,6 +45,11 @@ class DockerComposeEnvironment {
|
|
|
43
45
|
this.env[key] = value;
|
|
44
46
|
return this;
|
|
45
47
|
}
|
|
48
|
+
withNoRecreate() {
|
|
49
|
+
this.recreate = false;
|
|
50
|
+
this.projectName = "testcontainers-node";
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
46
53
|
withWaitStrategy(containerName, waitStrategy) {
|
|
47
54
|
this.waitStrategy[containerName] = waitStrategy;
|
|
48
55
|
return this;
|
|
@@ -53,13 +60,21 @@ class DockerComposeEnvironment {
|
|
|
53
60
|
}
|
|
54
61
|
up(services) {
|
|
55
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
logger_1.log.info(`Starting DockerCompose environment ${this.projectName}`);
|
|
63
|
+
logger_1.log.info(`Starting DockerCompose environment: ${this.projectName}`);
|
|
57
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
|
+
};
|
|
58
70
|
const commandOptions = [];
|
|
59
71
|
if (this.build) {
|
|
60
72
|
commandOptions.push("--build");
|
|
61
73
|
}
|
|
62
|
-
|
|
74
|
+
if (!this.recreate) {
|
|
75
|
+
commandOptions.push("--no-recreate");
|
|
76
|
+
}
|
|
77
|
+
yield docker_compose_up_1.dockerComposeUp(Object.assign(Object.assign({}, options), { commandOptions, env: this.env }), services);
|
|
63
78
|
const startedContainers = (yield list_containers_1.listContainers()).filter((container) => container.Labels["com.docker.compose.project"] === this.projectName);
|
|
64
79
|
const startedContainerNames = startedContainers.reduce((containerNames, startedContainer) => [
|
|
65
80
|
...containerNames,
|
|
@@ -67,7 +82,7 @@ class DockerComposeEnvironment {
|
|
|
67
82
|
], []);
|
|
68
83
|
logger_1.log.info(`Started the following containers: ${startedContainerNames.join(", ")}`);
|
|
69
84
|
const startedGenericContainers = (yield Promise.all(startedContainers.map((startedContainer) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const container =
|
|
85
|
+
const container = get_container_1.getContainerById(startedContainer.Id);
|
|
71
86
|
const containerName = container_name_resolver_1.resolveContainerName(this.projectName, startedContainer.Names[0]);
|
|
72
87
|
(yield container_logs_1.containerLogs(container))
|
|
73
88
|
.on("data", (data) => logger_1.containerLog.trace(`${containerName}: ${data}`))
|
|
@@ -82,7 +97,7 @@ class DockerComposeEnvironment {
|
|
|
82
97
|
catch (err) {
|
|
83
98
|
logger_1.log.error(`Container ${containerName} failed to be ready: ${err}`);
|
|
84
99
|
try {
|
|
85
|
-
yield docker_compose_down_1.dockerComposeDown(
|
|
100
|
+
yield docker_compose_down_1.dockerComposeDown(options);
|
|
86
101
|
}
|
|
87
102
|
catch (_a) {
|
|
88
103
|
logger_1.log.warn(`Failed to stop DockerCompose environment after failed up`);
|
|
@@ -95,7 +110,7 @@ class DockerComposeEnvironment {
|
|
|
95
110
|
return Object.assign(Object.assign({}, map), { [containerName]: startedGenericContainer });
|
|
96
111
|
}, {});
|
|
97
112
|
logger_1.log.info(`DockerCompose environment started: ${Object.keys(startedGenericContainers).join(", ")}`);
|
|
98
|
-
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers,
|
|
113
|
+
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, options);
|
|
99
114
|
});
|
|
100
115
|
}
|
|
101
116
|
getBoundPorts(containerInfo) {
|
package/dist/docker-ignore.js
CHANGED
|
@@ -18,28 +18,23 @@ const os_1 = __importDefault(require("os"));
|
|
|
18
18
|
const glob_1 = __importDefault(require("glob"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const findDockerIgnoreFiles = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
const dockerIgnoreFiles = new Set();
|
|
22
21
|
const dockerIgnoreFilePath = path_1.default.join(context, ".dockerignore");
|
|
23
22
|
if (!fs_1.existsSync(dockerIgnoreFilePath)) {
|
|
24
|
-
return
|
|
23
|
+
return new Set();
|
|
25
24
|
}
|
|
26
25
|
const dockerIgnorePatterns = (yield fs_1.promises.readFile(dockerIgnoreFilePath, { encoding: "utf-8" }))
|
|
27
26
|
.toString()
|
|
28
27
|
.split(os_1.default.EOL)
|
|
29
28
|
.map((dockerIgnorePattern) => path_1.default.resolve(context, dockerIgnorePattern));
|
|
30
|
-
const dockerIgnoreMatches = yield Promise.all(dockerIgnorePatterns.map((
|
|
31
|
-
|
|
32
|
-
if (err) {
|
|
33
|
-
return reject(err);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
resolve(matches);
|
|
37
|
-
}
|
|
38
|
-
}));
|
|
39
|
-
}));
|
|
40
|
-
dockerIgnoreMatches.forEach((dockerIgnoreFileBatch) => {
|
|
41
|
-
dockerIgnoreFileBatch.forEach((dockerIgnoreFile) => dockerIgnoreFiles.add(dockerIgnoreFile));
|
|
42
|
-
});
|
|
43
|
-
return dockerIgnoreFiles;
|
|
29
|
+
const dockerIgnoreMatches = (yield Promise.all(dockerIgnorePatterns.map(findIgnoredFilesForPattern))).reduce((prev, next) => [...prev, ...next]);
|
|
30
|
+
return new Set(dockerIgnoreMatches);
|
|
44
31
|
});
|
|
45
32
|
exports.findDockerIgnoreFiles = findDockerIgnoreFiles;
|
|
33
|
+
const findIgnoredFilesForPattern = (dockerIgnorePattern) => new Promise((resolve, reject) => glob_1.default(dockerIgnorePattern, (err, matches) => {
|
|
34
|
+
if (err) {
|
|
35
|
+
return reject(err);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
resolve(matches);
|
|
39
|
+
}
|
|
40
|
+
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export { KafkaContainer, StartedKafkaContainer } from "./modules/kafka/kafka-con
|
|
|
14
14
|
export { Neo4jContainer, StartedNeo4jContainer } from "./modules/neo4j/neo4j-container";
|
|
15
15
|
export { ArangoDBContainer, StartedArangoContainer } from "./modules/arangodb/arangodb-container";
|
|
16
16
|
export { ElasticsearchContainer, StartedElasticsearchContainer } from "./modules/elasticsearch/elasticsearch-container";
|
|
17
|
+
export { MySqlContainer, StartedMySqlContainer } from "./modules/mysql/mysql-container";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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;
|
|
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");
|
|
@@ -39,3 +39,6 @@ Object.defineProperty(exports, "StartedArangoContainer", { enumerable: true, get
|
|
|
39
39
|
var elasticsearch_container_1 = require("./modules/elasticsearch/elasticsearch-container");
|
|
40
40
|
Object.defineProperty(exports, "ElasticsearchContainer", { enumerable: true, get: function () { return elasticsearch_container_1.ElasticsearchContainer; } });
|
|
41
41
|
Object.defineProperty(exports, "StartedElasticsearchContainer", { enumerable: true, get: function () { return elasticsearch_container_1.StartedElasticsearchContainer; } });
|
|
42
|
+
var mysql_container_1 = require("./modules/mysql/mysql-container");
|
|
43
|
+
Object.defineProperty(exports, "MySqlContainer", { enumerable: true, get: function () { return mysql_container_1.MySqlContainer; } });
|
|
44
|
+
Object.defineProperty(exports, "StartedMySqlContainer", { enumerable: true, get: function () { return mysql_container_1.StartedMySqlContainer; } });
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { StartedTestContainer, StopOptions, StoppedTestContainer } from "../test-container";
|
|
3
3
|
import { Port } from "../port";
|
|
4
|
-
import { ContainerName, Host, Id } from "../docker/types";
|
|
5
|
-
import { Command, ExecResult } from "../docker/types";
|
|
4
|
+
import { ContainerName, Host, Id, Command, ExecResult } from "../docker/types";
|
|
6
5
|
import { Readable } from "stream";
|
|
7
6
|
export declare class AbstractStartedContainer {
|
|
8
7
|
protected readonly startedTestContainer: StartedTestContainer;
|
|
@@ -63,7 +63,7 @@ class KafkaContainer extends generic_container_1.GenericContainer {
|
|
|
63
63
|
const zooKeeperHost = this.uuid.nextUuid();
|
|
64
64
|
zooKeeperPort = yield this.portGenerator.generatePort();
|
|
65
65
|
this.withEnv("KAFKA_ZOOKEEPER_CONNECT", `${zooKeeperHost}:${zooKeeperPort}`);
|
|
66
|
-
const zookeeperContainer =
|
|
66
|
+
const zookeeperContainer = new generic_container_1.GenericContainer(this.zooKeeperImage)
|
|
67
67
|
.withName(zooKeeperHost)
|
|
68
68
|
.withEnv("ZOOKEEPER_CLIENT_PORT", zooKeeperPort.toString());
|
|
69
69
|
if (this.networkMode !== undefined) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GenericContainer } from "../../generic-container/generic-container";
|
|
2
|
+
import { StartedTestContainer } from "../../test-container";
|
|
3
|
+
import { AbstractStartedContainer } from "../abstract-started-container";
|
|
4
|
+
import { Port } from "../../port";
|
|
5
|
+
export declare class MySqlContainer extends GenericContainer {
|
|
6
|
+
private database;
|
|
7
|
+
private username;
|
|
8
|
+
private userPassword;
|
|
9
|
+
private rootPassword;
|
|
10
|
+
constructor(image?: string);
|
|
11
|
+
withDatabase(database: string): this;
|
|
12
|
+
withUsername(username: string): this;
|
|
13
|
+
withRootPassword(rootPassword: string): this;
|
|
14
|
+
withUserPassword(userPassword: string): this;
|
|
15
|
+
start(): Promise<StartedMySqlContainer>;
|
|
16
|
+
}
|
|
17
|
+
export declare class StartedMySqlContainer extends AbstractStartedContainer {
|
|
18
|
+
private readonly database;
|
|
19
|
+
private readonly username;
|
|
20
|
+
private readonly userPassword;
|
|
21
|
+
private readonly rootPassword;
|
|
22
|
+
private readonly port;
|
|
23
|
+
constructor(startedTestContainer: StartedTestContainer, database: string, username: string, userPassword: string, rootPassword: string);
|
|
24
|
+
getPort(): Port;
|
|
25
|
+
getDatabase(): string;
|
|
26
|
+
getUsername(): string;
|
|
27
|
+
getUserPassword(): string;
|
|
28
|
+
getRootPassword(): string;
|
|
29
|
+
executeQuery(query: string, additionalFlags?: string[]): Promise<string>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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.StartedMySqlContainer = exports.MySqlContainer = void 0;
|
|
13
|
+
const generic_container_1 = require("../../generic-container/generic-container");
|
|
14
|
+
const uuid_1 = require("../../uuid");
|
|
15
|
+
const abstract_started_container_1 = require("../abstract-started-container");
|
|
16
|
+
class MySqlContainer extends generic_container_1.GenericContainer {
|
|
17
|
+
constructor(image = "mysql:8.0.26") {
|
|
18
|
+
super(image);
|
|
19
|
+
this.database = "test";
|
|
20
|
+
this.username = new uuid_1.RandomUuid().nextUuid();
|
|
21
|
+
this.userPassword = new uuid_1.RandomUuid().nextUuid();
|
|
22
|
+
this.rootPassword = new uuid_1.RandomUuid().nextUuid();
|
|
23
|
+
}
|
|
24
|
+
withDatabase(database) {
|
|
25
|
+
this.database = database;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
withUsername(username) {
|
|
29
|
+
this.username = username;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
withRootPassword(rootPassword) {
|
|
33
|
+
this.rootPassword = rootPassword;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
withUserPassword(userPassword) {
|
|
37
|
+
this.userPassword = userPassword;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
const _super = Object.create(null, {
|
|
42
|
+
start: { get: () => super.start }
|
|
43
|
+
});
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
this.withExposedPorts(3306)
|
|
46
|
+
.withEnv("MYSQL_DATABASE", this.database)
|
|
47
|
+
.withEnv("MYSQL_ROOT_PASSWORD", this.rootPassword)
|
|
48
|
+
.withEnv("MYSQL_USER", this.username)
|
|
49
|
+
.withEnv("MYSQL_PASSWORD", this.userPassword)
|
|
50
|
+
.withStartupTimeout(120000);
|
|
51
|
+
return new StartedMySqlContainer(yield _super.start.call(this), this.database, this.username, this.userPassword, this.rootPassword);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.MySqlContainer = MySqlContainer;
|
|
56
|
+
class StartedMySqlContainer extends abstract_started_container_1.AbstractStartedContainer {
|
|
57
|
+
constructor(startedTestContainer, database, username, userPassword, rootPassword) {
|
|
58
|
+
super(startedTestContainer);
|
|
59
|
+
this.database = database;
|
|
60
|
+
this.username = username;
|
|
61
|
+
this.userPassword = userPassword;
|
|
62
|
+
this.rootPassword = rootPassword;
|
|
63
|
+
this.port = startedTestContainer.getMappedPort(3306);
|
|
64
|
+
}
|
|
65
|
+
getPort() {
|
|
66
|
+
return this.port;
|
|
67
|
+
}
|
|
68
|
+
getDatabase() {
|
|
69
|
+
return this.database;
|
|
70
|
+
}
|
|
71
|
+
getUsername() {
|
|
72
|
+
return this.username;
|
|
73
|
+
}
|
|
74
|
+
getUserPassword() {
|
|
75
|
+
return this.userPassword;
|
|
76
|
+
}
|
|
77
|
+
getRootPassword() {
|
|
78
|
+
return this.rootPassword;
|
|
79
|
+
}
|
|
80
|
+
executeQuery(query, additionalFlags = []) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const result = yield this.startedTestContainer.exec([
|
|
83
|
+
"mysql",
|
|
84
|
+
"-u",
|
|
85
|
+
this.username,
|
|
86
|
+
`-p${this.userPassword}`,
|
|
87
|
+
"-e",
|
|
88
|
+
`${query};`,
|
|
89
|
+
...additionalFlags,
|
|
90
|
+
]);
|
|
91
|
+
if (result.exitCode !== 0) {
|
|
92
|
+
throw new Error(`executeQuery failed with exit code ${result.exitCode} for query: ${query}`);
|
|
93
|
+
}
|
|
94
|
+
return result.output;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.StartedMySqlContainer = StartedMySqlContainer;
|
package/dist/reaper.js
CHANGED
|
@@ -17,8 +17,7 @@ const session_id_1 = require("./docker/session-id");
|
|
|
17
17
|
const docker_host_1 = require("./docker/docker-host");
|
|
18
18
|
const images_1 = require("./images");
|
|
19
19
|
class RealReaper {
|
|
20
|
-
constructor(
|
|
21
|
-
this.sessionId = sessionId;
|
|
20
|
+
constructor(container, socket) {
|
|
22
21
|
this.container = container;
|
|
23
22
|
this.socket = socket;
|
|
24
23
|
}
|
|
@@ -100,11 +99,11 @@ class ReaperInstance {
|
|
|
100
99
|
logger_1.log.warn(`Connection to Reaper ${container.getId()} closed`);
|
|
101
100
|
}
|
|
102
101
|
});
|
|
103
|
-
return
|
|
102
|
+
return new Promise((resolve) => {
|
|
104
103
|
socket.connect(port, host, () => {
|
|
105
104
|
logger_1.log.debug(`Connected to Reaper ${container.getId()}`);
|
|
106
105
|
socket.write(`label=org.testcontainers.session-id=${session_id_1.sessionId}\r\n`);
|
|
107
|
-
const reaper = new RealReaper(
|
|
106
|
+
const reaper = new RealReaper(container, socket);
|
|
108
107
|
resolve(reaper);
|
|
109
108
|
});
|
|
110
109
|
});
|
|
@@ -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) => {
|
package/dist/wait-strategy.js
CHANGED
|
@@ -91,21 +91,16 @@ class LogWaitStrategy extends AbstractWaitStrategy {
|
|
|
91
91
|
return line.includes(this.message);
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
-
|
|
95
|
-
.on("data", (line) => {
|
|
96
|
-
if (comparisonFn(line)) {
|
|
97
|
-
stream.destroy();
|
|
98
|
-
clearTimeout(timeout);
|
|
99
|
-
resolve();
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
.on("err", (line) => {
|
|
94
|
+
const lineProcessor = (line) => {
|
|
103
95
|
if (comparisonFn(line)) {
|
|
104
96
|
stream.destroy();
|
|
105
97
|
clearTimeout(timeout);
|
|
106
98
|
resolve();
|
|
107
99
|
}
|
|
108
|
-
}
|
|
100
|
+
};
|
|
101
|
+
byline_1.default(stream)
|
|
102
|
+
.on("data", lineProcessor)
|
|
103
|
+
.on("err", lineProcessor)
|
|
109
104
|
.on("end", () => {
|
|
110
105
|
stream.destroy();
|
|
111
106
|
clearTimeout(timeout);
|
|
@@ -121,7 +116,7 @@ class HealthCheckWaitStrategy extends AbstractWaitStrategy {
|
|
|
121
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
117
|
logger_1.log.debug(`Waiting for health check`);
|
|
123
118
|
const retryStrategy = new retry_strategy_1.IntervalRetryStrategy(100);
|
|
124
|
-
const status = yield retryStrategy.retryUntil(() => __awaiter(this, void 0, void 0, function* () { return (yield inspect_container_1.inspectContainer(container)).healthCheckStatus; }), (
|
|
119
|
+
const status = yield retryStrategy.retryUntil(() => __awaiter(this, void 0, void 0, function* () { return (yield inspect_container_1.inspectContainer(container)).healthCheckStatus; }), (healthCheckStatus) => healthCheckStatus === "healthy" || healthCheckStatus === "unhealthy", () => {
|
|
125
120
|
const timeout = this.startupTimeout;
|
|
126
121
|
throw new Error(`Health check not healthy after ${timeout}ms for ${container.id}`);
|
|
127
122
|
}, this.startupTimeout);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testcontainers",
|
|
3
3
|
"author": "Cristian Greco",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.22.1-beta.0",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"keywords": [
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"docker-compose": "^0.23.13",
|
|
41
41
|
"dockerode": "^3.3.1",
|
|
42
42
|
"get-port": "^5.1.1",
|
|
43
|
-
"glob": "^7.
|
|
43
|
+
"glob": "^7.2.0",
|
|
44
44
|
"slash": "^3.0.0",
|
|
45
|
-
"ssh-remote-port-forward": "^1.0.
|
|
45
|
+
"ssh-remote-port-forward": "^1.0.4",
|
|
46
46
|
"tar-fs": "^2.1.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@types/debug": "4.1.7",
|
|
52
52
|
"@types/glob": "^7.1.4",
|
|
53
53
|
"@types/jest": "^27.0.2",
|
|
54
|
-
"@types/node": "^16.9.
|
|
54
|
+
"@types/node": "^16.9.6",
|
|
55
55
|
"@types/node-fetch": "^2.5.11",
|
|
56
56
|
"@types/pg": "^8.6.1",
|
|
57
57
|
"@types/tar-fs": "^2.0.1",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"jest": "^27.2.1",
|
|
66
66
|
"kafkajs": "^1.15.0",
|
|
67
67
|
"lint-staged": "^11.1.2",
|
|
68
|
+
"mysql2": "^2.3.0",
|
|
68
69
|
"neo4j-driver": "^4.3.3",
|
|
69
70
|
"node-fetch": "^2.6.1",
|
|
70
71
|
"pg": "^8.7.1",
|