testcontainers 8.6.0 → 8.6.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,9 +24,9 @@ The following environment variables are supported:
24
24
  - `DOCKER_HOST=tcp://docker:2375` Sets the URL of the docker daemon
25
25
  - `DOCKER_TLS_VERIFY=1` When set to `1`, enables TLS communication with the docker
26
26
  daemon
27
- - `DOCKER_CONFIG=/some/path` Configures the path to the `config.json`. Defaults to `~/.docker`
28
27
  - `DOCKER_CERT_PATH=/some/path` Configures the path to the `ca.pem`, `cert.pem`, and `key.pem` files used for TLS
29
28
  verification. Defaults to `~/.docker`
29
+ - `DOCKER_CONFIG=/some/path` Configures the path to the `config.json`. Defaults to `~/.docker`
30
30
  - `TESTCONTAINERS_HOST_OVERRIDE=docker.svc.local` Docker's host on which ports are exposed
31
31
  - `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock` Path to Docker's socket. Used by [ryuk](#ryuk) and
32
32
  other [auxiliary containers](#auxiliary-containers) that need to perform Docker actions
@@ -17,7 +17,7 @@ const dockerode_1 = __importDefault(require("dockerode"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const logger_1 = require("../logger");
19
19
  const url_1 = require("url");
20
- const fs_1 = __importDefault(require("fs"));
20
+ const fs_1 = require("fs");
21
21
  const run_in_container_1 = require("./functions/run-in-container");
22
22
  const log_system_diagnostics_1 = require("../log-system-diagnostics");
23
23
  require("../testcontainers-properties-file");
@@ -30,11 +30,10 @@ const getDockerClient = () => __awaiter(void 0, void 0, void 0, function* () {
30
30
  for (const strategy of strategies) {
31
31
  if (strategy.isApplicable()) {
32
32
  logger_1.log.debug(`Found applicable Docker client strategy: ${strategy.getName()}`);
33
- const dockerConfig = strategy.getDockerConfig();
34
- const dockerode = new dockerode_1.default(createDockerodeOptions(dockerConfig));
35
- logger_1.log.debug(`Testing Docker client strategy URI: ${dockerConfig.uri}`);
33
+ const { uri, dockerode } = yield strategy.initialise();
34
+ logger_1.log.debug(`Testing Docker client strategy URI: ${uri}`);
36
35
  if (yield isDockerDaemonReachable(dockerode)) {
37
- const host = yield resolveHost(dockerode, dockerConfig.uri);
36
+ const host = yield resolveHost(dockerode, uri);
38
37
  logger_1.log.info(`Using Docker client strategy: ${strategy.getName()}, Docker host: ${host}`);
39
38
  log_system_diagnostics_1.logSystemDiagnostics();
40
39
  return { host, dockerode };
@@ -46,23 +45,6 @@ const getDockerClient = () => __awaiter(void 0, void 0, void 0, function* () {
46
45
  }
47
46
  throw new Error("No Docker client strategy found");
48
47
  });
49
- const createDockerodeOptions = (dockerConfig) => {
50
- const dockerOptions = {};
51
- if (dockerConfig.socketPath) {
52
- dockerOptions.socketPath = dockerConfig.socketPath;
53
- }
54
- else {
55
- const { hostname, port } = new url_1.URL(dockerConfig.uri);
56
- dockerOptions.host = hostname;
57
- dockerOptions.port = port;
58
- }
59
- if (dockerConfig.ssl) {
60
- dockerOptions.ca = dockerConfig.ssl.ca;
61
- dockerOptions.cert = dockerConfig.ssl.cert;
62
- dockerOptions.key = dockerConfig.ssl.key;
63
- }
64
- return dockerOptions;
65
- };
66
48
  const isDockerDaemonReachable = (dockerode) => __awaiter(void 0, void 0, void 0, function* () {
67
49
  try {
68
50
  const response = yield dockerode.ping();
@@ -74,18 +56,25 @@ const isDockerDaemonReachable = (dockerode) => __awaiter(void 0, void 0, void 0,
74
56
  }
75
57
  });
76
58
  class ConfigurationStrategy {
77
- getDockerConfig() {
78
- const { DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH } = process.env;
79
- return {
80
- uri: DOCKER_HOST,
81
- ssl: DOCKER_TLS_VERIFY === "1" && DOCKER_CERT_PATH !== undefined
82
- ? {
83
- ca: path_1.default.resolve(DOCKER_CERT_PATH, "ca.pem"),
84
- cert: path_1.default.resolve(DOCKER_CERT_PATH, "cert.pem"),
85
- key: path_1.default.resolve(DOCKER_CERT_PATH, "key.pem"),
86
- }
87
- : undefined,
88
- };
59
+ initialise() {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const { DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH } = process.env;
62
+ const dockerOptions = {};
63
+ const url = new url_1.URL(DOCKER_HOST);
64
+ const dockerHost = url.host === "" ? `tcp://${DOCKER_HOST}` : DOCKER_HOST;
65
+ const { hostname, port } = new url_1.URL(dockerHost);
66
+ dockerOptions.host = hostname;
67
+ dockerOptions.port = port;
68
+ if (DOCKER_TLS_VERIFY === "1" && DOCKER_CERT_PATH !== undefined) {
69
+ dockerOptions.ca = yield fs_1.promises.readFile(path_1.default.resolve(DOCKER_CERT_PATH, "ca.pem"));
70
+ dockerOptions.cert = yield fs_1.promises.readFile(path_1.default.resolve(DOCKER_CERT_PATH, "cert.pem"));
71
+ dockerOptions.key = yield fs_1.promises.readFile(path_1.default.resolve(DOCKER_CERT_PATH, "key.pem"));
72
+ }
73
+ return {
74
+ uri: dockerHost,
75
+ dockerode: new dockerode_1.default(dockerOptions),
76
+ };
77
+ });
89
78
  }
90
79
  isApplicable() {
91
80
  return process.env.DOCKER_HOST !== undefined;
@@ -95,11 +84,13 @@ class ConfigurationStrategy {
95
84
  }
96
85
  }
97
86
  class UnixSocketStrategy {
98
- getDockerConfig() {
99
- return {
100
- uri: "unix:///var/run/docker.sock",
101
- socketPath: "/var/run/docker.sock",
102
- };
87
+ initialise() {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ return {
90
+ uri: "unix:///var/run/docker.sock",
91
+ dockerode: new dockerode_1.default({ socketPath: "/var/run/docker.sock" }),
92
+ };
93
+ });
103
94
  }
104
95
  isApplicable() {
105
96
  return process.platform === "linux" || process.platform === "darwin";
@@ -109,11 +100,13 @@ class UnixSocketStrategy {
109
100
  }
110
101
  }
111
102
  class NpipeSocketStrategy {
112
- getDockerConfig() {
113
- return {
114
- uri: "npipe:////./pipe/docker_engine",
115
- socketPath: "//./pipe/docker_engine",
116
- };
103
+ initialise() {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ return {
106
+ uri: "npipe:////./pipe/docker_engine",
107
+ dockerode: new dockerode_1.default({ socketPath: "//./pipe/docker_engine" }),
108
+ };
109
+ });
117
110
  }
118
111
  isApplicable() {
119
112
  return process.platform === "win32";
@@ -156,5 +149,5 @@ const findGateway = (dockerode) => __awaiter(void 0, void 0, void 0, function* (
156
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;
157
150
  });
158
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 }'"]); });
159
- const isInContainer = () => fs_1.default.existsSync("/.dockerenv");
152
+ const isInContainer = () => fs_1.existsSync("/.dockerenv");
160
153
  exports.dockerClient = getDockerClient();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "8.6.0",
4
+ "version": "8.6.1-beta.0",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "keywords": [