testcontainers 8.16.0 → 9.0.1

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.
Files changed (54) hide show
  1. package/README.md +115 -78
  2. package/dist/bound-ports.d.ts +4 -4
  3. package/dist/docker/docker-client.d.ts +1 -2
  4. package/dist/docker/functions/container/container-logs.js +1 -6
  5. package/dist/docker/functions/container/create-container.d.ts +5 -5
  6. package/dist/docker/functions/container/create-container.js +5 -6
  7. package/dist/docker/functions/container/exec-container.d.ts +2 -2
  8. package/dist/docker/functions/container/get-container.d.ts +1 -2
  9. package/dist/docker/functions/container/inspect-container.d.ts +2 -2
  10. package/dist/docker/functions/create-labels.d.ts +1 -1
  11. package/dist/docker/functions/image/build-image.d.ts +2 -2
  12. package/dist/docker/functions/run-in-container.d.ts +1 -2
  13. package/dist/docker/types.d.ts +23 -22
  14. package/dist/docker-compose/default-docker-compose-options.d.ts +1 -1
  15. package/dist/docker-compose/default-docker-compose-options.js +2 -2
  16. package/dist/docker-compose/docker-compose-options.d.ts +2 -2
  17. package/dist/docker-compose/functions/docker-compose-up.d.ts +1 -1
  18. package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -7
  19. package/dist/docker-compose-environment/docker-compose-environment.js +16 -30
  20. package/dist/generic-container/generic-container-builder.d.ts +3 -3
  21. package/dist/generic-container/generic-container-builder.js +2 -2
  22. package/dist/generic-container/generic-container.d.ts +16 -19
  23. package/dist/generic-container/generic-container.js +42 -63
  24. package/dist/generic-container/started-generic-container.d.ts +8 -10
  25. package/dist/generic-container/started-generic-container.js +2 -21
  26. package/dist/modules/abstract-started-container.d.ts +6 -7
  27. package/dist/modules/arangodb/arangodb-container.js +2 -2
  28. package/dist/modules/elasticsearch/elasticsearch-container.js +2 -2
  29. package/dist/modules/kafka/kafka-container.d.ts +4 -5
  30. package/dist/modules/kafka/kafka-container.js +41 -34
  31. package/dist/modules/mongodb/mongodb-container.js +1 -1
  32. package/dist/modules/mysql/mysql-container.d.ts +1 -2
  33. package/dist/modules/mysql/mysql-container.js +7 -5
  34. package/dist/modules/nats/nats-container.d.ts +1 -1
  35. package/dist/modules/nats/nats-container.js +2 -2
  36. package/dist/modules/neo4j/neo4j-container.js +10 -4
  37. package/dist/modules/postgresql/postgresql-container.d.ts +1 -2
  38. package/dist/modules/postgresql/postgresql-container.js +5 -3
  39. package/dist/port-binder.d.ts +1 -2
  40. package/dist/port-check.d.ts +4 -6
  41. package/dist/port-forwarder.d.ts +1 -2
  42. package/dist/port-forwarder.js +2 -2
  43. package/dist/port-generator.d.ts +4 -5
  44. package/dist/port.d.ts +3 -5
  45. package/dist/reaper.js +33 -22
  46. package/dist/retry-strategy.d.ts +1 -1
  47. package/dist/retry-strategy.js +3 -2
  48. package/dist/test-container.d.ts +16 -14
  49. package/dist/test-containers.d.ts +1 -2
  50. package/dist/wait-for-container.d.ts +4 -0
  51. package/dist/wait-for-container.js +34 -0
  52. package/dist/wait-strategy.d.ts +1 -0
  53. package/dist/wait-strategy.js +4 -1
  54. package/package.json +29 -25
@@ -1,6 +1,6 @@
1
1
  import { WaitStrategy } from "../wait-strategy";
2
2
  import { Uuid } from "../uuid";
3
- import { EnvKey, EnvValue } from "../docker/types";
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,20 +8,18 @@ export declare class DockerComposeEnvironment {
8
8
  private projectName;
9
9
  private build;
10
10
  private recreate;
11
- private envFile;
11
+ private environmentFile;
12
12
  private profiles;
13
- private env;
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
- withEnv(key: EnvKey, value: EnvValue): this;
19
- withEnvFile(envFile: string): this;
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;
23
23
  withStartupTimeout(startupTimeout: number): this;
24
24
  up(services?: Array<string>): Promise<StartedDockerComposeEnvironment>;
25
- private waitForContainer;
26
- private getWaitStrategy;
27
25
  }
