testcontainers 8.15.0 → 9.0.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 +160 -43
- package/dist/bound-ports.d.ts +4 -4
- package/dist/docker/docker-client.d.ts +1 -2
- package/dist/docker/functions/container/container-logs.js +1 -6
- package/dist/docker/functions/container/create-container.d.ts +9 -5
- package/dist/docker/functions/container/create-container.js +19 -6
- package/dist/docker/functions/container/exec-container.d.ts +2 -2
- package/dist/docker/functions/container/exec-container.js +10 -3
- package/dist/docker/functions/container/get-container.d.ts +1 -2
- package/dist/docker/functions/container/inspect-container.d.ts +2 -2
- package/dist/docker/functions/create-labels.d.ts +1 -1
- package/dist/docker/functions/image/build-image.d.ts +3 -2
- package/dist/docker/functions/image/build-image.js +14 -9
- package/dist/docker/functions/run-in-container.d.ts +1 -2
- package/dist/docker/types.d.ts +29 -22
- package/dist/docker-compose/default-docker-compose-options.d.ts +1 -1
- package/dist/docker-compose/default-docker-compose-options.js +2 -2
- package/dist/docker-compose/docker-compose-options.d.ts +2 -2
- package/dist/docker-compose/functions/docker-compose-down.d.ts +2 -1
- package/dist/docker-compose/functions/docker-compose-down.js +12 -2
- package/dist/docker-compose/functions/docker-compose-up.d.ts +1 -1
- package/dist/docker-compose/functions/docker-compose-up.js +1 -1
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -5
- package/dist/docker-compose-environment/docker-compose-environment.js +12 -12
- package/dist/docker-compose-environment/started-docker-compose-environment.d.ts +2 -1
- package/dist/docker-compose-environment/started-docker-compose-environment.js +3 -2
- package/dist/docker-compose-environment/stopped-docker-compose-environment.d.ts +2 -1
- package/dist/docker-compose-environment/stopped-docker-compose-environment.js +3 -2
- package/dist/generic-container/generic-container-builder.d.ts +5 -3
- package/dist/generic-container/generic-container-builder.js +8 -2
- package/dist/generic-container/generic-container.d.ts +24 -17
- package/dist/generic-container/generic-container.js +48 -24
- package/dist/generic-container/started-generic-container.d.ts +7 -8
- package/dist/generic-container/started-generic-container.js +1 -2
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +2 -1
- package/dist/modules/abstract-started-container.d.ts +6 -7
- package/dist/modules/arangodb/arangodb-container.js +2 -2
- package/dist/modules/elasticsearch/elasticsearch-container.js +2 -2
- package/dist/modules/kafka/kafka-container.d.ts +4 -5
- package/dist/modules/kafka/kafka-container.js +41 -34
- package/dist/modules/mongodb/mongodb-container.js +1 -1
- package/dist/modules/mysql/mysql-container.d.ts +1 -2
- package/dist/modules/mysql/mysql-container.js +7 -5
- package/dist/modules/nats/nats-container.d.ts +1 -1
- package/dist/modules/nats/nats-container.js +2 -2
- package/dist/modules/neo4j/neo4j-container.js +10 -4
- package/dist/modules/postgresql/postgresql-container.d.ts +1 -2
- package/dist/modules/postgresql/postgresql-container.js +5 -3
- package/dist/port-binder.d.ts +1 -2
- package/dist/port-check.d.ts +4 -6
- package/dist/port-check.js +1 -1
- package/dist/port-forwarder.d.ts +1 -2
- package/dist/port-forwarder.js +2 -2
- package/dist/port-generator.d.ts +4 -5
- package/dist/port.d.ts +3 -5
- package/dist/reaper.js +1 -1
- package/dist/test-container.d.ts +24 -14
- package/dist/test-containers.d.ts +1 -2
- package/package.json +29 -25
package/dist/docker/types.d.ts
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare type
|
|
5
|
-
|
|
6
|
-
[key in EnvKey]: EnvValue;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
export declare type Environment = {
|
|
5
|
+
[key in string]: string;
|
|
7
6
|
};
|
|
8
|
-
export declare type Dir = string;
|
|
9
7
|
export declare type BindMode = "rw" | "ro" | "z" | "Z";
|
|
10
8
|
export declare type BindMount = {
|
|
11
|
-
source:
|
|
12
|
-
target:
|
|
13
|
-
|
|
9
|
+
source: string;
|
|
10
|
+
target: string;
|
|
11
|
+
mode?: BindMode;
|
|
12
|
+
};
|
|
13
|
+
export declare type FileToCopy = {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type Content = string | Buffer | Readable;
|
|
18
|
+
export declare type ContentToCopy = {
|
|
19
|
+
content: Content;
|
|
20
|
+
target: string;
|
|
14
21
|
};
|
|
15
22
|
export declare type TmpFs = {
|
|
16
|
-
[dir in
|
|
23
|
+
[dir in string]: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type Ulimits = {
|
|
26
|
+
[name: string]: {
|
|
27
|
+
hard: number | undefined;
|
|
28
|
+
soft: number | undefined;
|
|
29
|
+
};
|
|
17
30
|
};
|
|
18
31
|
export declare type HealthCheck = {
|
|
19
|
-
test: string;
|
|
32
|
+
test: ["CMD-SHELL", string] | ["CMD", ...string[]];
|
|
20
33
|
interval?: number;
|
|
21
34
|
timeout?: number;
|
|
22
35
|
retries?: number;
|
|
23
36
|
startPeriod?: number;
|
|
24
37
|
};
|
|
25
38
|
export declare type ExtraHost = {
|
|
26
|
-
host:
|
|
39
|
+
host: string;
|
|
27
40
|
ipAddress: string;
|
|
28
41
|
};
|
|
29
|
-
export declare type NetworkMode = string;
|
|
30
|
-
export declare type ContainerName = string;
|
|
31
42
|
export declare type Labels = {
|
|
32
43
|
[key: string]: string;
|
|
33
44
|
};
|
|
@@ -46,16 +57,12 @@ export declare type RegistryConfig = {
|
|
|
46
57
|
password: string;
|
|
47
58
|
};
|
|
48
59
|
};
|
|
49
|
-
export declare type BuildContext = string;
|
|
50
60
|
export declare type BuildArgs = {
|
|
51
|
-
[key in
|
|
61
|
+
[key in string]: string;
|
|
52
62
|
};
|
|
53
|
-
export declare type StreamOutput = string;
|
|
54
|
-
export declare type ExitCode = number;
|
|
55
|
-
export declare type Command = string;
|
|
56
63
|
export declare type ExecResult = {
|
|
57
|
-
output:
|
|
58
|
-
exitCode:
|
|
64
|
+
output: string;
|
|
65
|
+
exitCode: number;
|
|
59
66
|
};
|
|
60
67
|
export declare type HealthCheckStatus = "none" | "starting" | "unhealthy" | "healthy";
|
|
61
68
|
export declare type NetworkSettings = {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IDockerComposeOptions } from "./docker-compose";
|
|
2
2
|
import { DockerComposeOptions } from "./docker-compose-options";
|
|
3
|
-
export declare const defaultDockerComposeOptions: ({
|
|
3
|
+
export declare const defaultDockerComposeOptions: ({ environment, ...options }: DockerComposeOptions) => Partial<IDockerComposeOptions>;
|
|
@@ -13,14 +13,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.defaultDockerComposeOptions = void 0;
|
|
15
15
|
const defaultDockerComposeOptions = (_a) => {
|
|
16
|
-
var {
|
|
16
|
+
var { environment = {} } = _a, options = __rest(_a, ["environment"]);
|
|
17
17
|
return {
|
|
18
18
|
log: false,
|
|
19
19
|
cwd: options.filePath,
|
|
20
20
|
config: options.files,
|
|
21
21
|
composeOptions: options.composeOptions,
|
|
22
22
|
commandOptions: options.commandOptions,
|
|
23
|
-
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }),
|
|
23
|
+
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }), environment),
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
exports.defaultDockerComposeOptions = defaultDockerComposeOptions;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Environment } from "../docker/types";
|
|
2
2
|
export declare type DockerComposeOptions = {
|
|
3
3
|
filePath: string;
|
|
4
4
|
files: string | string[];
|
|
5
5
|
projectName: string;
|
|
6
6
|
commandOptions?: string[];
|
|
7
7
|
composeOptions?: string[];
|
|
8
|
-
|
|
8
|
+
environment?: Environment;
|
|
9
9
|
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DockerComposeOptions } from "../docker-compose-options";
|
|
2
|
-
|
|
2
|
+
import { DockerComposeDownOptions } from "../../test-container";
|
|
3
|
+
export declare const dockerComposeDown: (options: DockerComposeOptions, downOptions: DockerComposeDownOptions) => Promise<void>;
|
|
@@ -13,10 +13,10 @@ exports.dockerComposeDown = void 0;
|
|
|
13
13
|
const logger_1 = require("../../logger");
|
|
14
14
|
const default_docker_compose_options_1 = require("../default-docker-compose-options");
|
|
15
15
|
const docker_compose_1 = require("../docker-compose");
|
|
16
|
-
const dockerComposeDown = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const dockerComposeDown = (options, downOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
logger_1.log.info(`Downing DockerCompose environment`);
|
|
18
18
|
try {
|
|
19
|
-
yield (0, docker_compose_1.down)(Object.assign(Object.assign({}, (0, default_docker_compose_options_1.defaultDockerComposeOptions)(options)), { commandOptions:
|
|
19
|
+
yield (0, docker_compose_1.down)(Object.assign(Object.assign({}, (0, default_docker_compose_options_1.defaultDockerComposeOptions)(options)), { commandOptions: commandOptions(downOptions) }));
|
|
20
20
|
logger_1.log.info(`Downed DockerCompose environment`);
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
|
@@ -26,3 +26,13 @@ const dockerComposeDown = (options) => __awaiter(void 0, void 0, void 0, functio
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
exports.dockerComposeDown = dockerComposeDown;
|
|
29
|
+
const commandOptions = (options) => {
|
|
30
|
+
const result = [];
|
|
31
|
+
if (options.removeVolumes) {
|
|
32
|
+
result.push("-v");
|
|
33
|
+
}
|
|
34
|
+
if (options.timeout) {
|
|
35
|
+
result.push("-t", `${options.timeout / 1000}`);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DockerComposeOptions } from "../docker-compose-options";
|
|
2
|
-
export declare const dockerComposeUp: (options: DockerComposeOptions, services?: string
|
|
2
|
+
export declare const dockerComposeUp: (options: DockerComposeOptions, services?: Array<string>) => Promise<void>;
|
|
@@ -29,7 +29,7 @@ const dockerComposeUp = (options, services) => __awaiter(void 0, void 0, void 0,
|
|
|
29
29
|
const errorMessage = err.err || err.message || err;
|
|
30
30
|
logger_1.log.error(`Failed to up DockerCompose environment: ${errorMessage}`);
|
|
31
31
|
try {
|
|
32
|
-
yield (0, docker_compose_down_1.dockerComposeDown)(options);
|
|
32
|
+
yield (0, docker_compose_down_1.dockerComposeDown)(options, { removeVolumes: true, timeout: 0 });
|
|
33
33
|
}
|
|
34
34
|
catch (_a) {
|
|
35
35
|
logger_1.log.warn(`Failed to down DockerCompose environment after failed up`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WaitStrategy } from "../wait-strategy";
|
|
2
2
|
import { Uuid } from "../uuid";
|
|
3
|
-
import {
|
|
3
|
+
import { Environment } from "../docker/types";
|
|
4
4
|
import { StartedDockerComposeEnvironment } from "./started-docker-compose-environment";
|
|
5
5
|
export declare class DockerComposeEnvironment {
|
|
6
6
|
private readonly composeFilePath;
|
|
@@ -8,15 +8,15 @@ export declare class DockerComposeEnvironment {
|
|
|
8
8
|
private projectName;
|
|
9
9
|
private build;
|
|
10
10
|
private recreate;
|
|
11
|
-
private
|
|
11
|
+
private environmentFile;
|
|
12
12
|
private profiles;
|
|
13
|
-
private
|
|
13
|
+
private environment;
|
|
14
14
|
private waitStrategy;
|
|
15
15
|
private startupTimeout;
|
|
16
16
|
constructor(composeFilePath: string, composeFiles: string | string[], uuid?: Uuid);
|
|
17
17
|
withBuild(): this;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
withEnvironment(environment: Environment): this;
|
|
19
|
+
withEnvironmentFile(environmentFile: string): this;
|
|
20
20
|
withProfiles(...profiles: string[]): this;
|
|
21
21
|
withNoRecreate(): this;
|
|
22
22
|
withWaitStrategy(containerName: string, waitStrategy: WaitStrategy): this;
|
|
@@ -30,9 +30,9 @@ class DockerComposeEnvironment {
|
|
|
30
30
|
constructor(composeFilePath, composeFiles, uuid = new uuid_1.RandomUuid()) {
|
|
31
31
|
this.build = false;
|
|
32
32
|
this.recreate = true;
|
|
33
|
-
this.
|
|
33
|
+
this.environmentFile = "";
|
|
34
34
|
this.profiles = [];
|
|
35
|
-
this.
|
|
35
|
+
this.environment = {};
|
|
36
36
|
this.waitStrategy = {};
|
|
37
37
|
this.startupTimeout = 60000;
|
|
38
38
|
this.composeFilePath = composeFilePath;
|
|
@@ -43,16 +43,16 @@ class DockerComposeEnvironment {
|
|
|
43
43
|
this.build = true;
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
this.
|
|
46
|
+
withEnvironment(environment) {
|
|
47
|
+
this.environment = Object.assign(Object.assign({}, this.environment), environment);
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
this.
|
|
50
|
+
withEnvironmentFile(environmentFile) {
|
|
51
|
+
this.environmentFile = environmentFile;
|
|
52
52
|
return this;
|
|
53
53
|
}
|
|
54
54
|
withProfiles(...profiles) {
|
|
55
|
-
this.profiles = profiles;
|
|
55
|
+
this.profiles = [...this.profiles, ...profiles];
|
|
56
56
|
return this;
|
|
57
57
|
}
|
|
58
58
|
withNoRecreate() {
|
|
@@ -85,11 +85,11 @@ class DockerComposeEnvironment {
|
|
|
85
85
|
commandOptions.push("--no-recreate");
|
|
86
86
|
}
|
|
87
87
|
const composeOptions = [];
|
|
88
|
-
if (this.
|
|
89
|
-
composeOptions.push("--env-file", this.
|
|
88
|
+
if (this.environmentFile) {
|
|
89
|
+
composeOptions.push("--env-file", this.environmentFile);
|
|
90
90
|
}
|
|
91
91
|
this.profiles.forEach((profile) => composeOptions.push("--profile", profile));
|
|
92
|
-
yield (0, docker_compose_up_1.dockerComposeUp)(Object.assign(Object.assign({}, options), { commandOptions, composeOptions,
|
|
92
|
+
yield (0, docker_compose_up_1.dockerComposeUp)(Object.assign(Object.assign({}, options), { commandOptions, composeOptions, environment: this.environment }), services);
|
|
93
93
|
const startedContainers = (yield (0, list_containers_1.listContainers)()).filter((container) => container.Labels["com.docker.compose.project"] === this.projectName);
|
|
94
94
|
const startedContainerNames = startedContainers.reduce((containerNames, startedContainer) => [
|
|
95
95
|
...containerNames,
|
|
@@ -112,7 +112,7 @@ class DockerComposeEnvironment {
|
|
|
112
112
|
catch (err) {
|
|
113
113
|
logger_1.log.error(`Container ${containerName} failed to be ready: ${err}`);
|
|
114
114
|
try {
|
|
115
|
-
yield (0, docker_compose_down_1.dockerComposeDown)(options);
|
|
115
|
+
yield (0, docker_compose_down_1.dockerComposeDown)(options, { removeVolumes: true, timeout: 0 });
|
|
116
116
|
}
|
|
117
117
|
catch (_a) {
|
|
118
118
|
logger_1.log.warn(`Failed to stop DockerCompose environment after failed up`);
|
|
@@ -125,7 +125,7 @@ class DockerComposeEnvironment {
|
|
|
125
125
|
return Object.assign(Object.assign({}, map), { [containerName]: startedGenericContainer });
|
|
126
126
|
}, {});
|
|
127
127
|
logger_1.log.info(`DockerCompose environment started: ${Object.keys(startedGenericContainers).join(", ")}`);
|
|
128
|
-
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, Object.assign(Object.assign({}, options), { composeOptions,
|
|
128
|
+
return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, Object.assign(Object.assign({}, options), { composeOptions, environment: this.environment }));
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
waitForContainer(container, containerName, boundPorts) {
|
|
@@ -2,6 +2,7 @@ import { StartedGenericContainer } from "../generic-container/started-generic-co
|
|
|
2
2
|
import { StoppedDockerComposeEnvironment } from "./stopped-docker-compose-environment";
|
|
3
3
|
import { DownedDockerComposeEnvironment } from "./downed-docker-compose-environment";
|
|
4
4
|
import { DockerComposeOptions } from "../docker-compose/docker-compose-options";
|
|
5
|
+
import { DockerComposeDownOptions } from "../test-container";
|
|
5
6
|
export declare class StartedDockerComposeEnvironment {
|
|
6
7
|
private readonly startedGenericContainers;
|
|
7
8
|
private readonly options;
|
|
@@ -9,6 +10,6 @@ export declare class StartedDockerComposeEnvironment {
|
|
|
9
10
|
[containerName: string]: StartedGenericContainer;
|
|
10
11
|
}, options: DockerComposeOptions);
|
|
11
12
|
stop(): Promise<StoppedDockerComposeEnvironment>;
|
|
12
|
-
down(): Promise<DownedDockerComposeEnvironment>;
|
|
13
|
+
down(options?: Partial<DockerComposeDownOptions>): Promise<DownedDockerComposeEnvironment>;
|
|
13
14
|
getContainer(containerName: string): StartedGenericContainer;
|
|
14
15
|
}
|
|
@@ -26,9 +26,10 @@ class StartedDockerComposeEnvironment {
|
|
|
26
26
|
return new stopped_docker_compose_environment_1.StoppedDockerComposeEnvironment(this.options);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
down() {
|
|
29
|
+
down(options = {}) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
|
|
31
|
+
const downOptions = Object.assign({ timeout: 0, removeVolumes: true }, options);
|
|
32
|
+
yield (0, docker_compose_down_1.dockerComposeDown)(this.options, downOptions);
|
|
32
33
|
return new downed_docker_compose_environment_1.DownedDockerComposeEnvironment();
|
|
33
34
|
});
|
|
34
35
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DownedDockerComposeEnvironment } from "./downed-docker-compose-environment";
|
|
2
2
|
import { DockerComposeOptions } from "../docker-compose/docker-compose-options";
|
|
3
|
+
import { DockerComposeDownOptions } from "../test-container";
|
|
3
4
|
export declare class StoppedDockerComposeEnvironment {
|
|
4
5
|
private readonly options;
|
|
5
6
|
constructor(options: DockerComposeOptions);
|
|
6
|
-
down(): Promise<DownedDockerComposeEnvironment>;
|
|
7
|
+
down(options?: Partial<DockerComposeDownOptions>): Promise<DownedDockerComposeEnvironment>;
|
|
7
8
|
}
|
|
@@ -16,9 +16,10 @@ class StoppedDockerComposeEnvironment {
|
|
|
16
16
|
constructor(options) {
|
|
17
17
|
this.options = options;
|
|
18
18
|
}
|
|
19
|
-
down() {
|
|
19
|
+
down(options = {}) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
21
|
+
const resolvedOptions = Object.assign({ timeout: 0, removeVolumes: true }, options);
|
|
22
|
+
yield (0, docker_compose_down_1.dockerComposeDown)(this.options, resolvedOptions);
|
|
22
23
|
return new downed_docker_compose_environment_1.DownedDockerComposeEnvironment();
|
|
23
24
|
});
|
|
24
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuildArgs } from "../docker/types";
|
|
2
2
|
import { PullPolicy } from "../pull-policy";
|
|
3
3
|
import { Uuid } from "../uuid";
|
|
4
4
|
import { GenericContainer } from "./generic-container";
|
|
@@ -8,9 +8,11 @@ export declare class GenericContainerBuilder {
|
|
|
8
8
|
private readonly uuid;
|
|
9
9
|
private buildArgs;
|
|
10
10
|
private pullPolicy;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
private cache;
|
|
12
|
+
constructor(context: string, dockerfileName: string, uuid?: Uuid);
|
|
13
|
+
withBuildArgs(buildArgs: BuildArgs): GenericContainerBuilder;
|
|
13
14
|
withPullPolicy(pullPolicy: PullPolicy): this;
|
|
15
|
+
withCache(cache: boolean): this;
|
|
14
16
|
build(image?: string): Promise<GenericContainer>;
|
|
15
17
|
private getRegistryConfig;
|
|
16
18
|
}
|
|
@@ -32,15 +32,20 @@ class GenericContainerBuilder {
|
|
|
32
32
|
this.uuid = uuid;
|
|
33
33
|
this.buildArgs = {};
|
|
34
34
|
this.pullPolicy = new pull_policy_1.DefaultPullPolicy();
|
|
35
|
+
this.cache = true;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
this.buildArgs
|
|
37
|
+
withBuildArgs(buildArgs) {
|
|
38
|
+
this.buildArgs = buildArgs;
|
|
38
39
|
return this;
|
|
39
40
|
}
|
|
40
41
|
withPullPolicy(pullPolicy) {
|
|
41
42
|
this.pullPolicy = pullPolicy;
|
|
42
43
|
return this;
|
|
43
44
|
}
|
|
45
|
+
withCache(cache) {
|
|
46
|
+
this.cache = cache;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
44
49
|
build(image = `${this.uuid.nextUuid()}:${this.uuid.nextUuid()}`) {
|
|
45
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
51
|
const imageName = docker_image_name_1.DockerImageName.fromString(image);
|
|
@@ -55,6 +60,7 @@ class GenericContainerBuilder {
|
|
|
55
60
|
dockerfileName: this.dockerfileName,
|
|
56
61
|
buildArgs: this.buildArgs,
|
|
57
62
|
pullPolicy: this.pullPolicy,
|
|
63
|
+
cache: this.cache,
|
|
58
64
|
registryConfig,
|
|
59
65
|
});
|
|
60
66
|
const container = new generic_container_1.GenericContainer(imageName.toString());
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import archiver from "archiver";
|
|
3
2
|
import { BoundPorts } from "../bound-ports";
|
|
4
3
|
import { PortWithOptionalBinding } from "../port";
|
|
5
4
|
import { PullPolicy } from "../pull-policy";
|
|
6
5
|
import { StartedTestContainer, TestContainer } from "../test-container";
|
|
7
6
|
import { WaitStrategy } from "../wait-strategy";
|
|
8
|
-
import {
|
|
9
|
-
import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, ExtraHost, HealthCheck, NetworkMode, TmpFs, Labels } from "../docker/types";
|
|
7
|
+
import { BindMount, ContentToCopy, Environment, ExtraHost, FileToCopy, HealthCheck, Labels, TmpFs, Ulimits } from "../docker/types";
|
|
10
8
|
import { InspectResult } from "../docker/functions/container/inspect-container";
|
|
11
9
|
import { GenericContainerBuilder } from "./generic-container-builder";
|
|
10
|
+
import { StartedNetwork } from "../network";
|
|
12
11
|
export declare class GenericContainer implements TestContainer {
|
|
13
12
|
readonly image: string;
|
|
14
|
-
static fromDockerfile(context:
|
|
13
|
+
static fromDockerfile(context: string, dockerfileName?: string): GenericContainerBuilder;
|
|
15
14
|
private readonly imageName;
|
|
16
|
-
protected
|
|
17
|
-
protected networkMode?:
|
|
15
|
+
protected environment: Environment;
|
|
16
|
+
protected networkMode?: string;
|
|
18
17
|
protected networkAliases: string[];
|
|
19
18
|
protected ports: PortWithOptionalBinding[];
|
|
20
|
-
protected
|
|
19
|
+
protected command: string[];
|
|
20
|
+
protected entrypoint?: string[];
|
|
21
21
|
protected bindMounts: BindMount[];
|
|
22
|
-
protected name?:
|
|
22
|
+
protected name?: string;
|
|
23
23
|
protected labels: Labels;
|
|
24
24
|
protected tmpFs: TmpFs;
|
|
25
25
|
protected healthCheck?: HealthCheck;
|
|
@@ -28,6 +28,9 @@ export declare class GenericContainer implements TestContainer {
|
|
|
28
28
|
protected useDefaultLogDriver: boolean;
|
|
29
29
|
protected privilegedMode: boolean;
|
|
30
30
|
protected ipcMode?: string;
|
|
31
|
+
protected ulimits?: Ulimits;
|
|
32
|
+
protected addedCapabilities?: string[];
|
|
33
|
+
protected droppedCapabilities?: string[];
|
|
31
34
|
protected user?: string;
|
|
32
35
|
protected pullPolicy: PullPolicy;
|
|
33
36
|
protected reuse: boolean;
|
|
@@ -40,17 +43,21 @@ export declare class GenericContainer implements TestContainer {
|
|
|
40
43
|
private startContainer;
|
|
41
44
|
protected postStart?(container: StartedTestContainer, inspectResult: InspectResult, boundPorts: BoundPorts): Promise<void>;
|
|
42
45
|
protected get hasExposedPorts(): boolean;
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
withCommand(command: string[]): this;
|
|
47
|
+
withEntrypoint(entrypoint: string[]): this;
|
|
48
|
+
withName(name: string): this;
|
|
45
49
|
withLabels(labels: Labels): this;
|
|
46
|
-
|
|
50
|
+
withEnvironment(environment: Environment): this;
|
|
47
51
|
withTmpFs(tmpFs: TmpFs): this;
|
|
48
|
-
|
|
52
|
+
withUlimits(ulimits: Ulimits): this;
|
|
53
|
+
withAddedCapabilities(...capabilities: string[]): this;
|
|
54
|
+
withDroppedCapabilities(...capabilities: string[]): this;
|
|
55
|
+
withNetwork(network: StartedNetwork): this;
|
|
56
|
+
withNetworkMode(networkMode: string): this;
|
|
49
57
|
withNetworkAliases(...networkAliases: string[]): this;
|
|
50
|
-
withExtraHosts(
|
|
58
|
+
withExtraHosts(extraHosts: ExtraHost[]): this;
|
|
51
59
|
withExposedPorts(...ports: PortWithOptionalBinding[]): this;
|
|
52
|
-
|
|
53
|
-
withBindMount(source: Dir, target: Dir, bindMode?: BindMode): this;
|
|
60
|
+
withBindMounts(bindMounts: BindMount[]): this;
|
|
54
61
|
withHealthCheck(healthCheck: HealthCheck): this;
|
|
55
62
|
withStartupTimeout(startupTimeout: number): this;
|
|
56
63
|
withWaitStrategy(waitStrategy: WaitStrategy): this;
|
|
@@ -60,8 +67,8 @@ export declare class GenericContainer implements TestContainer {
|
|
|
60
67
|
withReuse(): this;
|
|
61
68
|
withPullPolicy(pullPolicy: PullPolicy): this;
|
|
62
69
|
withIpcMode(ipcMode: string): this;
|
|
63
|
-
|
|
64
|
-
withCopyContentToContainer(
|
|
70
|
+
withCopyFilesToContainer(filesToCopy: FileToCopy[]): this;
|
|
71
|
+
withCopyContentToContainer(contentsToCopy: ContentToCopy[]): this;
|
|
65
72
|
protected getTarToCopy(): archiver.Archiver;
|
|
66
73
|
private waitForContainer;
|
|
67
74
|
private getWaitStrategy;
|
|
@@ -41,10 +41,10 @@ const labels_1 = require("../labels");
|
|
|
41
41
|
class GenericContainer {
|
|
42
42
|
constructor(image) {
|
|
43
43
|
this.image = image;
|
|
44
|
-
this.
|
|
44
|
+
this.environment = {};
|
|
45
45
|
this.networkAliases = [];
|
|
46
46
|
this.ports = [];
|
|
47
|
-
this.
|
|
47
|
+
this.command = [];
|
|
48
48
|
this.bindMounts = [];
|
|
49
49
|
this.labels = {};
|
|
50
50
|
this.tmpFs = {};
|
|
@@ -78,8 +78,9 @@ class GenericContainer {
|
|
|
78
78
|
}
|
|
79
79
|
const createContainerOptions = {
|
|
80
80
|
imageName: this.imageName,
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
environment: this.environment,
|
|
82
|
+
command: this.command,
|
|
83
|
+
entrypoint: this.entrypoint,
|
|
83
84
|
bindMounts: this.bindMounts,
|
|
84
85
|
tmpFs: this.tmpFs,
|
|
85
86
|
exposedPorts: this.ports,
|
|
@@ -93,6 +94,9 @@ class GenericContainer {
|
|
|
93
94
|
autoRemove: this.imageName.isReaper(),
|
|
94
95
|
extraHosts: this.extraHosts,
|
|
95
96
|
ipcMode: this.ipcMode,
|
|
97
|
+
ulimits: this.ulimits,
|
|
98
|
+
addedCapabilities: this.addedCapabilities,
|
|
99
|
+
droppedCapabilities: this.droppedCapabilities,
|
|
96
100
|
user: this.user,
|
|
97
101
|
};
|
|
98
102
|
if (this.reuse) {
|
|
@@ -166,8 +170,12 @@ class GenericContainer {
|
|
|
166
170
|
get hasExposedPorts() {
|
|
167
171
|
return this.ports.length !== 0;
|
|
168
172
|
}
|
|
169
|
-
|
|
170
|
-
this.
|
|
173
|
+
withCommand(command) {
|
|
174
|
+
this.command = command;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
withEntrypoint(entrypoint) {
|
|
178
|
+
this.entrypoint = entrypoint;
|
|
171
179
|
return this;
|
|
172
180
|
}
|
|
173
181
|
withName(name) {
|
|
@@ -175,15 +183,33 @@ class GenericContainer {
|
|
|
175
183
|
return this;
|
|
176
184
|
}
|
|
177
185
|
withLabels(labels) {
|
|
178
|
-
this.labels = Object.assign({}, labels);
|
|
186
|
+
this.labels = Object.assign(Object.assign({}, this.labels), labels);
|
|
179
187
|
return this;
|
|
180
188
|
}
|
|
181
|
-
|
|
182
|
-
this.
|
|
189
|
+
withEnvironment(environment) {
|
|
190
|
+
this.environment = Object.assign(Object.assign({}, this.environment), environment);
|
|
183
191
|
return this;
|
|
184
192
|
}
|
|
185
193
|
withTmpFs(tmpFs) {
|
|
186
|
-
this.tmpFs = tmpFs;
|
|
194
|
+
this.tmpFs = Object.assign(Object.assign({}, this.tmpFs), tmpFs);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
withUlimits(ulimits) {
|
|
198
|
+
this.ulimits = Object.assign(Object.assign({}, this.ulimits), ulimits);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
withAddedCapabilities(...capabilities) {
|
|
202
|
+
var _a;
|
|
203
|
+
this.addedCapabilities = [...((_a = this.addedCapabilities) !== null && _a !== void 0 ? _a : []), ...capabilities];
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
withDroppedCapabilities(...capabilities) {
|
|
207
|
+
var _a;
|
|
208
|
+
this.droppedCapabilities = [...((_a = this.droppedCapabilities) !== null && _a !== void 0 ? _a : []), ...capabilities];
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
withNetwork(network) {
|
|
212
|
+
this.networkMode = network.getName();
|
|
187
213
|
return this;
|
|
188
214
|
}
|
|
189
215
|
withNetworkMode(networkMode) {
|
|
@@ -191,23 +217,19 @@ class GenericContainer {
|
|
|
191
217
|
return this;
|
|
192
218
|
}
|
|
193
219
|
withNetworkAliases(...networkAliases) {
|
|
194
|
-
this.networkAliases = networkAliases;
|
|
220
|
+
this.networkAliases = [...this.networkAliases, ...networkAliases];
|
|
195
221
|
return this;
|
|
196
222
|
}
|
|
197
|
-
withExtraHosts(
|
|
198
|
-
this.extraHosts.
|
|
223
|
+
withExtraHosts(extraHosts) {
|
|
224
|
+
this.extraHosts = [...this.extraHosts, ...extraHosts];
|
|
199
225
|
return this;
|
|
200
226
|
}
|
|
201
227
|
withExposedPorts(...ports) {
|
|
202
|
-
this.ports = ports;
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
addExposedPorts(...ports) {
|
|
206
|
-
this.ports.push(...ports);
|
|
228
|
+
this.ports = [...this.ports, ...ports];
|
|
207
229
|
return this;
|
|
208
230
|
}
|
|
209
|
-
|
|
210
|
-
this.bindMounts.
|
|
231
|
+
withBindMounts(bindMounts) {
|
|
232
|
+
this.bindMounts = bindMounts.map((bindMount) => (Object.assign({ mode: "rw" }, bindMount)));
|
|
211
233
|
return this;
|
|
212
234
|
}
|
|
213
235
|
withHealthCheck(healthCheck) {
|
|
@@ -246,12 +268,14 @@ class GenericContainer {
|
|
|
246
268
|
this.ipcMode = ipcMode;
|
|
247
269
|
return this;
|
|
248
270
|
}
|
|
249
|
-
|
|
250
|
-
this.getTarToCopy()
|
|
271
|
+
withCopyFilesToContainer(filesToCopy) {
|
|
272
|
+
const tar = this.getTarToCopy();
|
|
273
|
+
filesToCopy.forEach(({ source, target }) => tar.file(source, { name: target }));
|
|
251
274
|
return this;
|
|
252
275
|
}
|
|
253
|
-
withCopyContentToContainer(
|
|
254
|
-
this.getTarToCopy()
|
|
276
|
+
withCopyContentToContainer(contentsToCopy) {
|
|
277
|
+
const tar = this.getTarToCopy();
|
|
278
|
+
contentsToCopy.forEach(({ content, target }) => tar.append(content, { name: target }));
|
|
255
279
|
return this;
|
|
256
280
|
}
|
|
257
281
|
getTarToCopy() {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { RestartOptions, StartedTestContainer, StopOptions, ExecOptions, StoppedTestContainer } from "../test-container";
|
|
3
3
|
import Dockerode from "dockerode";
|
|
4
|
-
import {
|
|
4
|
+
import { ExecResult, Labels } from "../docker/types";
|
|
5
5
|
import { InspectResult } from "../docker/functions/container/inspect-container";
|
|
6
6
|
import { BoundPorts } from "../bound-ports";
|
|
7
|
-
import { Port } from "../port";
|
|
8
7
|
import { Readable } from "stream";
|
|
9
8
|
import { WaitStrategy } from "../wait-strategy";
|
|
10
9
|
export declare class StartedGenericContainer implements StartedTestContainer {
|
|
@@ -14,19 +13,19 @@ export declare class StartedGenericContainer implements StartedTestContainer {
|
|
|
14
13
|
private boundPorts;
|
|
15
14
|
private readonly name;
|
|
16
15
|
private readonly waitStrategy;
|
|
17
|
-
constructor(container: Dockerode.Container, host:
|
|
16
|
+
constructor(container: Dockerode.Container, host: string, inspectResult: InspectResult, boundPorts: BoundPorts, name: string, waitStrategy: WaitStrategy);
|
|
18
17
|
stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
|
|
19
18
|
restart(options?: Partial<RestartOptions>): Promise<void>;
|
|
20
19
|
private stopContainer;
|
|
21
20
|
private waitForContainer;
|
|
22
|
-
getHost():
|
|
23
|
-
getMappedPort(port:
|
|
24
|
-
getId():
|
|
25
|
-
getName():
|
|
21
|
+
getHost(): string;
|
|
22
|
+
getMappedPort(port: number): number;
|
|
23
|
+
getId(): string;
|
|
24
|
+
getName(): string;
|
|
26
25
|
getLabels(): Labels;
|
|
27
26
|
getNetworkNames(): string[];
|
|
28
27
|
getNetworkId(networkName: string): string;
|
|
29
28
|
getIpAddress(networkName: string): string;
|
|
30
|
-
exec(command:
|
|
29
|
+
exec(command: string[], options?: Partial<ExecOptions>): Promise<ExecResult>;
|
|
31
30
|
logs(): Promise<Readable>;
|
|
32
31
|
}
|
|
@@ -37,9 +37,8 @@ class StartedGenericContainer {
|
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
const resolvedOptions = Object.assign({ timeout: 0 }, options);
|
|
39
39
|
yield (0, restart_container_1.restartContainer)(this.container, resolvedOptions);
|
|
40
|
-
// Inspect the restarted container and update the bound ports
|
|
41
40
|
this.inspectResult = yield (0, inspect_container_1.inspectContainer)(this.container);
|
|
42
|
-
this.boundPorts =
|
|
41
|
+
this.boundPorts = bound_ports_1.BoundPorts.fromInspectResult(this.inspectResult).filter(Array.from(this.boundPorts.iterator()).map((port) => port[0]));
|
|
43
42
|
yield this.waitForContainer(this.container, this.boundPorts);
|
|
44
43
|
});
|
|
45
44
|
}
|