testcontainers 8.6.1-beta.0 → 8.7.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 CHANGED
@@ -243,6 +243,19 @@ const container = await new GenericContainer("alpine")
243
243
  .start();
244
244
  ```
245
245
 
246
+ Creating a container with labels:
247
+
248
+ ```javascript
249
+ const { GenericContainer } = require("testcontainers");
250
+
251
+ const container = await new GenericContainer("alpine")
252
+ .withLabels({
253
+ label1: "value1",
254
+ label2: "value2",
255
+ })
256
+ .start();
257
+ ```
258
+
246
259
  Creating a container with a custom health check command. Note that `interval`, `timeout`, `retries` and `startPeriod` are optional; the values will be inherited from the image or parent image if omitted. Also note that the wait strategy should be set to `Wait.forHealthCheck()` for this option to take effect:
247
260
 
248
261
  ```javascript
@@ -148,6 +148,6 @@ const findGateway = (dockerode) => __awaiter(void 0, void 0, void 0, function* (
148
148
  const inspectResult = yield dockerode.getNetwork("bridge").inspect();
149
149
  return (_c = (_b = (_a = inspectResult === null || inspectResult === void 0 ? void 0 : inspectResult.IPAM) === null || _a === void 0 ? void 0 : _a.Config) === null || _b === void 0 ? void 0 : _b.find((config) => config.Gateway !== undefined)) === null || _c === void 0 ? void 0 : _c.Gateway;
150
150
  });
151
- const findDefaultGateway = (dockerode) => __awaiter(void 0, void 0, void 0, function* () { return run_in_container_1.runInContainer(dockerode, "alpine:3.5", ["sh", "-c", "ip route|awk '/default/ { print $3 }'"]); });
151
+ const findDefaultGateway = (dockerode) => __awaiter(void 0, void 0, void 0, function* () { return run_in_container_1.runInContainer(dockerode, "alpine:3.14", ["sh", "-c", "ip route|awk '/default/ { print $3 }'"]); });
152
152
  const isInContainer = () => fs_1.existsSync("/.dockerenv");
153
153
  exports.dockerClient = getDockerClient();
@@ -1,8 +1,7 @@
1
1
  import { DockerImageName } from "../../../docker-image-name";
2
2
  import Dockerode from "dockerode";
3
3
  import { PortWithOptionalBinding } from "../../../port";
4
- import { Labels } from "../create-labels";
5
- import { BindMount, Command, ContainerName, Env, ExtraHost, HealthCheck, NetworkMode, TmpFs } from "../../types";
4
+ import { BindMount, Command, ContainerName, Env, ExtraHost, HealthCheck, Labels, NetworkMode, TmpFs } from "../../types";
6
5
  export declare type CreateContainerOptions = {
7
6
  imageName: DockerImageName;
8
7
  env: Env;
@@ -1,4 +1,4 @@
1
- import { ContainerName, HealthCheckStatus, NetworkSettings, Ports } from "../../types";
1
+ import { ContainerName, HealthCheckStatus, Labels, NetworkSettings, Ports } from "../../types";
2
2
  import Dockerode from "dockerode";
3
3
  export declare type InspectResult = {
4
4
  name: ContainerName;
@@ -12,5 +12,6 @@ export declare type InspectResult = {
12
12
  status: string;
13
13
  running: boolean;
14
14
  };
15
+ labels: Labels;
15
16
  };
16
17
  export declare const inspectContainer: (container: Dockerode.Container) => Promise<InspectResult>;
@@ -21,6 +21,7 @@ const inspectContainer = (container) => __awaiter(void 0, void 0, void 0, functi
21
21
  healthCheckStatus: getHealthCheckStatus(inspectResult),
22
22
  networkSettings: getNetworkSettings(inspectResult),
23
23
  state: { status: inspectResult.State.Status, running: inspectResult.State.Running },
24
+ labels: inspectResult.Config.Labels,
24
25
  };
25
26
  }
