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.
Files changed (60) hide show
  1. package/README.md +160 -43
  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 +9 -5
  6. package/dist/docker/functions/container/create-container.js +19 -6
  7. package/dist/docker/functions/container/exec-container.d.ts +2 -2
  8. package/dist/docker/functions/container/exec-container.js +10 -3
  9. package/dist/docker/functions/container/get-container.d.ts +1 -2
  10. package/dist/docker/functions/container/inspect-container.d.ts +2 -2
  11. package/dist/docker/functions/create-labels.d.ts +1 -1
  12. package/dist/docker/functions/image/build-image.d.ts +3 -2
  13. package/dist/docker/functions/image/build-image.js +14 -9
  14. package/dist/docker/functions/run-in-container.d.ts +1 -2
  15. package/dist/docker/types.d.ts +29 -22
  16. package/dist/docker-compose/default-docker-compose-options.d.ts +1 -1
  17. package/dist/docker-compose/default-docker-compose-options.js +2 -2
  18. package/dist/docker-compose/docker-compose-options.d.ts +2 -2
  19. package/dist/docker-compose/functions/docker-compose-down.d.ts +2 -1
  20. package/dist/docker-compose/functions/docker-compose-down.js +12 -2
  21. package/dist/docker-compose/functions/docker-compose-up.d.ts +1 -1
  22. package/dist/docker-compose/functions/docker-compose-up.js +1 -1
  23. package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -5
  24. package/dist/docker-compose-environment/docker-compose-environment.js +12 -12
  25. package/dist/docker-compose-environment/started-docker-compose-environment.d.ts +2 -1
  26. package/dist/docker-compose-environment/started-docker-compose-environment.js +3 -2
  27. package/dist/docker-compose-environment/stopped-docker-compose-environment.d.ts +2 -1
  28. package/dist/docker-compose-environment/stopped-docker-compose-environment.js +3 -2
  29. package/dist/generic-container/generic-container-builder.d.ts +5 -3
  30. package/dist/generic-container/generic-container-builder.js +8 -2
  31. package/dist/generic-container/generic-container.d.ts +24 -17
  32. package/dist/generic-container/generic-container.js +48 -24
  33. package/dist/generic-container/started-generic-container.d.ts +7 -8
  34. package/dist/generic-container/started-generic-container.js +1 -2
  35. package/dist/logger.d.ts +1 -0
  36. package/dist/logger.js +2 -1
  37. package/dist/modules/abstract-started-container.d.ts +6 -7
  38. package/dist/modules/arangodb/arangodb-container.js +2 -2
  39. package/dist/modules/elasticsearch/elasticsearch-container.js +2 -2
  40. package/dist/modules/kafka/kafka-container.d.ts +4 -5
  41. package/dist/modules/kafka/kafka-container.js +41 -34
  42. package/dist/modules/mongodb/mongodb-container.js +1 -1
  43. package/dist/modules/mysql/mysql-container.d.ts +1 -2
  44. package/dist/modules/mysql/mysql-container.js +7 -5
  45. package/dist/modules/nats/nats-container.d.ts +1 -1
  46. package/dist/modules/nats/nats-container.js +2 -2
  47. package/dist/modules/neo4j/neo4j-container.js +10 -4
  48. package/dist/modules/postgresql/postgresql-container.d.ts +1 -2
  49. package/dist/modules/postgresql/postgresql-container.js +5 -3
  50. package/dist/port-binder.d.ts +1 -2
  51. package/dist/port-check.d.ts +4 -6
  52. package/dist/port-check.js +1 -1
  53. package/dist/port-forwarder.d.ts +1 -2
  54. package/dist/port-forwarder.js +2 -2
  55. package/dist/port-generator.d.ts +4 -5
  56. package/dist/port.d.ts +3 -5
  57. package/dist/reaper.js +1 -1
  58. package/dist/test-container.d.ts +24 -14
  59. package/dist/test-containers.d.ts +1 -2
  60. package/package.json +29 -25
package/dist/logger.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.containerLog = exports.log = exports.FakeLogger = void 0;
6
+ exports.execLog = exports.containerLog = exports.log = exports.FakeLogger = void 0;
7
7
  const debug_1 = __importDefault(require("debug"));
