testcontainers 8.1.1 → 8.3.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 +17 -6
- package/dist/docker/docker-client.js +13 -2
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +2 -0
- package/dist/docker-compose-environment/docker-compose-environment.js +8 -0
- package/dist/log-system-diagnostics.js +1 -1
- package/dist/registry-auth-locator/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,14 +18,15 @@ npm i -D testcontainers
|
|
|
18
18
|
|
|
19
19
|
The following environment variables are supported:
|
|
20
20
|
|
|
21
|
-
- `DEBUG=testcontainers`
|
|
22
|
-
- `DEBUG=testcontainers:containers`
|
|
23
|
-
- `DEBUG=testcontainers*`
|
|
21
|
+
- `DEBUG=testcontainers` Enable testcontainers logs
|
|
22
|
+
- `DEBUG=testcontainers:containers` Enable container logs
|
|
23
|
+
- `DEBUG=testcontainers*` Enable all logs
|
|
24
24
|
- `DOCKER_HOST=tcp://docker:2375` Sets the URL of the docker daemon
|
|
25
|
-
- `DOCKER_TLS_VERIFY=1` When set to
|
|
25
|
+
- `DOCKER_TLS_VERIFY=1` When set to `1`, enables TLS communication with the docker
|
|
26
26
|
daemon
|
|
27
|
-
- `
|
|
28
|
-
|
|
27
|
+
- `DOCKER_CONFIG=/some/path` Configures the path to the `config.json`. Defaults to `~/.docker`
|
|
28
|
+
- `DOCKER_CERT_PATH=/some/path` Configures the path to the `ca.pem`, `cert.pem`, and `key.pem` files used for TLS
|
|
29
|
+
verification. Defaults to `~/.docker`
|
|
29
30
|
- `TESTCONTAINERS_HOST_OVERRIDE=docker.svc.local` Docker's host on which ports are exposed
|
|
30
31
|
- `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock` Path to Docker's socket. Used by [ryuk](#ryuk) and
|
|
31
32
|
other [auxiliary containers](#auxiliary-containers) that need to perform Docker actions
|
|
@@ -547,6 +548,16 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
|
|
|
547
548
|
.up();
|
|
548
549
|
```
|
|
549
550
|
|
|
551
|
+
Specify the [environment file](https://docs.docker.com/compose/environment-variables/#using-the---env-file--option):
|
|
552
|
+
|
|
553
|
+
```javascript
|
|
554
|
+
const { DockerComposeEnvironment } = require("testcontainers");
|
|
555
|
+
|
|
556
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
557
|
+
.withEnvFile(".env.custom")
|
|
558
|
+
.up();
|
|
559
|
+
```
|
|
560
|
+
|
|
550
561
|
Specify [profiles](https://docs.docker.com/compose/profiles/):
|
|
551
562
|
|
|
552
563
|
```javascript
|
|
@@ -52,7 +52,9 @@ const createDockerodeOptions = (dockerConfig) => {
|
|
|
52
52
|
dockerOptions.socketPath = dockerConfig.socketPath;
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
|
|
55
|
+
const { hostname, port } = new url_1.URL(dockerConfig.uri);
|
|
56
|
+
dockerOptions.host = hostname;
|
|
57
|
+
dockerOptions.port = port;
|
|
56
58
|
}
|
|
57
59
|
if (dockerConfig.ssl) {
|
|
58
60
|
dockerOptions.ca = dockerConfig.ssl.ca;
|
|
@@ -61,7 +63,16 @@ const createDockerodeOptions = (dockerConfig) => {
|
|
|
61
63
|
}
|
|
62
64
|
return dockerOptions;
|
|
63
65
|
};
|
|
64
|
-
const isDockerDaemonReachable = (dockerode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const isDockerDaemonReachable = (dockerode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const response = yield dockerode.ping();
|
|
69
|
+
return response.toString() === "OK";
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
logger_1.log.warn(`Docker daemon is not reachable: ${err}`);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
65
76
|
class ConfigurationStrategy {
|
|
66
77
|
getDockerConfig() {
|
|
67
78
|
const { DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH } = process.env;
|
|
@@ -8,6 +8,7 @@ export declare class DockerComposeEnvironment {
|
|
|
8
8
|
private projectName;
|
|
9
9
|
private build;
|
|
10
10
|
private recreate;
|
|
11
|
+
private envFile;
|
|
11
12
|
private profiles;
|
|
12
13
|
private env;
|
|
13
14
|
private waitStrategy;
|
|
@@ -15,6 +16,7 @@ export declare class DockerComposeEnvironment {
|
|
|
15
16
|
constructor(composeFilePath: string, composeFiles: string | string[], uuid?: Uuid);
|
|
16
17
|
withBuild(): this;
|
|
17
18
|
withEnv(key: EnvKey, value: EnvValue): this;
|
|
19
|
+
withEnvFile(envFile: string): this;
|
|
18
20
|
withProfiles(...profiles: string[]): this;
|
|
19
21
|
withNoRecreate(): this;
|
|
20
22
|
withWaitStrategy(containerName: string, waitStrategy: WaitStrategy): this;
|
|
@@ -30,6 +30,7 @@ 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
34
|
this.profiles = [];
|
|
34
35
|
this.env = {};
|
|
35
36
|
this.waitStrategy = {};
|
|
@@ -46,6 +47,10 @@ class DockerComposeEnvironment {
|
|
|
46
47
|
this.env[key] = value;
|
|
47
48
|
return this;
|
|
48
49
|
}
|
|
50
|
+
withEnvFile(envFile) {
|
|
51
|
+
this.envFile = envFile;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
49
54
|
withProfiles(...profiles) {
|
|
50
55
|
this.profiles = profiles;
|
|
51
56
|
return this;
|
|
@@ -80,6 +85,9 @@ class DockerComposeEnvironment {
|
|
|
80
85
|
commandOptions.push("--no-recreate");
|
|
81
86
|
}
|
|
82
87
|
const composeOptions = [];
|
|
88
|
+
if (this.envFile) {
|
|
89
|
+
composeOptions.push("--env-file", this.envFile);
|
|
90
|
+
}
|
|
83
91
|
this.profiles.forEach((profile) => composeOptions.push("--profile", profile));
|
|
84
92
|
yield docker_compose_up_1.dockerComposeUp(Object.assign(Object.assign({}, options), { commandOptions, composeOptions, env: this.env }), services);
|
|
85
93
|
const startedContainers = (yield list_containers_1.listContainers()).filter((container) => container.Labels["com.docker.compose.project"] === this.projectName);
|
|
@@ -19,7 +19,7 @@ const logSystemDiagnostics = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
19
19
|
docker: yield get_info_1.getDockerInfo(),
|
|
20
20
|
dockerCompose: yield getDockerComposeInfo(),
|
|
21
21
|
};
|
|
22
|
-
logger_1.log.debug(`System diagnostics: ${JSON.stringify(info
|
|
22
|
+
logger_1.log.debug(`System diagnostics: ${JSON.stringify(info)}`);
|
|
23
23
|
});
|
|
24
24
|
exports.logSystemDiagnostics = logSystemDiagnostics;
|
|
25
25
|
const getNodeInfo = () => {
|
|
@@ -21,7 +21,8 @@ const creds_store_1 = require("./creds-store");
|
|
|
21
21
|
const auths_1 = require("./auths");
|
|
22
22
|
const logger_1 = require("../logger");
|
|
23
23
|
const DEFAULT_REGISTRY = "https://index.docker.io/v1/";
|
|
24
|
-
const
|
|
24
|
+
const dockerConfigLocation = process.env.DOCKER_CONFIG || `${os_1.default.homedir()}/.docker`;
|
|
25
|
+
const dockerConfigFile = path_1.default.resolve(dockerConfigLocation, "config.json");
|
|
25
26
|
const readDockerConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
27
|
if (!fs_1.existsSync(dockerConfigFile)) {
|
|
27
28
|
return Promise.resolve({});
|