26
27
  catch (err) {
@@ -1,5 +1,3 @@
1
1
  import { DockerImageName } from "../../docker-image-name";
2
- export declare type Labels = {
3
- [key: string]: string;
4
- };
2
+ import { Labels } from "../types";
5
3
  export declare const createLabels: (reusable: boolean, dockerImageName?: DockerImageName | undefined, extraLabels?: Labels) => Labels;
@@ -28,6 +28,9 @@ export declare type ExtraHost = {
28
28
  };
29
29
  export declare type NetworkMode = string;
30
30
  export declare type ContainerName = string;
31
+ export declare type Labels = {
32
+ [key: string]: string;
33
+ };
31
34
  export declare type Ports = {
32
35
  [internalPort: number]: number;
33
36
  };
@@ -6,7 +6,7 @@ import { PullPolicy } from "../pull-policy";
6
6
  import { StartedTestContainer, TestContainer } from "../test-container";
7
7
  import { WaitStrategy } from "../wait-strategy";
8
8
  import { Readable } from "stream";
9
- import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, ExtraHost, HealthCheck, NetworkMode, TmpFs } from "../docker/types";
9
+ import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, ExtraHost, HealthCheck, NetworkMode, TmpFs, Labels } from "../docker/types";
10
10
  import { InspectResult } from "../docker/functions/container/inspect-container";
11
11
  import { GenericContainerBuilder } from "./generic-container-builder";