@@ -14,7 +14,6 @@ const bound_ports_1 = require("../bound-ports");
14
14
  const container_name_resolver_1 = require("../docker-compose/functions/container-name-resolver");
15
15
  const started_generic_container_1 = require("../generic-container/started-generic-container");
16
16
  const logger_1 = require("../logger");
17
- const port_check_1 = require("../port-check");
18
17
  const wait_strategy_1 = require("../wait-strategy");
19
18
  const reaper_1 = require("../reaper");
20
19
  const uuid_1 = require("../uuid");
@@ -26,13 +25,14 @@ const container_logs_1 = require("../docker/functions/container/container-logs")
26
25
  const started_docker_compose_environment_1 = require("./started-docker-compose-environment");
27
26
  const docker_compose_down_1 = require("../docker-compose/functions/docker-compose-down");
28
27
  const docker_compose_up_1 = require("../docker-compose/functions/docker-compose-up");
28
+ const wait_for_container_1 = require("../wait-for-container");
29
29
  class DockerComposeEnvironment {
30
30
  constructor(composeFilePath, composeFiles, uuid = new uuid_1.RandomUuid()) {
31
31
  this.build = false;
32
32
  this.recreate = true;
33
- this.envFile = "";
33
+ this.environmentFile = "";
34
34
  this.profiles = [];
35
- this.env = {};
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
- withEnv(key, value) {
47
- this.env[key] = value;
46
+ withEnvironment(environment) {
47
+ this.environment = Object.assign(Object.assign({}, this.environment), environment);
48
48
  return this;
49
49
  }
50
- withEnvFile(envFile) {
51
- this.envFile = envFile;
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.envFile) {
89
- composeOptions.push("--env-file", this.envFile);
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, env: this.env }), services);
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,
@@ -104,9 +104,11 @@ class DockerComposeEnvironment {
104
104
  .on("err", (data) => logger_1.containerLog.error(`${containerName}: ${data}`));
105
105
  const inspectResult = yield (0, inspect_container_1.inspectContainer)(container);
106
106
  const boundPorts = bound_ports_1.BoundPorts.fromInspectResult(inspectResult);
107
+ const host = (yield (0, docker_client_1.dockerClient)()).host;
108
+ const waitStrategy = (this.waitStrategy[containerName] ? this.waitStrategy[containerName] : (0, wait_strategy_1.defaultWaitStrategy)(host, container)).withStartupTimeout(this.startupTimeout);
107
109
  try {
108
110
  logger_1.log.info(`Waiting for container ${containerName} to be ready`);
109
- yield this.waitForContainer(container, containerName, boundPorts);
111
+ yield (0, wait_for_container_1.waitForContainer)(container, waitStrategy, boundPorts);
110
112
  logger_1.log.info(`Container ${containerName} is ready`);
111
113
  }
112
114
  catch (err) {
@@ -119,30 +121,14 @@ class DockerComposeEnvironment {
119
121
  }
120
122
  throw err;
121
123
  }
122
- return new started_generic_container_1.StartedGenericContainer(container, (yield (0, docker_client_1.dockerClient)()).host, inspectResult, boundPorts, containerName, this.getWaitStrategy((yield (0, docker_client_1.dockerClient)()).host, container, containerName).withStartupTimeout(this.startupTimeout));
124
+ return new started_generic_container_1.StartedGenericContainer(container, host, inspectResult, boundPorts, containerName, waitStrategy);
123
125
  })))).reduce((map, startedGenericContainer) => {
124
126
  const containerName = startedGenericContainer.getName();
125
127
  return Object.assign(Object.assign({}, map), { [containerName]: startedGenericContainer });
126
128
  }, {});
127
129
  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, env: this.env }));
130
+ return new started_docker_compose_environment_1.StartedDockerComposeEnvironment(startedGenericContainers, Object.assign(Object.assign({}, options), { composeOptions, environment: this.environment }));
129
131
  });
130
132
  }