8
8
  class DebugLogger {
9
9
  constructor(namespace) {
@@ -52,3 +52,4 @@ class FakeLogger {
52
52
  exports.FakeLogger = FakeLogger;
53
53
  exports.log = new DebugLogger("testcontainers");
54
54
  exports.containerLog = new DebugLogger("testcontainers:containers");
55
+ exports.execLog = new DebugLogger("testcontainers:exec");
@@ -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>;
@@ -16,23 +16,23 @@ const abstract_started_container_1 = require("../abstract-started-container");
16
16
  const KAFKA_PORT = 9093;
17
17
  const KAFKA_BROKER_PORT = 9092;
18
18
  const DEFAULT_ZOOKEEPER_PORT = 2181;
19
- exports.KAFKA_IMAGE = "confluentinc/cp-kafka:5.5.4";
19
+ exports.KAFKA_IMAGE = "confluentinc/cp-kafka:7.2.2";
20
20
  class KafkaContainer extends generic_container_1.GenericContainer {
21
21
  constructor(image = exports.KAFKA_IMAGE) {
22
22
  super(image);
23
23
  this.uuid = new uuid_1.RandomUuid();
24
24
  this.isZooKeeperProvided = false;
25
- this.withExposedPorts(KAFKA_PORT)
26
- .withStartupTimeout(180000)
27
- .withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT")
28
- .withEnv("KAFKA_INTER_BROKER_LISTENER_NAME", "BROKER")
29
- .withEnv("KAFKA_BROKER_ID", "1")
30
- .withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1")
31
- .withEnv("KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS", "1")
32
- .withEnv("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", "1")
33
- .withEnv("KAFKA_LOG_FLUSH_INTERVAL_MESSAGES", "9223372036854775807")
34
- .withEnv("KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS", "0")
35
- .withEnv("KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE", "false");
25
+ this.withExposedPorts(KAFKA_PORT).withStartupTimeout(180000).withEnvironment({
26
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT",
27
+ KAFKA_INTER_BROKER_LISTENER_NAME: "BROKER",
28
+ KAFKA_BROKER_ID: "1",
29
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1",
30
+ KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: "1",
31
+ KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1",
32
+ KAFKA_LOG_FLUSH_INTERVAL_MESSAGES: "9223372036854775807",
33
+ KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: "0",
34
+ KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE: "false",
35
+ });
36
36
  }
37
37
  withZooKeeper(host, port) {
38
38
  this.isZooKeeperProvided = true;
@@ -47,7 +47,7 @@ class KafkaContainer extends generic_container_1.GenericContainer {
47
47
  preStart() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  const network = this.networkMode && this.networkAliases.length > 0 ? this.networkAliases[0] : "localhost";
50
- this.withEnv("KAFKA_ADVERTISED_LISTENERS", `BROKER://${network}:${KAFKA_BROKER_PORT}`);
50
+ this.withEnvironment({ KAFKA_ADVERTISED_LISTENERS: `BROKER://${network}:${KAFKA_BROKER_PORT}` });
51
51
  if (this.saslSslConfig) {
52
52
  this.addPlaintextAndSecureListener(this.saslSslConfig);
53
53
  }
@@ -56,13 +56,13 @@ class KafkaContainer extends generic_container_1.GenericContainer {
56
56
  }
57
57
  let command = "#!/bin/bash\n";
58
58
  if (this.isZooKeeperProvided) {
59
- this.withEnv("KAFKA_ZOOKEEPER_CONNECT", `${this.zooKeeperHost}:${this.zooKeeperPort}`);
59
+ this.withEnvironment({ KAFKA_ZOOKEEPER_CONNECT: `${this.zooKeeperHost}:${this.zooKeeperPort}` });
60
60
  }
61
61
  else {
62
62
  this.zooKeeperHost = this.uuid.nextUuid();
63
63
  this.zooKeeperPort = DEFAULT_ZOOKEEPER_PORT;
64
- this.addExposedPorts(this.zooKeeperPort);
65
- this.withEnv("KAFKA_ZOOKEEPER_CONNECT", `localhost:${this.zooKeeperPort}`);
64
+ this.withExposedPorts(this.zooKeeperPort);
65
+ this.withEnvironment({ KAFKA_ZOOKEEPER_CONNECT: `localhost:${this.zooKeeperPort}` });
66
66
  command += "echo 'clientPort=" + this.zooKeeperPort + "' > zookeeper.properties\n";
67
67
  command += "echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties\n";
68
68
  command += "echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties\n";
@@ -70,7 +70,7 @@ class KafkaContainer extends generic_container_1.GenericContainer {
70
70
  }
71
71
  command += "echo '' > /etc/confluent/docker/ensure \n";
72
72
  command += "/etc/confluent/docker/run \n";
73
- this.withCmd(["sh", "-c", command]);
73
+ this.withCommand(["sh", "-c", command]);
74
74
  });
75
75
  }
76
76
  start() {
@@ -90,25 +90,32 @@ class KafkaContainer extends generic_container_1.GenericContainer {
90
90
  });
91
91
  }
92
92
  addPlaintextAndSecureListener({ port, sasl, keystore, truststore }) {
93
- this.withEnv("KAFKA_LISTENERS", `SECURE://0.0.0.0:${port},PLAINTEXT://0.0.0.0:${KAFKA_PORT},BROKER://0.0.0.0:${KAFKA_BROKER_PORT}`)
94
- .withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SECURE:SASL_SSL")
95
- .withEnv("KAFKA_SSL_PROTOCOL", "TLSv1.2")
96
- .withCopyContentToContainer(keystore.content, "/etc/kafka/secrets/server.keystore.pfx")
97
- .withEnv("KAFKA_SSL_KEYSTORE_LOCATION", "/etc/kafka/secrets/server.keystore.pfx")
98
- .withEnv("KAFKA_SSL_KEYSTORE_PASSWORD", keystore.passphrase)
99
- .withEnv("KAFKA_SSL_KEYSTORE_TYPE", "PKCS12")
100
- .withEnv("KAFKA_SASL_ENABLED_MECHANISMS", sasl.mechanism)
101
- .withEnv(`KAFKA_LISTENER_NAME_SECURE_${sasl.mechanism}_SASL_JAAS_CONFIG`, "org.apache.kafka.common.security.scram.ScramLoginModule required;")
102
- .addExposedPorts(KAFKA_PORT, port);
93
+ this.withEnvironment({
94
+ KAFKA_LISTENERS: `SECURE://0.0.0.0:${port},PLAINTEXT://0.0.0.0:${KAFKA_PORT},BROKER://0.0.0.0:${KAFKA_BROKER_PORT}`,
95
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SECURE:SASL_SSL",
96
+ KAFKA_SSL_PROTOCOL: "TLSv1.2",
97
+ KAFKA_SSL_KEYSTORE_LOCATION: "/etc/kafka/secrets/server.keystore.pfx",
98
+ KAFKA_SSL_KEYSTORE_PASSWORD: keystore.passphrase,
99
+ KAFKA_SSL_KEYSTORE_TYPE: "PKCS12",
100
+ KAFKA_SASL_ENABLED_MECHANISMS: sasl.mechanism,
101
+ [`KAFKA_LISTENER_NAME_SECURE_${sasl.mechanism}_SASL_JAAS_CONFIG`]: "org.apache.kafka.common.security.scram.ScramLoginModule required;",
102
+ })
103
+ .withCopyContentToContainer([{ content: keystore.content, target: "/etc/kafka/secrets/server.keystore.pfx" }])
104
+ .withExposedPorts(KAFKA_PORT, port);
103
105
  if (truststore) {
104
- this.withCopyContentToContainer(truststore.content, "/etc/kafka/secrets/server.truststore.pfx")
105
- .withEnv("KAFKA_SSL_TRUSTSTORE_LOCATION", "/etc/kafka/secrets/server.truststore.pfx")
106
- .withEnv("KAFKA_SSL_TRUSTSTORE_PASSWORD", truststore.passphrase)
107
- .withEnv("KAFKA_SSL_TRUSTSTORE_TYPE", "PKCS12");
106
+ this.withCopyContentToContainer([
107
+ { content: truststore.content, target: "/etc/kafka/secrets/server.truststore.pfx" },
108
+ ]).withEnvironment({
109
+ KAFKA_SSL_TRUSTSTORE_LOCATION: "/etc/kafka/secrets/server.truststore.pfx",
110
+ KAFKA_SSL_TRUSTSTORE_PASSWORD: truststore.passphrase,
111
+ KAFKA_SSL_TRUSTSTORE_TYPE: "PKCS12",
112
+ });
108
113
  }
109
114
  }
110
115
  addPlaintextListener() {
111
- this.withEnv("KAFKA_LISTENERS", `PLAINTEXT://0.0.0.0:${KAFKA_PORT},BROKER://0.0.0.0:${KAFKA_BROKER_PORT}`).addExposedPorts(KAFKA_PORT);
116
+ this.withEnvironment({
117
+ KAFKA_LISTENERS: `PLAINTEXT://0.0.0.0:${KAFKA_PORT},BROKER://0.0.0.0:${KAFKA_BROKER_PORT}`,
118
+ }).withExposedPorts(KAFKA_PORT);
112
119
  }
113
120
  updateAdvertisedListeners(container, inspectResult, boundPorts) {
114
121
  return __awaiter(this, void 0, void 0, function* () {
@@ -125,7 +132,7 @@ class KafkaContainer extends generic_container_1.GenericContainer {
125
132
  "--entity-type",
126
133
  "brokers",
127
134
  "--entity-name",
128
- this.env["KAFKA_BROKER_ID"],
135
+ this.environment["KAFKA_BROKER_ID"],
129
136
  "--add-config",
130
137
  `advertised.listeners=[${bootstrapServers},${brokerAdvertisedListener}]`,
131
138
  ]);
@@ -142,7 +149,7 @@ class KafkaContainer extends generic_container_1.GenericContainer {
142
149
  // At the time of writing kafka-configs displays a warning stating that the 'zookeeper' flag is deprecated in favor of 'bootstrap-server'.
143
150
  // Unfortunately, 'bootstrap-server' can only be used to set quotas and not to create a user.
144
151
  "--zookeeper",
145
- this.env["KAFKA_ZOOKEEPER_CONNECT"],
152
+ this.environment["KAFKA_ZOOKEEPER_CONNECT"],
146
153
  "--entity-type",
147
154
  "users",
148
155
  "--entity-name",
@@ -26,7 +26,7 @@ class MongoDBContainer extends generic_container_1.GenericContainer {
26
26
  });
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
28
  this.withExposedPorts(MONGODB_PORT)
29
- .withCmd(["--replSet", "rs0"])
29
+ .withCommand(["--replSet", "rs0"])
30
30
  .withWaitStrategy(wait_1.Wait.forLogMessage(new RegExp(".*waiting for connections.*", "i")))
31
31
  .withStartupTimeout(120000);
32
32
  return new StartedMongoDBContainer(yield _super.start.call(this));
@@ -1,7 +1,6 @@
1
1
  import { GenericContainer } from "../../generic-container/generic-container";
2
2
  import { StartedTestContainer } from "../../test-container";
3
3
  import { AbstractStartedContainer } from "../abstract-started-container";
4
- import { Port } from "../../port";
5
4
  export declare class MySqlContainer extends GenericContainer {
6
5
  private database;
7
6
  private username;
@@ -21,7 +20,7 @@ export declare class StartedMySqlContainer extends AbstractStartedContainer {
21
20
  private readonly rootPassword;
22
21
  private readonly port;
23
22
  constructor(startedTestContainer: StartedTestContainer, database: string, username: string, userPassword: string, rootPassword: string);
24
- getPort(): Port;
23
+ getPort(): number;
25
24
  getDatabase(): string;
26
25
  getUsername(): string;
27
26
  getUserPassword(): string;
@@ -15,7 +15,7 @@ const uuid_1 = require("../../uuid");
15
15
  const abstract_started_container_1 = require("../abstract-started-container");
16
16
  const MYSQL_PORT = 3306;
17
17
  class MySqlContainer extends generic_container_1.GenericContainer {
18
- constructor(image = "mysql:8.0.26") {
18
+ constructor(image = "mysql:8.0.31") {
19
19
  super(image);
20
20
  this.database = "test";
21
21
  this.username = new uuid_1.RandomUuid().nextUuid();
@@ -44,10 +44,12 @@ class MySqlContainer extends generic_container_1.GenericContainer {
44
44
  });
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [MYSQL_PORT]))
47
- .withEnv("MYSQL_DATABASE", this.database)
48
- .withEnv("MYSQL_ROOT_PASSWORD", this.rootPassword)
49
- .withEnv("MYSQL_USER", this.username)
50
- .withEnv("MYSQL_PASSWORD", this.userPassword)
47
+ .withEnvironment({
48
+ MYSQL_DATABASE: this.database,
49
+ MYSQL_ROOT_PASSWORD: this.rootPassword,
50
+ MYSQL_USER: this.username,
51
+ MYSQL_PASSWORD: this.userPassword,
52
+ })
51
53
  .withStartupTimeout(120000);
52
54
  return new StartedMySqlContainer(yield _super.start.call(this), this.database, this.username, this.userPassword, this.rootPassword);
53
55
  });
@@ -4,7 +4,7 @@ import { AbstractStartedContainer } from "../abstract-started-container";
4
4
  export declare class NatsContainer extends GenericContainer {
5
5
  private args;
6
6
  constructor(image?: string);
7
- withUser(user: string): this;
7
+ withUsername(user: string): this;
8
8
  withPass(pass: string): this;
9
9
  withArg(name: string, value: string): this;
10
10
  private static ensureDashInFrontOfArgumentName;
@@ -26,7 +26,7 @@ class NatsContainer extends generic_container_1.GenericContainer {
26
26
  this.args[USER_ARGUMENT_KEY] = new uuid_1.RandomUuid().nextUuid();
27
27
  this.args[PASS_ARGUMENT_KEY] = new uuid_1.RandomUuid().nextUuid();
28
28
  }
29
- withUser(user) {
29
+ withUsername(user) {
30
30
  this.args[USER_ARGUMENT_KEY] = user;
31
31
  return this;
32
32
  }
@@ -64,7 +64,7 @@ class NatsContainer extends generic_container_1.GenericContainer {
64
64
  }
65
65
  return result;
66
66
  }
67
- this.withCmd(buildCmdsFromArgs(this.args))
67
+ this.withCommand(buildCmdsFromArgs(this.args))
68
68
  .withExposedPorts(...(this.hasExposedPorts ? this.ports : [CLIENT_PORT, ROUTING_PORT_FOR_CLUSTERING, HTTP_MANAGEMENT_PORT]))
69
69
  .withWaitStrategy(wait_1.Wait.forLogMessage(new RegExp(".*Server is ready.*")))
70
70
  .withStartupTimeout(120000);
@@ -17,7 +17,7 @@ const BOLT_PORT = 7687;
17
17
  const HTTP_PORT = 7474;
18
18
  const USERNAME = "neo4j";
19
19
  class Neo4jContainer extends __1.GenericContainer {
20
- constructor(image = "neo4j:4.3.2") {
20
+ constructor(image = "neo4j:4.4.12") {
21
21
  super(image);
22
22
  this.password = new uuid_1.RandomUuid().nextUuid();
23
23
  this.apoc = false;
@@ -41,13 +41,19 @@ class Neo4jContainer extends __1.GenericContainer {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [BOLT_PORT, HTTP_PORT]))
43
43
  .withWaitStrategy(__1.Wait.forLogMessage("Started."))
44
- .withEnv("NEO4J_AUTH", `${USERNAME}/${this.password}`)
44
+ .withEnvironment({ NEO4J_AUTH: `${USERNAME}/${this.password}` })
45
45
  .withStartupTimeout(120000);
46
46
  if (this.apoc) {
47
- this.withEnv("NEO4JLABS_PLUGINS", '["apoc"]').withEnv("NEO4J_dbms_security_procedures_unrestricted", "apoc.*");
47
+ this.withEnvironment({
48
+ NEO4JLABS_PLUGINS: '["apoc"]',
49
+ NEO4J_dbms_security_procedures_unrestricted: "apoc.*",
50
+ });
48
51
  }
49
52
  if (this.ttl) {
50
- this.withEnv("NEO4J_apoc_ttl_enabled", "true").withEnv("NEO4J_apoc_ttl_schedule", this.ttl.toString());
53
+ this.withEnvironment({
54
+ NEO4J_apoc_ttl_enabled: "true",
55
+ NEO4J_apoc_ttl_schedule: this.ttl.toString(),
56
+ });
51
57
  }
52
58
  return new StartedNeo4jContainer(yield _super.start.call(this), this.password);
53
59
  });
@@ -1,7 +1,6 @@
1
1
  import { GenericContainer } from "../../generic-container/generic-container";
2
2
  import { StartedTestContainer } from "../../test-container";
3
3
  import { AbstractStartedContainer } from "../abstract-started-container";
4
- import { Port } from "../../port";
5
4
  export declare class PostgreSqlContainer extends GenericContainer {
6
5
  private database;
7
6
  private username;
@@ -18,7 +17,7 @@ export declare class StartedPostgreSqlContainer extends AbstractStartedContainer
18
17
  private readonly password;
19
18
  private readonly port;
20
19
  constructor(startedTestContainer: StartedTestContainer, database: string, username: string, password: string);
21
- getPort(): Port;
20
+ getPort(): number;
22
21
  getDatabase(): string;
23
22
  getUsername(): string;
24
23
  getPassword(): string;
@@ -39,9 +39,11 @@ class PostgreSqlContainer extends generic_container_1.GenericContainer {
39
39
  });
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [POSTGRES_PORT]))
42
- .withEnv("POSTGRES_DB", this.database)
43
- .withEnv("POSTGRES_USER", this.username)
44
- .withEnv("POSTGRES_PASSWORD", this.password)
42
+ .withEnvironment({
43
+ POSTGRES_DB: this.database,
44
+ POSTGRES_USER: this.username,
45
+ POSTGRES_PASSWORD: this.password,
46
+ })
45
47
  .withStartupTimeout(120000);
46
48
  return new StartedPostgreSqlContainer(yield _super.start.call(this), this.database, this.username, this.password);
47
49
  });
@@ -1,8 +1,7 @@
1
1
  import { BoundPorts } from "./bound-ports";
2
- import { Port } from "./port";
3
2
  import { PortGenerator } from "./port-generator";
4
3
  export declare class PortBinder {
5
4
  private readonly portGenerator;
6
5
  constructor(portGenerator?: PortGenerator);
7
- bind(ports: Port[]): Promise<BoundPorts>;
6
+ bind(ports: number[]): Promise<BoundPorts>;
8
7
  }
@@ -1,19 +1,17 @@
1
- import { Port } from "./port";
2
- import { Host } from "./docker/types";
3
1
  import Dockerode from "dockerode";
4
2
  export interface PortCheck {
5
- isBound(port: Port): Promise<boolean>;
3
+ isBound(port: number): Promise<boolean>;
6
4
  }
7
5
  export declare class HostPortCheck implements PortCheck {
8
6
  private readonly host;
9
- constructor(host: Host);
10
- isBound(port: Port): Promise<boolean>;
7
+ constructor(host: string);
8
+ isBound(port: number): Promise<boolean>;
11
9
  }
12
10
  export declare class InternalPortCheck implements PortCheck {
13
11
  private readonly container;
14
12
  private isDistroless;
15
13
  private commandOutputs;
16
14
  constructor(container: Dockerode.Container);
17
- isBound(port: Port): Promise<boolean>;
15
+ isBound(port: number): Promise<boolean>;
18
16
  private commandOutputsKey;
19
17
  }
@@ -52,7 +52,7 @@ class InternalPortCheck {
52
52
  ["/bin/sh", "-c", `nc -vz -w 1 localhost ${port}`],
53
53
  ["/bin/bash", "-c", `</dev/tcp/localhost/${port}`],
54
54
  ];
55
- const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command, { stdin: true, detach: false, tty: true })));
55
+ const commandResults = yield Promise.all(commands.map((command) => (0, exec_container_1.execContainer)(this.container, command, { stdin: true, detach: false, tty: true }, false)));
56
56
  const isBound = commandResults.some((result) => result.exitCode === 0);