12
12
  export declare class GenericContainer implements TestContainer {
@@ -20,6 +20,7 @@ export declare class GenericContainer implements TestContainer {
20
20
  protected cmd: Command[];
21
21
  protected bindMounts: BindMount[];
22
22
  protected name?: ContainerName;
23
+ protected labels: Labels;
23
24
  protected tmpFs: TmpFs;
24
25
  protected healthCheck?: HealthCheck;
25
26
  protected waitStrategy?: WaitStrategy;
@@ -40,6 +41,7 @@ export declare class GenericContainer implements TestContainer {
40
41
  protected postStart?(container: StartedTestContainer, inspectResult: InspectResult, boundPorts: BoundPorts): Promise<void>;
41
42
  withCmd(cmd: Command[]): this;
42
43
  withName(name: ContainerName): this;
44
+ withLabels(labels: Labels): this;
43
45
  withEnv(key: EnvKey, value: EnvValue): this;
44
46
  withTmpFs(tmpFs: TmpFs): this;
45
47
  withNetworkMode(networkMode: NetworkMode): this;
@@ -46,6 +46,7 @@ class GenericContainer {
46
46
  this.ports = [];
47
47
  this.cmd = [];
48
48
  this.bindMounts = [];
49
+ this.labels = {};
49
50
  this.tmpFs = {};
50
51
  this.startupTimeout = 60000;
51
52
  this.useDefaultLogDriver = false;
@@ -83,6 +84,7 @@ class GenericContainer {
83
84
  tmpFs: this.tmpFs,
84
85
  exposedPorts: this.ports,
85
86
  name: this.name,
87
+ labels: this.labels,
86
88
  reusable: this.reuse,
87
89
  networkMode: this.networkAliases.length > 0 ? undefined : this.networkMode,
88
90
  healthCheck: this.healthCheck,
@@ -169,6 +171,10 @@ class GenericContainer {
169
171
  this.name = name;
170
172
  return this;
171
173
  }
174
+ withLabels(labels) {
175
+ this.labels = Object.assign({}, labels);
176
+ return this;
177
+ }
172
178
  withEnv(key, value) {
173
179
  this.env[key] = value;
174
180
  return this;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { StartedTestContainer, StopOptions, StoppedTestContainer } from "../test-container";
3
3
  import Dockerode from "dockerode";
4
- import { Command, ContainerName, ExecResult, Host, Id as ContainerId } from "../docker/types";
4
+ import { Command, ContainerName, ExecResult, Host, Id as ContainerId, Labels } from "../docker/types";
5
5
  import { InspectResult } from "../docker/functions/container/inspect-container";
6
6
  import { BoundPorts } from "../bound-ports";
7
7
  import { Port } from "../port";
@@ -19,6 +19,7 @@ export declare class StartedGenericContainer implements StartedTestContainer {
19
19
  getMappedPort(port: Port): Port;
20
20
  getId(): ContainerId;
21
21
  getName(): ContainerName;
22
+ getLabels(): Labels;
22
23
  getNetworkNames(): string[];
23
24
  getNetworkId(networkName: string): string;
24
25
  getIpAddress(networkName: string): string;
@@ -50,6 +50,9 @@ class StartedGenericContainer {
50
50
  getName() {
51
51
  return this.name;
52
52
  }
53
+ getLabels() {
54
+ return this.inspectResult.labels;
55
+ }
53
56
  getNetworkNames() {
54
57
  return Object.keys(this.inspectResult.networkSettings);
55
58
  }
@@ -1,7 +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, Command, ExecResult } from "../docker/types";
4
+ import { ContainerName, Host, Id, Command, ExecResult, Labels } from "../docker/types";
5
5
  import { Readable } from "stream";
6
6
  export declare class AbstractStartedContainer {
7
7
  protected readonly startedTestContainer: StartedTestContainer;
@@ -10,6 +10,7 @@ export declare class AbstractStartedContainer {
10
10
  getHost(): Host;
11
11
  getMappedPort(port: Port): Port;
12
12
  getName(): ContainerName;
13
+ getLabels(): Labels;
13
14
  getId(): Id;
14
15
  getNetworkNames(): string[];
15
16
  getNetworkId(networkName: string): string;
@@ -17,6 +17,9 @@ class AbstractStartedContainer {
17
17
  getName() {
18
18
  return this.startedTestContainer.getName();
19
19
  }
20
+ getLabels() {
21
+ return this.startedTestContainer.getLabels();
22
+ }
20
23
  getId() {
21
24
  return this.startedTestContainer.getId();
22
25
  }
package/dist/reaper.js CHANGED
@@ -14,10 +14,10 @@ const net_1 = require("net");
14
14
  const logger_1 = require("./logger");
15
15
  const generic_container_1 = require("./generic-container/generic-container");
16
16
  const session_id_1 = require("./docker/session-id");
17
- const docker_client_1 = require("./docker/docker-client");
18
17
  const images_1 = require("./images");
19
18
  const port_1 = require("./port");
20
19
  const labels_1 = require("./labels");
20
+ const wait_1 = require("./wait");
21
21
  class RealReaper {
22
22
  constructor(container, socket) {
23
23
  this.container = container;
@@ -85,13 +85,14 @@ class ReaperInstance {
85
85
  const container = new generic_container_1.GenericContainer(images_1.REAPER_IMAGE)
86
86
  .withName(`testcontainers-ryuk-${session_id_1.sessionId}`)
87
87
  .withExposedPorts(8080)
88
- .withBindMount(dockerSocket, "/var/run/docker.sock");
88
+ .withBindMount(dockerSocket, "/var/run/docker.sock")
89
+ .withWaitStrategy(wait_1.Wait.forLogMessage(/.+ Started!/));
89
90
  if (this.isPrivileged()) {
90
91
  container.withPrivilegedMode();
91
92
  }
92
93
  const startedContainer = yield container.start();
93
94
  const containerId = startedContainer.getId();
94
- const host = (yield docker_client_1.dockerClient).host;
95
+ const host = startedContainer.getHost();
95
96
  const port = startedContainer.getMappedPort(8080);
96
97
  logger_1.log.debug(`Connecting to Reaper ${containerId} on ${host}:${port}`);
97
98
  const socket = new net_1.Socket();
@@ -3,7 +3,7 @@ import { Port, PortWithOptionalBinding } from "./port";
3
3
  import { PullPolicy } from "./pull-policy";
4
4
  import { WaitStrategy } from "./wait-strategy";
5
5
  import { Readable } from "stream";
6
- import { BindMode, Command, ContainerName, Dir, EnvKey, EnvValue, ExecResult, ExtraHost, Host, Id, NetworkMode, TmpFs } from "./docker/types";
6
+ import { BindMode, Command, ContainerName, Dir, EnvKey, EnvValue, ExecResult, ExtraHost, Host, Id, NetworkMode, TmpFs, Labels } from "./docker/types";
7
7
  export interface TestContainer {
8
8
  start(): Promise<StartedTestContainer>;
9
9
  withEnv(key: EnvKey, value: EnvValue): this;
@@ -32,6 +32,7 @@ export interface StartedTestContainer {
32
32
  getHost(): Host;
33
33
  getMappedPort(port: Port): Port;
34
34
  getName(): ContainerName;
35
+ getLabels(): Labels;
35
36
  getId(): Id;
36
37
  getNetworkNames(): string[];
37
38
  getNetworkId(networkName: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "8.6.1-beta.0",
4
+ "version": "8.7.0",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "keywords": [