131
- waitForContainer(container, containerName, boundPorts) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- const waitStrategy = this.getWaitStrategy((yield (0, docker_client_1.dockerClient)()).host, container, containerName);
134
- yield waitStrategy.withStartupTimeout(this.startupTimeout).waitUntilReady(container, boundPorts);
135
- });
136
- }
137
- getWaitStrategy(host, container, containerName) {
138
- if (this.waitStrategy[containerName]) {
139
- return this.waitStrategy[containerName];
140
- }
141
- else {
142
- const hostPortCheck = new port_check_1.HostPortCheck(host);
143
- const internalPortCheck = new port_check_1.InternalPortCheck(container);
144
- return new wait_strategy_1.HostPortWaitStrategy(hostPortCheck, internalPortCheck);
145
- }
146
- }
147
133
  }
148
134
  exports.DockerComposeEnvironment = DockerComposeEnvironment;
@@ -1,4 +1,4 @@
1
- import { BuildContext } from "../docker/types";
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";
@@ -9,8 +9,8 @@ export declare class GenericContainerBuilder {
9
9
  private buildArgs;
10
10
  private pullPolicy;
11
11
  private cache;
12
- constructor(context: BuildContext, dockerfileName: string, uuid?: Uuid);
13
- withBuildArg(key: string, value: string): GenericContainerBuilder;
12
+ constructor(context: string, dockerfileName: string, uuid?: Uuid);
13
+ withBuildArgs(buildArgs: BuildArgs): GenericContainerBuilder;
14
14
  withPullPolicy(pullPolicy: PullPolicy): this;
15
15
  withCache(cache: boolean): this;
16
16
  build(image?: string): Promise<GenericContainer>;
@@ -34,8 +34,8 @@ class GenericContainerBuilder {
34
34
  this.pullPolicy = new pull_policy_1.DefaultPullPolicy();
35
35
  this.cache = true;
36
36
  }
37
- withBuildArg(key, value) {
38
- this.buildArgs[key] = value;
37
+ withBuildArgs(buildArgs) {
38
+ this.buildArgs = buildArgs;
39
39
  return this;
40
40
  }
41
41
  withPullPolicy(pullPolicy) {
@@ -1,26 +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 { Readable } from "stream";
9
- import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, ExtraHost, HealthCheck, NetworkMode, TmpFs, Labels, Ulimits } 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: BuildContext, dockerfileName?: string): GenericContainerBuilder;
13
+ static fromDockerfile(context: string, dockerfileName?: string): GenericContainerBuilder;
15
14
  private readonly imageName;
16
- protected env: Env;
17
- protected networkMode?: NetworkMode;
15
+ protected environment: Environment;
16
+ protected networkMode?: string;
18
17
  protected networkAliases: string[];
19
18
  protected ports: PortWithOptionalBinding[];
20
- protected cmd: Command[];
19
+ protected command: string[];
21
20
  protected entrypoint?: string[];
22
21
  protected bindMounts: BindMount[];
23
- protected name?: ContainerName;
22
+ protected name?: string;
24
23
  protected labels: Labels;
25
24
  protected tmpFs: TmpFs;
26
25
  protected healthCheck?: HealthCheck;
@@ -44,21 +43,21 @@ export declare class GenericContainer implements TestContainer {
44
43
  private startContainer;
45
44
  protected postStart?(container: StartedTestContainer, inspectResult: InspectResult, boundPorts: BoundPorts): Promise<void>;
46
45
  protected get hasExposedPorts(): boolean;
47
- withCmd(cmd: Command[]): this;
46
+ withCommand(command: string[]): this;
48
47
  withEntrypoint(entrypoint: string[]): this;
49
- withName(name: ContainerName): this;
48
+ withName(name: string): this;
50
49
  withLabels(labels: Labels): this;
51
- withEnv(key: EnvKey, value: EnvValue): this;
50
+ withEnvironment(environment: Environment): this;
52
51
  withTmpFs(tmpFs: TmpFs): this;
53
52
  withUlimits(ulimits: Ulimits): this;
54
53
  withAddedCapabilities(...capabilities: string[]): this;
55
54
  withDroppedCapabilities(...capabilities: string[]): this;
56
- withNetworkMode(networkMode: NetworkMode): this;
55
+ withNetwork(network: StartedNetwork): this;
56
+ withNetworkMode(networkMode: string): this;
57
57
  withNetworkAliases(...networkAliases: string[]): this;
58
- withExtraHosts(...extraHosts: ExtraHost[]): this;
58
+ withExtraHosts(extraHosts: ExtraHost[]): this;
59
59
  withExposedPorts(...ports: PortWithOptionalBinding[]): this;
60
- protected addExposedPorts(...ports: PortWithOptionalBinding[]): this;
61
- withBindMount(source: Dir, target: Dir, bindMode?: BindMode): this;
60
+ withBindMounts(bindMounts: BindMount[]): this;
62
61
  withHealthCheck(healthCheck: HealthCheck): this;
63
62
  withStartupTimeout(startupTimeout: number): this;
64
63
  withWaitStrategy(waitStrategy: WaitStrategy): this;
@@ -68,9 +67,7 @@ export declare class GenericContainer implements TestContainer {
68
67
  withReuse(): this;
69
68
  withPullPolicy(pullPolicy: PullPolicy): this;
70
69
  withIpcMode(ipcMode: string): this;
71
- withCopyFileToContainer(sourcePath: string, containerPath: string): this;
72
- withCopyContentToContainer(content: string | Buffer | Readable, containerPath: string): this;
70
+ withCopyFilesToContainer(filesToCopy: FileToCopy[]): this;
71
+ withCopyContentToContainer(contentsToCopy: ContentToCopy[]): this;
73
72
  protected getTarToCopy(): archiver.Archiver;
74
- private waitForContainer;
75
- private getWaitStrategy;
76
73
  }
@@ -16,7 +16,6 @@ exports.GenericContainer = void 0;
16
16
  const archiver_1 = __importDefault(require("archiver"));
17
17
  const bound_ports_1 = require("../bound-ports");
18
18
  const logger_1 = require("../logger");
19
- const port_check_1 = require("../port-check");
20
19
  const pull_policy_1 = require("../pull-policy");
21
20
  const reaper_1 = require("../reaper");
22
21
  const docker_image_name_1 = require("../docker-image-name");
@@ -30,21 +29,20 @@ const docker_client_1 = require("../docker/docker-client");
30
29
  const inspect_container_1 = require("../docker/functions/container/inspect-container");
31
30
  const start_container_1 = require("../docker/functions/container/start-container");
32
31
  const container_logs_1 = require("../docker/functions/container/container-logs");
33
- const stop_container_1 = require("../docker/functions/container/stop-container");
34
- const remove_container_1 = require("../docker/functions/container/remove-container");
35
32
  const put_container_archive_1 = require("../docker/functions/container/put-container-archive");
36
33
  const generic_container_builder_1 = require("./generic-container-builder");
37
34
  const started_generic_container_1 = require("./started-generic-container");
38
35
  const hash_1 = require("../hash");
39
36
  const get_container_1 = require("../docker/functions/container/get-container");
40
37
  const labels_1 = require("../labels");
38
+ const wait_for_container_1 = require("../wait-for-container");
41
39
  class GenericContainer {
42
40
  constructor(image) {
43
41
  this.image = image;
44
- this.env = {};
42
+ this.environment = {};
45
43
  this.networkAliases = [];
46
44
  this.ports = [];
47
- this.cmd = [];
45
+ this.command = [];
48
46
  this.bindMounts = [];
49
47
  this.labels = {};
50
48
  this.tmpFs = {};
@@ -78,8 +76,8 @@ class GenericContainer {
78
76
  }
79
77
  const createContainerOptions = {
80
78
  imageName: this.imageName,
81
- env: this.env,
82
- cmd: this.cmd,
79
+ environment: this.environment,
80
+ command: this.command,
83
81
  entrypoint: this.entrypoint,
84
82
  bindMounts: this.bindMounts,
85
83
  tmpFs: this.tmpFs,
@@ -119,14 +117,18 @@ class GenericContainer {
119
117
  });
120
118
  }
121
119
  reuseContainer(startedContainer) {
120
+ var _a;
122
121
  return __awaiter(this, void 0, void 0, function* () {
123
122
  const inspectResult = yield (0, inspect_container_1.inspectContainer)(startedContainer);
124
123
  const boundPorts = bound_ports_1.BoundPorts.fromInspectResult(inspectResult).filter(this.ports);
125
- yield this.waitForContainer(startedContainer, boundPorts);
126
- return new started_generic_container_1.StartedGenericContainer(startedContainer, (yield (0, docker_client_1.dockerClient)()).host, inspectResult, boundPorts, inspectResult.name, this.getWaitStrategy((yield (0, docker_client_1.dockerClient)()).host, startedContainer).withStartupTimeout(this.startupTimeout));
124
+ const host = (yield (0, docker_client_1.dockerClient)()).host;
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);
127
+ return new started_generic_container_1.StartedGenericContainer(startedContainer, host, inspectResult, boundPorts, inspectResult.name, waitStrategy);
127
128
  });
128
129
  }
129
130
  startContainer(createContainerOptions) {
131
+ var _a;
130
132
  return __awaiter(this, void 0, void 0, function* () {
131
133
  const container = yield (0, create_container_1.createContainer)(createContainerOptions);
132
134
  if (!this.imageName.isHelperContainer() && port_forwarder_1.PortForwarderInstance.isRunning()) {
@@ -159,8 +161,10 @@ class GenericContainer {
159
161
  .on("err", (data) => logger_1.containerLog.error(`${container.id}: ${data.trim()}`));
160
162
  const inspectResult = yield (0, inspect_container_1.inspectContainer)(container);
161
163
  const boundPorts = bound_ports_1.BoundPorts.fromInspectResult(inspectResult).filter(this.ports);
162
- yield this.waitForContainer(container, boundPorts);
163
- const startedContainer = new started_generic_container_1.StartedGenericContainer(container, (yield (0, docker_client_1.dockerClient)()).host, inspectResult, boundPorts, inspectResult.name, this.getWaitStrategy((yield (0, docker_client_1.dockerClient)()).host, container).withStartupTimeout(this.startupTimeout));
164
+ const host = (yield (0, docker_client_1.dockerClient)()).host;
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);
167
+ const startedContainer = new started_generic_container_1.StartedGenericContainer(container, host, inspectResult, boundPorts, inspectResult.name, waitStrategy);
164
168
  if (this.postStart) {
165
169
  yield this.postStart(startedContainer, inspectResult, boundPorts);
166
170
  }
@@ -170,8 +174,8 @@ class GenericContainer {
170
174
  get hasExposedPorts() {
171
175
  return this.ports.length !== 0;
172
176
  }
173
- withCmd(cmd) {
174
- this.cmd = cmd;
177
+ withCommand(command) {
178
+ this.command = command;
175
179
  return this;
176
180
  }
177
181
  withEntrypoint(entrypoint) {
@@ -183,27 +187,33 @@ class GenericContainer {
183
187
  return this;
184
188
  }
185
189
  withLabels(labels) {
186
- this.labels = Object.assign({}, labels);
190
+ this.labels = Object.assign(Object.assign({}, this.labels), labels);
187
191
  return this;
188
192
  }
189
- withEnv(key, value) {
190
- this.env[key] = value;
193
+ withEnvironment(environment) {
194
+ this.environment = Object.assign(Object.assign({}, this.environment), environment);
191
195
  return this;
192
196
  }
193
197
  withTmpFs(tmpFs) {
194
- this.tmpFs = tmpFs;
198
+ this.tmpFs = Object.assign(Object.assign({}, this.tmpFs), tmpFs);
195
199
  return this;
196
200
  }
197
201
  withUlimits(ulimits) {
198
- this.ulimits = ulimits;
202
+ this.ulimits = Object.assign(Object.assign({}, this.ulimits), ulimits);
199
203
  return this;
200
204
  }
201
205
  withAddedCapabilities(...capabilities) {
202
- this.addedCapabilities = capabilities;
206
+ var _a;
207
+ this.addedCapabilities = [...((_a = this.addedCapabilities) !== null && _a !== void 0 ? _a : []), ...capabilities];
203
208
  return this;
204
209
  }
205
210
  withDroppedCapabilities(...capabilities) {
206
- this.droppedCapabilities = capabilities;
211
+ var _a;
212
+ this.droppedCapabilities = [...((_a = this.droppedCapabilities) !== null && _a !== void 0 ? _a : []), ...capabilities];
213
+ return this;
214
+ }
215
+ withNetwork(network) {
216
+ this.networkMode = network.getName();
207
217
  return this;
208
218
  }
209
219
  withNetworkMode(networkMode) {
@@ -211,23 +221,19 @@ class GenericContainer {
211
221
  return this;
212
222
  }
213
223
  withNetworkAliases(...networkAliases) {
214
- this.networkAliases = networkAliases;
224
+ this.networkAliases = [...this.networkAliases, ...networkAliases];
215
225
  return this;
216
226
  }
217
- withExtraHosts(...extraHosts) {
218
- this.extraHosts.push(...extraHosts);
227
+ withExtraHosts(extraHosts) {
228
+ this.extraHosts = [...this.extraHosts, ...extraHosts];
219
229
  return this;
220
230
  }
221
231
  withExposedPorts(...ports) {
222
- this.ports = ports;
223
- return this;
224
- }
225
- addExposedPorts(...ports) {
226
- this.ports.push(...ports);
232
+ this.ports = [...this.ports, ...ports];
227
233
  return this;
228
234
  }
229
- withBindMount(source, target, bindMode = "rw") {
230
- this.bindMounts.push({ source, target, bindMode });
235
+ withBindMounts(bindMounts) {
236
+ this.bindMounts = bindMounts.map((bindMount) => (Object.assign({ mode: "rw" }, bindMount)));
231
237
  return this;
232
238
  }
233
239
  withHealthCheck(healthCheck) {
@@ -266,12 +272,14 @@ class GenericContainer {
266
272
  this.ipcMode = ipcMode;
267
273
  return this;
268
274
  }
269
- withCopyFileToContainer(sourcePath, containerPath) {
270
- this.getTarToCopy().file(sourcePath, { name: containerPath });
275
+ withCopyFilesToContainer(filesToCopy) {
276
+ const tar = this.getTarToCopy();
277
+ filesToCopy.forEach(({ source, target }) => tar.file(source, { name: target }));
271
278
  return this;
272
279
  }
273
- withCopyContentToContainer(content, containerPath) {
274
- this.getTarToCopy().append(content, { name: containerPath });
280
+ withCopyContentToContainer(contentsToCopy) {
281
+ const tar = this.getTarToCopy();
282
+ contentsToCopy.forEach(({ content, target }) => tar.append(content, { name: target }));
275
283
  return this;
276
284
  }
277
285
  getTarToCopy() {
@@ -280,34 +288,5 @@ class GenericContainer {
280
288
  }
281
289
  return this.tarToCopy;
282
290
  }
283
- waitForContainer(container, boundPorts) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- logger_1.log.debug(`Waiting for container to be ready: ${container.id}`);
286
- const waitStrategy = this.getWaitStrategy((yield (0, docker_client_1.dockerClient)()).host, container);
287
- try {
288
- yield waitStrategy.withStartupTimeout(this.startupTimeout).waitUntilReady(container, boundPorts);
289
- logger_1.log.info("Container is ready");
290
- }
291
- catch (err) {
292
- logger_1.log.error(`Container failed to be ready: ${err}`);
293
- try {
294
- yield (0, stop_container_1.stopContainer)(container, { timeout: 0 });
295
- yield (0, remove_container_1.removeContainer)(container, { removeVolumes: true });
296
- }
297
- catch (stopErr) {
298
- logger_1.log.error(`Failed to stop container after it failed to be ready: ${stopErr}`);
299
- }
300
- throw err;
301
- }
302
- });
303
- }
304
- getWaitStrategy(host, container) {
305
- if (this.waitStrategy) {
306
- return this.waitStrategy;
307
- }
308
- const hostPortCheck = new port_check_1.HostPortCheck(host);
309
- const internalPortCheck = new port_check_1.InternalPortCheck(container);
310
- return new wait_strategy_1.HostPortWaitStrategy(hostPortCheck, internalPortCheck);
311
- }
312
291
  }
313
292
  exports.GenericContainer = GenericContainer;
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
- import { RestartOptions, StartedTestContainer, StopOptions, ExecOptions, StoppedTestContainer } from "../test-container";
2
+ import { ExecOptions, RestartOptions, StartedTestContainer, StopOptions, StoppedTestContainer } from "../test-container";
3
3
  import Dockerode from "dockerode";
4
- import { Command, ContainerName, ExecResult, Host, Id as ContainerId, Labels } from "../docker/types";
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,18 @@ 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: Host, inspectResult: InspectResult, boundPorts: BoundPorts, name: ContainerName, waitStrategy: WaitStrategy);
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
- private waitForContainer;
22
- getHost(): Host;
23
- getMappedPort(port: Port): Port;
24
- getId(): ContainerId;
25
- getName(): ContainerName;
20
+ getHost(): string;
21
+ getMappedPort(port: number): number;
22
+ getId(): string;
23
+ getName(): string;
26
24
  getLabels(): Labels;
27
25
  getNetworkNames(): string[];
28
26
  getNetworkId(networkName: string): string;
29
27
  getIpAddress(networkName: string): string;
30
- exec(command: Command[], options?: Partial<ExecOptions>): Promise<ExecResult>;
28
+ exec(command: string[], options?: Partial<ExecOptions>): Promise<ExecResult>;
31
29
  logs(): Promise<Readable>;
32
30
  }
@@ -19,6 +19,7 @@ const container_logs_1 = require("../docker/functions/container/container-logs")
19
19
  const stopped_generic_container_1 = require("./stopped-generic-container");
20
20
  const stop_container_1 = require("../docker/functions/container/stop-container");
21
21
  const restart_container_1 = require("../docker/functions/container/restart-container");
22
+ const wait_for_container_1 = require("../wait-for-container");
22
23
  class StartedGenericContainer {
23
24
  constructor(container, host, inspectResult, boundPorts, name, waitStrategy) {
24
25
  this.container = container;
@@ -39,7 +40,7 @@ class StartedGenericContainer {
39
40
  yield (0, restart_container_1.restartContainer)(this.container, resolvedOptions);
40
41
  this.inspectResult = yield (0, inspect_container_1.inspectContainer)(this.container);
41
42
  this.boundPorts = bound_ports_1.BoundPorts.fromInspectResult(this.inspectResult).filter(Array.from(this.boundPorts.iterator()).map((port) => port[0]));
42
- yield this.waitForContainer(this.container, this.boundPorts);
43
+ yield (0, wait_for_container_1.waitForContainer)(this.container, this.waitStrategy, this.boundPorts);
43
44
  });
44
45
  }
45
46
  stopContainer(options = {}) {
@@ -51,26 +52,6 @@ class StartedGenericContainer {
51
52
  return new stopped_generic_container_1.StoppedGenericContainer();
52
53
  });
53
54
  }
54
- waitForContainer(container, boundPorts) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- logger_1.log.debug(`Waiting for container to be ready: ${container.id}`);
57
- try {
58
- yield this.waitStrategy.waitUntilReady(container, boundPorts);
59
- logger_1.log.info("Container is ready");
60
- }
61
- catch (err) {
62
- logger_1.log.error(`Container failed to be ready: ${err}`);
63
- try {
64
- yield (0, stop_container_1.stopContainer)(container, { timeout: 0 });
65
- yield (0, remove_container_1.removeContainer)(container, { removeVolumes: true });
66
- }
67
- catch (stopErr) {
68
- logger_1.log.error(`Failed to stop container after it failed to be ready: ${stopErr}`);
69
- }
70
- throw err;
71
- }
72
- });
73
- }
74
55
  getHost() {
75
56
  return this.host;
76
57
  }
@@ -1,21 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import { RestartOptions, StartedTestContainer, StopOptions, StoppedTestContainer } from "../test-container";
3
- import { Port } from "../port";
4
- import { ContainerName, Host, Id, Command, ExecResult, Labels } from "../docker/types";
3
+ import { ExecResult, Labels } from "../docker/types";
5
4
  import { Readable } from "stream";
6
5
  export declare class AbstractStartedContainer {
7
6
  protected readonly startedTestContainer: StartedTestContainer;
8
7
  constructor(startedTestContainer: StartedTestContainer);
9
8
  stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
10
9
  restart(options?: Partial<RestartOptions>): Promise<void>;
11
- getHost(): Host;
12
- getMappedPort(port: Port): Port;
13
- getName(): ContainerName;
10
+ getHost(): string;
11
+ getMappedPort(port: number): number;
12
+ getName(): string;
14
13
  getLabels(): Labels;
15
- getId(): Id;
14
+ getId(): string;
16
15
  getNetworkNames(): string[];
17
16
  getNetworkId(networkName: string): string;
18
17
  getIpAddress(networkName: string): string;
19
- exec(command: Command[]): Promise<ExecResult>;
18
+ exec(command: string[]): Promise<ExecResult>;
20
19
  logs(): Promise<Readable>;
21
20
  }
@@ -16,7 +16,7 @@ const abstract_started_container_1 = require("../abstract-started-container");
16
16
  const ARANGODB_PORT = 8529;
17
17
  const USERNAME = "root";
18
18
  class ArangoDBContainer extends __1.GenericContainer {
19
- constructor(image = "arangodb:3.7.13", password = new uuid_1.RandomUuid().nextUuid()) {
19
+ constructor(image = "arangodb:3.10.0", password = new uuid_1.RandomUuid().nextUuid()) {
20
20
  super(image);
21
21
  this.password = password;
22
22
  }
@@ -31,7 +31,7 @@ class ArangoDBContainer extends __1.GenericContainer {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [ARANGODB_PORT]))
33
33
  .withWaitStrategy(__1.Wait.forLogMessage("Have fun!"))
34
- .withEnv("ARANGO_ROOT_PASSWORD", this.password)
34
+ .withEnvironment({ ARANGO_ROOT_PASSWORD: this.password })
35
35
  .withStartupTimeout(120000);
36
36
  return new StartedArangoContainer(yield _super.start.call(this), this.password);
37
37
  });
@@ -14,7 +14,7 @@ const __1 = require("../..");
14
14
  const abstract_started_container_1 = require("../abstract-started-container");
15
15
  const ELASTIC_SEARCH_HTTP_PORT = 9200;
16
16
  class ElasticsearchContainer extends __1.GenericContainer {
17
- constructor(image = "docker.elastic.co/elasticsearch/elasticsearch:7.9.2") {
17
+ constructor(image = "elasticsearch:7.17.7") {
18
18
  super(image);
19
19
  }
20
20
  start() {
@@ -23,7 +23,7 @@ class ElasticsearchContainer extends __1.GenericContainer {
23
23
  });
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [ELASTIC_SEARCH_HTTP_PORT]))
26
- .withEnv("discovery.type", "single-node")
26
+ .withEnvironment({ "discovery.type": "single-node" })
27
27
  .withStartupTimeout(120000);
28
28
  return new StartedElasticsearchContainer(yield _super.start.call(this));
29
29
  });
@@ -1,11 +1,10 @@
1
1
  import { GenericContainer } from "../../generic-container/generic-container";
2
2
  import { BoundPorts } from "../../bound-ports";
3
- import { Port } from "../../port";
4
3
  import { StartedTestContainer } from "../..";
5
4
  import { AbstractStartedContainer } from "../abstract-started-container";
6
- import { Host } from "../../docker/types";
7
5
  import { InspectResult } from "../../docker/functions/container/inspect-container";
8
- export declare const KAFKA_IMAGE = "confluentinc/cp-kafka:5.5.4";
6
+ import { Content } from "../../docker/types";
7
+ export declare const KAFKA_IMAGE = "confluentinc/cp-kafka:7.2.2";
9
8
  interface SaslSslListenerOptions {
10
9
  sasl: SaslOptions;
11
10
  port: number;
@@ -21,7 +20,7 @@ interface User {
21
20
  password: string;
22
21
  }
23
22
  interface PKCS12CertificateStore {
24
- content: Parameters<GenericContainer["withCopyContentToContainer"]>[0];
23
+ content: Content;
25
24
  passphrase: string;
26
25
  }
27
26
  export declare class KafkaContainer extends GenericContainer {
@@ -31,7 +30,7 @@ export declare class KafkaContainer extends GenericContainer {
31
30
  private zooKeeperPort?;
32
31
  private saslSslConfig?;
33
32
  constructor(image?: string);
34
- withZooKeeper(host: Host, port: Port): this;
33
+ withZooKeeper(host: string, port: number): this;
35
34
  withSaslSslListener(options: SaslSslListenerOptions): this;
36
35
  protected preStart(): Promise<void>;
37
36
  start(): Promise<StartedKafkaContainer>;