57
57
  if (!isBound) {
58
58
  const shellExists = commandResults.some((result) => result.exitCode !== 126);
@@ -1,11 +1,10 @@
1
1
  import { SshConnection } from "ssh-remote-port-forward";
2
- import { Port } from "./port";
3
2
  import { StartedTestContainer } from "./test-container";
4
3
  export declare class PortForwarder {
5
4
  private readonly sshConnection;
6
5
  private readonly container;
7
6
  constructor(sshConnection: SshConnection, container: StartedTestContainer);
8
- exposeHostPort(port: Port): Promise<void>;
7
+ exposeHostPort(port: number): Promise<void>;
9
8
  getNetworkId(): string;
10
9
  getIpAddress(): string;
11
10
  private getNetworkName;
@@ -62,8 +62,8 @@ class PortForwarderInstance {
62
62
  const container = yield new generic_container_1.GenericContainer(images_1.SSHD_IMAGE)
63
63
  .withName(`testcontainers-port-forwarder-${session_id_1.sessionId}`)
64
64
  .withExposedPorts(containerPort)
65
- .withEnv("PASSWORD", password)
66
- .withCmd([
65
+ .withEnvironment({ PASSWORD: password })
66
+ .withCommand([
67
67
  "sh",
68
68
  "-c",
69
69
  `echo "${username}:$PASSWORD" | chpasswd && /usr/sbin/sshd -D -o PermitRootLogin=yes -o AddressFamily=inet -o GatewayPorts=yes`,
@@ -1,16 +1,15 @@
1
- import { Port } from "./port";
2
1
  export interface PortGenerator {
3
- generatePort(): Promise<Port>;
2
+ generatePort(): Promise<number>;
4
3
  }
5
4
  export declare class RandomUniquePortGenerator implements PortGenerator {
6
5
  private readonly portGenerator;
7
6
  private static readonly assignedPorts;
8
7
  constructor(portGenerator?: PortGenerator);
9
- generatePort(): Promise<Port>;
8
+ generatePort(): Promise<number>;
10
9
  }
11
10
  export declare class FixedPortGenerator implements PortGenerator {
12
11
  private readonly ports;
13
12
  private portIndex;
14
- constructor(ports: Port[]);
15
- generatePort(): Promise<Port>;
13
+ constructor(ports: number[]);
14
+ generatePort(): Promise<number>;
16
15
  }
package/dist/port.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- export declare type Port = number;
2
- export declare type PortString = string;
3
1
  export declare type PortWithBinding = {
4
- container: Port;
5
- host: Port;
2
+ container: number;
3
+ host: number;
6
4
  };
7
- export declare type PortWithOptionalBinding = Port | PortWithBinding;
5
+ export declare type PortWithOptionalBinding = number | PortWithBinding;
8
6
  export declare const getContainerPort: (port: PortWithOptionalBinding) => number;
9
7
  export declare const hasHostBinding: (port: PortWithOptionalBinding) => port is PortWithBinding;
package/dist/reaper.js CHANGED
@@ -88,7 +88,7 @@ class ReaperInstance {
88
88
  const container = new generic_container_1.GenericContainer(images_1.REAPER_IMAGE)
89
89
  .withName(`testcontainers-ryuk-${session_id_1.sessionId}`)
90
90
  .withExposedPorts(containerPort)
91
- .withBindMount(dockerSocket, "/var/run/docker.sock")
91
+ .withBindMounts([{ source: dockerSocket, target: "/var/run/docker.sock" }])
92
92
  .withWaitStrategy(wait_1.Wait.forLogMessage(/.+ Started!/));
93
93
  if (this.isPrivileged()) {
94
94
  container.withPrivilegedMode();
@@ -1,27 +1,33 @@
1
1
  /// <reference types="node" />
2
- import { Port, PortWithOptionalBinding } from "./port";
2
+ import { 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, Labels } from "./docker/types";
6
+ import { ExecResult, ExtraHost, TmpFs, Labels, Ulimits, BindMount, FileToCopy, ContentToCopy, Environment } from "./docker/types";
7
+ import { StartedNetwork } from "./network";
7
8
  export interface TestContainer {
8
9
  start(): Promise<StartedTestContainer>;
9
- withEnv(key: EnvKey, value: EnvValue): this;
10
- withCmd(cmd: Command[]): this;
10
+ withEnvironment(environment: Environment): this;
11
+ withCommand(command: string[]): this;
12
+ withEntrypoint(entrypoint: string[]): this;
11
13
  withTmpFs(tmpFs: TmpFs): this;
14
+ withUlimits(ulimits: Ulimits): this;
15
+ withAddedCapabilities(...capabilities: string[]): this;
16
+ withDroppedCapabilities(...capabilities: string[]): this;
12
17
  withExposedPorts(...ports: PortWithOptionalBinding[]): this;
13
- withBindMount(source: Dir, target: Dir, bindMode: BindMode): this;
18
+ withBindMounts(bindMounts: BindMount[]): this;
14
19
  withWaitStrategy(waitStrategy: WaitStrategy): this;
15
20
  withStartupTimeout(startupTimeout: number): this;
16
- withNetworkMode(networkMode: NetworkMode): this;
17
- withExtraHosts(...extraHosts: ExtraHost[]): this;
21
+ withNetwork(network: StartedNetwork): this;
22
+ withNetworkMode(networkMode: string): this;
23
+ withExtraHosts(extraHosts: ExtraHost[]): this;
18
24
  withDefaultLogDriver(): this;
19
25
  withPrivilegedMode(): this;
20
26
  withUser(user: string): this;
21
27
  withPullPolicy(pullPolicy: PullPolicy): this;
22
28
  withReuse(): this;
23
- withCopyFileToContainer(sourcePath: string, containerPath: string): this;
24
- withCopyContentToContainer(content: string | Buffer | Readable, containerPath: string): this;
29
+ withCopyFilesToContainer(filesToCopy: FileToCopy[]): this;
30
+ withCopyContentToContainer(contentsToCopy: ContentToCopy[]): this;
25
31
  }
26
32
  export interface RestartOptions {
27
33
  timeout: number;
@@ -30,6 +36,10 @@ export interface StopOptions {
30
36
  timeout: number;
31
37
  removeVolumes: boolean;
32
38
  }
39
+ export interface DockerComposeDownOptions {
40
+ timeout: number;
41
+ removeVolumes: boolean;
42
+ }
33
43
  export interface ExecOptions {
34
44
  tty: boolean;
35
45
  detach: boolean;
@@ -38,15 +48,15 @@ export interface ExecOptions {
38
48
  export interface StartedTestContainer {
39
49
  stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
40
50
  restart(options?: Partial<RestartOptions>): Promise<void>;
41
- getHost(): Host;
42
- getMappedPort(port: Port): Port;
43
- getName(): ContainerName;
51
+ getHost(): string;
52
+ getMappedPort(port: number): number;
53
+ getName(): string;
44
54
  getLabels(): Labels;
45
- getId(): Id;
55
+ getId(): string;
46
56
  getNetworkNames(): string[];
47
57
  getNetworkId(networkName: string): string;
48
58
  getIpAddress(networkName: string): string;
49
- exec(command: Command[], options?: Partial<ExecOptions>): Promise<ExecResult>;
59
+ exec(command: string[], options?: Partial<ExecOptions>): Promise<ExecResult>;
50
60
  logs(): Promise<Readable>;
51
61
  }
52
62
  export interface StoppedTestContainer {
@@ -1,4 +1,3 @@
1
- import { Port } from "./port";
2
1
  export declare class TestContainers {
3
- static exposeHostPorts(...ports: Port[]): Promise<void>;
2
+ static exposeHostPorts(...ports: number[]): Promise<void>;
4
3
  }