testcontainers 8.16.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.
- package/README.md +115 -78
- package/dist/bound-ports.d.ts +4 -4
- package/dist/docker/docker-client.d.ts +1 -2
- package/dist/docker/functions/container/container-logs.js +1 -6
- package/dist/docker/functions/container/create-container.d.ts +5 -5
- package/dist/docker/functions/container/create-container.js +5 -6
- package/dist/docker/functions/container/exec-container.d.ts +2 -2
- package/dist/docker/functions/container/get-container.d.ts +1 -2
- package/dist/docker/functions/container/inspect-container.d.ts +2 -2
- package/dist/docker/functions/create-labels.d.ts +1 -1
- package/dist/docker/functions/image/build-image.d.ts +2 -2
- package/dist/docker/functions/run-in-container.d.ts +1 -2
- package/dist/docker/types.d.ts +23 -22
- package/dist/docker-compose/default-docker-compose-options.d.ts +1 -1
- package/dist/docker-compose/default-docker-compose-options.js +2 -2
- package/dist/docker-compose/docker-compose-options.d.ts +2 -2
- package/dist/docker-compose/functions/docker-compose-up.d.ts +1 -1
- package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -5
- package/dist/docker-compose-environment/docker-compose-environment.js +11 -11
- package/dist/generic-container/generic-container-builder.d.ts +3 -3
- package/dist/generic-container/generic-container-builder.js +2 -2
- package/dist/generic-container/generic-container.d.ts +16 -17
- package/dist/generic-container/generic-container.js +31 -27
- package/dist/generic-container/started-generic-container.d.ts +7 -8
- package/dist/modules/abstract-started-container.d.ts +6 -7
- package/dist/modules/arangodb/arangodb-container.js +2 -2
- package/dist/modules/elasticsearch/elasticsearch-container.js +2 -2
- package/dist/modules/kafka/kafka-container.d.ts +4 -5
- package/dist/modules/kafka/kafka-container.js +41 -34
- package/dist/modules/mongodb/mongodb-container.js +1 -1
- package/dist/modules/mysql/mysql-container.d.ts +1 -2
- package/dist/modules/mysql/mysql-container.js +7 -5
- package/dist/modules/nats/nats-container.d.ts +1 -1
- package/dist/modules/nats/nats-container.js +2 -2
- package/dist/modules/neo4j/neo4j-container.js +10 -4
- package/dist/modules/postgresql/postgresql-container.d.ts +1 -2
- package/dist/modules/postgresql/postgresql-container.js +5 -3
- package/dist/port-binder.d.ts +1 -2
- package/dist/port-check.d.ts +4 -6
- package/dist/port-forwarder.d.ts +1 -2
- package/dist/port-forwarder.js +2 -2
- package/dist/port-generator.d.ts +4 -5
- package/dist/port.d.ts +3 -5
- package/dist/reaper.js +1 -1
- package/dist/test-container.d.ts +16 -14
- package/dist/test-containers.d.ts +1 -2
- package/package.json +29 -25
package/README.md
CHANGED
|
@@ -118,7 +118,10 @@ const { GenericContainer } = require("testcontainers");
|
|
|
118
118
|
const buildContext = path.resolve(__dirname, "dir-containing-dockerfile");
|
|
119
119
|
|
|
120
120
|
const container = await GenericContainer.fromDockerfile(buildContext)
|
|
121
|
-
.
|
|
121
|
+
.withBuildArgs({
|
|
122
|
+
ARG_1: "ARG_VALUE_1",
|
|
123
|
+
ARG_2: "ARG_VALUE_2",
|
|
124
|
+
})
|
|
122
125
|
.build();
|
|
123
126
|
|
|
124
127
|
const startedContainer = await container
|
|
@@ -161,12 +164,12 @@ Enabling container reuse, note that two containers are considered equal if their
|
|
|
161
164
|
const { GenericContainer } = require("testcontainers");
|
|
162
165
|
|
|
163
166
|
const container1 = await new GenericContainer("alpine")
|
|
164
|
-
.
|
|
167
|
+
.withCommand(["sleep", "infinity"])
|
|
165
168
|
.withReuse()
|
|
166
169
|
.start();
|
|
167
170
|
|
|
168
171
|
const container2 = await new GenericContainer("alpine")
|
|
169
|
-
.
|
|
172
|
+
.withCommand(["sleep", "infinity"])
|
|
170
173
|
.withReuse()
|
|
171
174
|
.start();
|
|
172
175
|
|
|
@@ -200,7 +203,7 @@ Creating a container with a command:
|
|
|
200
203
|
const { GenericContainer } = require("testcontainers");
|
|
201
204
|
|
|
202
205
|
const container = await new GenericContainer("alpine")
|
|
203
|
-
.
|
|
206
|
+
.withCommand(["sleep", "infinity"])
|
|
204
207
|
.start();
|
|
205
208
|
```
|
|
206
209
|
|
|
@@ -220,7 +223,7 @@ Execute commands inside a running container:
|
|
|
220
223
|
const { GenericContainer } = require("testcontainers");
|
|
221
224
|
|
|
222
225
|
const container = await new GenericContainer("alpine")
|
|
223
|
-
.
|
|
226
|
+
.withCommand(["sleep", "infinity"])
|
|
224
227
|
.start();
|
|
225
228
|
|
|
226
229
|
const { output, exitCode } = await container.exec(["echo", "hello", "world"]);
|
|
@@ -238,7 +241,6 @@ stream
|
|
|
238
241
|
.on("data", line => console.log(line))
|
|
239
242
|
.on("err", line => console.error(line))
|
|
240
243
|
.on("end", () => console.log("Stream closed"));
|
|
241
|
-
|
|
242
244
|
```
|
|
243
245
|
|
|
244
246
|
Creating a container with bind mounts:
|
|
@@ -247,8 +249,14 @@ Creating a container with bind mounts:
|
|
|
247
249
|
const { GenericContainer } = require("testcontainers");
|
|
248
250
|
|
|
249
251
|
const container = await new GenericContainer("alpine")
|
|
250
|
-
.
|
|
251
|
-
|
|
252
|
+
.withBindMounts([{
|
|
253
|
+
source: "/local/file.txt",
|
|
254
|
+
target:"/remote/file.txt"
|
|
255
|
+
}, {
|
|
256
|
+
source: "/local/dir",
|
|
257
|
+
target:"/remote/dir",
|
|
258
|
+
mode: "ro"
|
|
259
|
+
}])
|
|
252
260
|
.start();
|
|
253
261
|
```
|
|
254
262
|
|
|
@@ -263,41 +271,6 @@ const container = await new GenericContainer("postgres")
|
|
|
263
271
|
.start();
|
|
264
272
|
```
|
|
265
273
|
|
|
266
|
-
Creating a container with ulimits:
|
|
267
|
-
|
|
268
|
-
```javascript
|
|
269
|
-
const { GenericContainer } = require("testcontainers");
|
|
270
|
-
|
|
271
|
-
const container = await new GenericContainer("aline")
|
|
272
|
-
.withUlimits({
|
|
273
|
-
memlock: {
|
|
274
|
-
hard: -1,
|
|
275
|
-
soft: -1
|
|
276
|
-
}
|
|
277
|
-
})
|
|
278
|
-
.start();
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
Creating a container with added [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html):
|
|
282
|
-
|
|
283
|
-
```javascript
|
|
284
|
-
const { GenericContainer } = require("testcontainers");
|
|
285
|
-
|
|
286
|
-
const container = await new GenericContainer("aline")
|
|
287
|
-
.withAddedCapabilities("NET_ADMIN", "IPC_LOCK")
|
|
288
|
-
.start();
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
Creating a container with dropped [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html):
|
|
292
|
-
|
|
293
|
-
```javascript
|
|
294
|
-
const { GenericContainer } = require("testcontainers");
|
|
295
|
-
|
|
296
|
-
const container = await new GenericContainer("aline")
|
|
297
|
-
.withDroppedCapabilities("NET_ADMIN", "IPC_LOCK")
|
|
298
|
-
.start();
|
|
299
|
-
```
|
|
300
|
-
|
|
301
274
|
Copy a file to a container before it is started:
|
|
302
275
|
|
|
303
276
|
```javascript
|
|
@@ -305,8 +278,14 @@ const { GenericContainer } = require("testcontainers");
|
|
|
305
278
|
|
|
306
279
|
const container = await new GenericContainer("postgres")
|
|
307
280
|
.withExposedPorts(5432)
|
|
308
|
-
.
|
|
309
|
-
|
|
281
|
+
.withCopyFilesToContainer([{
|
|
282
|
+
source: "/local/file.txt",
|
|
283
|
+
target: "/remote/file1.txt"
|
|
284
|
+
}])
|
|
285
|
+
.withCopyContentToContainer([{
|
|
286
|
+
content: "hello world",
|
|
287
|
+
target: "/remote/file2.txt"
|
|
288
|
+
}])
|
|
310
289
|
.start();
|
|
311
290
|
```
|
|
312
291
|
|
|
@@ -316,7 +295,10 @@ Creating a container with environment variables:
|
|
|
316
295
|
const { GenericContainer } = require("testcontainers");
|
|
317
296
|
|
|
318
297
|
const container = await new GenericContainer("alpine")
|
|
319
|
-
.
|
|
298
|
+
.withEnvironment({
|
|
299
|
+
ENV_1: "ENV_VALUE_1",
|
|
300
|
+
ENV_2: "ENV_VALUE_2",
|
|
301
|
+
})
|
|
320
302
|
.start();
|
|
321
303
|
```
|
|
322
304
|
|
|
@@ -340,7 +322,7 @@ const { GenericContainer, Wait } = require("testcontainers");
|
|
|
340
322
|
|
|
341
323
|
const container = await new GenericContainer("alpine")
|
|
342
324
|
.withHealthCheck({
|
|
343
|
-
test: "curl -f http://localhost || exit 1",
|
|
325
|
+
test: ["CMD-SHELL", "curl -f http://localhost || exit 1"],
|
|
344
326
|
interval: 1000,
|
|
345
327
|
timeout: 3000,
|
|
346
328
|
retries: 5,
|
|
@@ -350,32 +332,44 @@ const container = await new GenericContainer("alpine")
|
|
|
350
332
|
.start();
|
|
351
333
|
```
|
|
352
334
|
|
|
353
|
-
|
|
335
|
+
To execute the `test` in a shell use the form `["CMD-SHELL", "command"]`, for example:
|
|
354
336
|
|
|
355
337
|
```javascript
|
|
356
|
-
|
|
338
|
+
["CMD-SHELL", "curl -f http://localhost:8000 || exit 1"]
|
|
339
|
+
```
|
|
357
340
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
341
|
+
To execute the `test` without a shell, use the form: `["CMD", "command", "arg1", "arg2"]`, for example:
|
|
342
|
+
|
|
343
|
+
```javascript
|
|
344
|
+
["CMD", "/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/hello-world"]
|
|
361
345
|
```
|
|
362
346
|
|
|
363
|
-
|
|
347
|
+
Creating a container within a network:
|
|
364
348
|
|
|
365
349
|
```javascript
|
|
366
350
|
const { GenericContainer, Network } = require("testcontainers");
|
|
367
351
|
|
|
368
352
|
const network = await new Network()
|
|
369
|
-
|
|
353
|
+
.start();
|
|
370
354
|
|
|
371
355
|
const container = await new GenericContainer("alpine")
|
|
372
|
-
.
|
|
356
|
+
.withNetwork(network)
|
|
373
357
|
.start();
|
|
374
358
|
|
|
375
359
|
await container.stop();
|
|
376
360
|
await network.stop();
|
|
377
361
|
```
|
|
378
362
|
|
|
363
|
+
Creating a container with a network mode:
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
const { GenericContainer } = require("testcontainers");
|
|
367
|
+
|
|
368
|
+
const container = await new GenericContainer("alpine")
|
|
369
|
+
.withNetworkMode("bridge")
|
|
370
|
+
.start();
|
|
371
|
+
```
|
|
372
|
+
|
|
379
373
|
Communicate to containers on the same network via aliases:
|
|
380
374
|
|
|
381
375
|
```javascript
|
|
@@ -385,17 +379,17 @@ const network = await new Network()
|
|
|
385
379
|
.start();
|
|
386
380
|
|
|
387
381
|
const container = await new GenericContainer("alpine")
|
|
388
|
-
.
|
|
389
|
-
.
|
|
382
|
+
.withCommand(["sleep", "infinity"])
|
|
383
|
+
.withNetwork(network)
|
|
390
384
|
.start();
|
|
391
385
|
|
|
392
386
|
const fooContainer = await new GenericContainer("alpine")
|
|
393
|
-
.
|
|
394
|
-
.
|
|
387
|
+
.withCommand(["sleep", "infinity"])
|
|
388
|
+
.withNetwork(network)
|
|
395
389
|
.withNetworkAliases("foo", "bar")
|
|
396
390
|
.start();
|
|
397
391
|
|
|
398
|
-
expect((await container.exec(["
|
|
392
|
+
expect((await container.exec(["getent", "hosts", "foo"])).exitCode).toBe(0);
|
|
399
393
|
```
|
|
400
394
|
|
|
401
395
|
Add hostname mappings:
|
|
@@ -404,14 +398,17 @@ Add hostname mappings:
|
|
|
404
398
|
const { GenericContainer } = require("testcontainers");
|
|
405
399
|
|
|
406
400
|
const container = await new GenericContainer("alpine")
|
|
407
|
-
.withExtraHosts(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
401
|
+
.withExtraHosts([{
|
|
402
|
+
host: "foo",
|
|
403
|
+
ipAddress: "10.11.12.13"
|
|
404
|
+
}, {
|
|
405
|
+
host: "bar",
|
|
406
|
+
ipAddress: "11.12.13.14"
|
|
407
|
+
}])
|
|
411
408
|
.start();
|
|
412
409
|
|
|
413
|
-
expect((await container.exec(["
|
|
414
|
-
expect((await container.exec(["
|
|
410
|
+
expect((await container.exec(["getent", "hosts", "foo"])).exitCode).toBe(0);
|
|
411
|
+
expect((await container.exec(["getent", "hosts", "bar"])).exitCode).toBe(0);
|
|
415
412
|
```
|
|
416
413
|
|
|
417
414
|
Specifying a pull policy. Note that if omitted will use the `DefaultPullPolicy` which will use a locally cached image
|
|
@@ -470,6 +467,41 @@ const container = await new GenericContainer("alpine")
|
|
|
470
467
|
.start();
|
|
471
468
|
```
|
|
472
469
|
|
|
470
|
+
Creating a container with added [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html):
|
|
471
|
+
|
|
472
|
+
```javascript
|
|
473
|
+
const { GenericContainer } = require("testcontainers");
|
|
474
|
+
|
|
475
|
+
const container = await new GenericContainer("aline")
|
|
476
|
+
.withAddedCapabilities("NET_ADMIN", "IPC_LOCK")
|
|
477
|
+
.start();
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Creating a container with dropped [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html):
|
|
481
|
+
|
|
482
|
+
```javascript
|
|
483
|
+
const { GenericContainer } = require("testcontainers");
|
|
484
|
+
|
|
485
|
+
const container = await new GenericContainer("aline")
|
|
486
|
+
.withDroppedCapabilities("NET_ADMIN", "IPC_LOCK")
|
|
487
|
+
.start();
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Creating a container with ulimits:
|
|
491
|
+
|
|
492
|
+
```javascript
|
|
493
|
+
const { GenericContainer } = require("testcontainers");
|
|
494
|
+
|
|
495
|
+
const container = await new GenericContainer("aline")
|
|
496
|
+
.withUlimits({
|
|
497
|
+
memlock: {
|
|
498
|
+
hard: -1,
|
|
499
|
+
soft: -1
|
|
500
|
+
}
|
|
501
|
+
})
|
|
502
|
+
.start();
|
|
503
|
+
```
|
|
504
|
+
|
|
473
505
|
Creating a container with [IPC mode](https://docs.docker.com/engine/reference/run/#ipc-settings---ipc):
|
|
474
506
|
|
|
475
507
|
```javascript
|
|
@@ -518,7 +550,7 @@ const network = await new Network()
|
|
|
518
550
|
.start();
|
|
519
551
|
|
|
520
552
|
const container = await new GenericContainer("alpine")
|
|
521
|
-
.
|
|
553
|
+
.withNetwork(network)
|
|
522
554
|
.start();
|
|
523
555
|
|
|
524
556
|
const networkIpAddress = container.getIpAddress(network.getName());
|
|
@@ -539,7 +571,7 @@ server.listen(8000);
|
|
|
539
571
|
await TestContainers.exposeHostPorts(8000);
|
|
540
572
|
|
|
541
573
|
const container = await new GenericContainer("alpine")
|
|
542
|
-
.
|
|
574
|
+
.withCommand(["sleep", "infinity"])
|
|
543
575
|
.start();
|
|
544
576
|
|
|
545
577
|
const { output } = await container.exec(["curl", `http://host.testcontainers.internal:8000`]);
|
|
@@ -638,7 +670,8 @@ Once the environment has started, you can interact with the containers as you wo
|
|
|
638
670
|
```javascript
|
|
639
671
|
const { DockerComposeEnvironment } = require("testcontainers");
|
|
640
672
|
|
|
641
|
-
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
673
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
674
|
+
.up();
|
|
642
675
|
|
|
643
676
|
const container = environment.getContainer("alpine_1");
|
|
644
677
|
const { output, exitCode } = await container.exec(["echo", "hello", "world"]);
|
|
@@ -649,7 +682,8 @@ You can supply [multiple compose files](https://docs.docker.com/compose/extends/
|
|
|
649
682
|
```javascript
|
|
650
683
|
const { DockerComposeEnvironment } = require("testcontainers");
|
|
651
684
|
|
|
652
|
-
const environment = await new DockerComposeEnvironment(composeFilePath, [composeFile1, composeFile2])
|
|
685
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, [composeFile1, composeFile2])
|
|
686
|
+
.up();
|
|
653
687
|
|
|
654
688
|
await environment.stop();
|
|
655
689
|
```
|
|
@@ -659,7 +693,8 @@ If you have multiple docker-compose environments which share dependencies such a
|
|
|
659
693
|
```javascript
|
|
660
694
|
const { DockerComposeEnvironment } = require("testcontainers");
|
|
661
695
|
|
|
662
|
-
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
696
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
697
|
+
.up();
|
|
663
698
|
|
|
664
699
|
await environment.stop();
|
|
665
700
|
```
|
|
@@ -718,7 +753,7 @@ Then we can set `TAG` as follows:
|
|
|
718
753
|
const { DockerComposeEnvironment } = require("testcontainers");
|
|
719
754
|
|
|
720
755
|
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
721
|
-
.
|
|
756
|
+
.withEnvironment({ "TAG": "VALUE" })
|
|
722
757
|
.up();
|
|
723
758
|
```
|
|
724
759
|
|
|
@@ -727,7 +762,8 @@ Testcontainers will not wait for an environment to down, to override:
|
|
|
727
762
|
```javascript
|
|
728
763
|
const { GenericContainer } = require("testcontainers");
|
|
729
764
|
|
|
730
|
-
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
765
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
766
|
+
.up();
|
|
731
767
|
|
|
732
768
|
await environment.down({
|
|
733
769
|
timeout: 10000
|
|
@@ -739,7 +775,8 @@ Testcontainers will remove associated volumes created by the environment when do
|
|
|
739
775
|
```javascript
|
|
740
776
|
const { GenericContainer } = require("testcontainers");
|
|
741
777
|
|
|
742
|
-
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
778
|
+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
|
|
779
|
+
.up();
|
|
743
780
|
|
|
744
781
|
await environment.down({
|
|
745
782
|
removeVolumes: false
|
|
@@ -806,10 +843,10 @@ Testcontainers may need to create auxiliary containers to provide its functional
|
|
|
806
843
|
|
|
807
844
|
To avoid Docker pull limits, you can host your own images and use them by setting the appropriate environment variables:
|
|
808
845
|
|
|
809
|
-
| Container | Environment Variable
|
|
810
|
-
|
|
811
|
-
| ryuk
|
|
812
|
-
| SSHd
|
|
846
|
+
| Container | Environment Variable | Default |
|
|
847
|
+
|-----------|------------------------|-----------------------------|
|
|
848
|
+
| ryuk | `RYUK_CONTAINER_IMAGE` | `testcontainers/ryuk:0.3.2` |
|
|
849
|
+
| SSHd | `SSHD_CONTAINER_IMAGE` | `testcontainers/sshd:1.0.0` |
|
|
813
850
|
|
|
814
851
|
### ryuk
|
|
815
852
|
|
package/dist/bound-ports.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PortWithOptionalBinding } from "./port";
|
|
2
2
|
import { InspectResult } from "./docker/functions/container/inspect-container";
|
|
3
3
|
export declare class BoundPorts {
|
|
4
4
|
private readonly ports;
|
|
5
|
-
getBinding(port:
|
|
6
|
-
setBinding(key:
|
|
7
|
-
iterator(): Iterable<[
|
|
5
|
+
getBinding(port: number): number;
|
|
6
|
+
setBinding(key: number, value: number): void;
|
|
7
|
+
iterator(): Iterable<[number, number]>;
|
|
8
8
|
filter(ports: PortWithOptionalBinding[]): BoundPorts;
|
|
9
9
|
static fromInspectResult(inspectResult: InspectResult): BoundPorts;
|
|
10
10
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Dockerode from "dockerode";
|
|
2
|
-
import { Host } from "./types";
|
|
3
2
|
import "../testcontainers-properties-file";
|
|
4
3
|
declare type DockerClient = {
|
|
5
|
-
host:
|
|
4
|
+
host: string;
|
|
6
5
|
dockerode: Dockerode;
|
|
7
6
|
};
|
|
8
7
|
export declare const dockerClient: () => Promise<DockerClient>;
|
|
@@ -15,12 +15,7 @@ const demux_stream_1 = require("../demux-stream");
|
|
|
15
15
|
const docker_client_1 = require("../../docker-client");
|
|
16
16
|
const containerLogs = (container) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
try {
|
|
18
|
-
const
|
|
19
|
-
follow: true,
|
|
20
|
-
stdout: true,
|
|
21
|
-
stderr: true,
|
|
22
|
-
};
|
|
23
|
-
const stream = (yield container.logs(options));
|
|
18
|
+
const stream = (yield container.logs({ follow: true, stdout: true, stderr: true }));
|
|
24
19
|
stream.socket.unref();
|
|
25
20
|
return (0, demux_stream_1.demuxStream)((yield (0, docker_client_1.dockerClient)()).dockerode, stream);
|
|
26
21
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { DockerImageName } from "../../../docker-image-name";
|
|
2
2
|
import Dockerode from "dockerode";
|
|
3
3
|
import { PortWithOptionalBinding } from "../../../port";
|
|
4
|
-
import { BindMount,
|
|
4
|
+
import { BindMount, Environment, ExtraHost, HealthCheck, Labels, TmpFs, Ulimits } from "../../types";
|
|
5
5
|
export declare type CreateContainerOptions = {
|
|
6
6
|
imageName: DockerImageName;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
environment: Environment;
|
|
8
|
+
command: string[];
|
|
9
9
|
entrypoint?: string[];
|
|
10
10
|
bindMounts: BindMount[];
|
|
11
11
|
tmpFs: TmpFs;
|
|
12
12
|
exposedPorts: PortWithOptionalBinding[];
|
|
13
|
-
name?:
|
|
13
|
+
name?: string;
|
|
14
14
|
reusable: boolean;
|
|
15
15
|
labels?: Labels;
|
|
16
|
-
networkMode?:
|
|
16
|
+
networkMode?: string;
|
|
17
17
|
healthCheck?: HealthCheck;
|
|
18
18
|
useDefaultLogDriver: boolean;
|
|
19
19
|
privilegedMode: boolean;
|
|
@@ -22,12 +22,11 @@ const createContainer = (options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
22
22
|
name: options.name,
|
|
23
23
|
User: options.user,
|
|
24
24
|
Image: options.imageName.toString(),
|
|
25
|
-
Env:
|
|
25
|
+
Env: getEnvironment(options.environment),
|
|
26
26
|
ExposedPorts: getExposedPorts(options.exposedPorts),
|
|
27
|
-
Cmd: options.
|
|
27
|
+
Cmd: options.command,
|
|
28
28
|
Entrypoint: options.entrypoint,
|
|
29
29
|
Labels: (0, create_labels_1.createLabels)(options.reusable, options.imageName, options.labels),
|
|
30
|
-
// @ts-ignore
|
|
31
30
|
Healthcheck: getHealthCheck(options.healthCheck),
|
|
32
31
|
HostConfig: {
|
|
33
32
|
IpcMode: options.ipcMode,
|
|
@@ -51,7 +50,7 @@ const createContainer = (options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
51
50
|
}
|
|
52
51
|
});
|
|
53
52
|
exports.createContainer = createContainer;
|
|
54
|
-
const
|
|
53
|
+
const getEnvironment = (environment) => Object.entries(environment).reduce((dockerodeEnvironment, [key, value]) => [...dockerodeEnvironment, `${key}=${value}`], []);
|
|
55
54
|
const getExposedPorts = (exposedPorts) => {
|
|
56
55
|
const dockerodeExposedPorts = {};
|
|
57
56
|
for (const exposedPort of exposedPorts) {
|
|
@@ -75,14 +74,14 @@ const getPortBindings = (exposedPorts) => {
|
|
|
75
74
|
return dockerodePortBindings;
|
|
76
75
|
};
|
|
77
76
|
const getBindMounts = (bindMounts) => {
|
|
78
|
-
return bindMounts.map(({ source, target,
|
|
77
|
+
return bindMounts.map(({ source, target, mode }) => `${source}:${target}:${mode}`);
|
|
79
78
|
};
|
|
80
79
|
const getHealthCheck = (healthCheck) => {
|
|
81
80
|
if (healthCheck === undefined) {
|
|
82
81
|
return undefined;
|
|
83
82
|
}
|
|
84
83
|
return {
|
|
85
|
-
Test:
|
|
84
|
+
Test: healthCheck.test,
|
|
86
85
|
Interval: healthCheck.interval ? toNanos(healthCheck.interval) : 0,
|
|
87
86
|
Timeout: healthCheck.timeout ? toNanos(healthCheck.timeout) : 0,
|
|
88
87
|
Retries: healthCheck.retries || 0,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExecResult } from "../../types";
|
|
2
2
|
import Dockerode from "dockerode";
|
|
3
3
|
declare type ExecContainerOptions = {
|
|
4
4
|
tty: boolean;
|
|
5
5
|
stdin: boolean;
|
|
6
6
|
detach: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare const execContainer: (container: Dockerode.Container, command:
|
|
8
|
+
export declare const execContainer: (container: Dockerode.Container, command: string[], options: ExecContainerOptions, shouldLog?: boolean) => Promise<ExecResult>;
|
|
9
9
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import Dockerode from "dockerode";
|
|
2
|
-
|
|
3
|
-
export declare const getContainerById: (id: Id) => Promise<Dockerode.Container>;
|
|
2
|
+
export declare const getContainerById: (id: string) => Promise<Dockerode.Container>;
|
|
4
3
|
export declare const getContainerByHash: (hash: string) => Promise<Dockerode.Container | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HealthCheckStatus, Labels, NetworkSettings, Ports } from "../../types";
|
|
2
2
|
import Dockerode from "dockerode";
|
|
3
3
|
export declare type InspectResult = {
|
|
4
|
-
name:
|
|
4
|
+
name: string;
|
|
5
5
|
hostname: string;
|
|
6
6
|
ports: Ports;
|
|
7
7
|
healthCheckStatus: HealthCheckStatus;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DockerImageName } from "../../docker-image-name";
|
|
2
2
|
import { Labels } from "../types";
|
|
3
|
-
export declare const createLabels: (reusable: boolean, dockerImageName?: DockerImageName
|
|
3
|
+
export declare const createLabels: (reusable: boolean, dockerImageName?: DockerImageName, extraLabels?: Labels) => Labels;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DockerImageName } from "../../../docker-image-name";
|
|
2
2
|
import { PullPolicy } from "../../../pull-policy";
|
|
3
|
-
import { BuildArgs,
|
|
3
|
+
import { BuildArgs, RegistryConfig } from "../../types";
|
|
4
4
|
export declare type BuildImageOptions = {
|
|
5
5
|
imageName: DockerImageName;
|
|
6
|
-
context:
|
|
6
|
+
context: string;
|
|
7
7
|
dockerfileName: string;
|
|
8
8
|
buildArgs: BuildArgs;
|
|
9
9
|
pullPolicy: PullPolicy;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Command } from "../types";
|
|
2
1
|
import Dockerode from "dockerode";
|
|
3
|
-
export declare const runInContainer: (dockerode: Dockerode, image: string, command:
|
|
2
|
+
export declare const runInContainer: (dockerode: Dockerode, image: string, command: string[]) => Promise<string | undefined>;
|
package/dist/docker/types.d.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare type
|
|
5
|
-
|
|
6
|
-
[key in EnvKey]: EnvValue;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
export declare type Environment = {
|
|
5
|
+
[key in string]: string;
|
|
7
6
|
};
|
|
8
|
-
export declare type Dir = string;
|
|
9
7
|
export declare type BindMode = "rw" | "ro" | "z" | "Z";
|
|
10
8
|
export declare type BindMount = {
|
|
11
|
-
source:
|
|
12
|
-
target:
|
|
13
|
-
|
|
9
|
+
source: string;
|
|
10
|
+
target: string;
|
|
11
|
+
mode?: BindMode;
|
|
12
|
+
};
|
|
13
|
+
export declare type FileToCopy = {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type Content = string | Buffer | Readable;
|
|
18
|
+
export declare type ContentToCopy = {
|
|
19
|
+
content: Content;
|
|
20
|
+
target: string;
|
|
14
21
|
};
|
|
15
22
|
export declare type TmpFs = {
|
|
16
|
-
[dir in
|
|
23
|
+
[dir in string]: string;
|
|
17
24
|
};
|
|
18
25
|
export declare type Ulimits = {
|
|
19
26
|
[name: string]: {
|
|
@@ -22,18 +29,16 @@ export declare type Ulimits = {
|
|
|
22
29
|
};
|
|
23
30
|
};
|
|
24
31
|
export declare type HealthCheck = {
|
|
25
|
-
test: string;
|
|
32
|
+
test: ["CMD-SHELL", string] | ["CMD", ...string[]];
|
|
26
33
|
interval?: number;
|
|
27
34
|
timeout?: number;
|
|
28
35
|
retries?: number;
|
|
29
36
|
startPeriod?: number;
|
|
30
37
|
};
|
|
31
38
|
export declare type ExtraHost = {
|
|
32
|
-
host:
|
|
39
|
+
host: string;
|
|
33
40
|
ipAddress: string;
|
|
34
41
|
};
|
|
35
|
-
export declare type NetworkMode = string;
|
|
36
|
-
export declare type ContainerName = string;
|
|
37
42
|
export declare type Labels = {
|
|
38
43
|
[key: string]: string;
|
|
39
44
|
};
|
|
@@ -52,16 +57,12 @@ export declare type RegistryConfig = {
|
|
|
52
57
|
password: string;
|
|
53
58
|
};
|
|
54
59
|
};
|
|
55
|
-
export declare type BuildContext = string;
|
|
56
60
|
export declare type BuildArgs = {
|
|
57
|
-
[key in
|
|
61
|
+
[key in string]: string;
|
|
58
62
|
};
|
|
59
|
-
export declare type StreamOutput = string;
|
|
60
|
-
export declare type ExitCode = number;
|
|
61
|
-
export declare type Command = string;
|
|
62
63
|
export declare type ExecResult = {
|
|
63
|
-
output:
|
|
64
|
-
exitCode:
|
|
64
|
+
output: string;
|
|
65
|
+
exitCode: number;
|
|
65
66
|
};
|
|
66
67
|
export declare type HealthCheckStatus = "none" | "starting" | "unhealthy" | "healthy";
|
|
67
68
|
export declare type NetworkSettings = {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IDockerComposeOptions } from "./docker-compose";
|
|
2
2
|
import { DockerComposeOptions } from "./docker-compose-options";
|
|
3
|
-
export declare const defaultDockerComposeOptions: ({
|
|
3
|
+
export declare const defaultDockerComposeOptions: ({ environment, ...options }: DockerComposeOptions) => Partial<IDockerComposeOptions>;
|
|
@@ -13,14 +13,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.defaultDockerComposeOptions = void 0;
|
|
15
15
|
const defaultDockerComposeOptions = (_a) => {
|
|
16
|
-
var {
|
|
16
|
+
var { environment = {} } = _a, options = __rest(_a, ["environment"]);
|
|
17
17
|
return {
|
|
18
18
|
log: false,
|
|
19
19
|
cwd: options.filePath,
|
|
20
20
|
config: options.files,
|
|
21
21
|
composeOptions: options.composeOptions,
|
|
22
22
|
commandOptions: options.commandOptions,
|
|
23
|
-
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }),
|
|
23
|
+
env: Object.assign(Object.assign(Object.assign({}, process.env), { COMPOSE_PROJECT_NAME: options.projectName }), environment),
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
exports.defaultDockerComposeOptions = defaultDockerComposeOptions;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Environment } from "../docker/types";
|
|
2
2
|
export declare type DockerComposeOptions = {
|
|
3
3
|
filePath: string;
|
|
4
4
|
files: string | string[];
|
|
5
5
|
projectName: string;
|
|
6
6
|
commandOptions?: string[];
|
|
7
7
|
composeOptions?: string[];
|
|
8
|
-
|
|
8
|
+
environment?: Environment;
|
|
9
9
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DockerComposeOptions } from "../docker-compose-options";
|
|
2
|
-
export declare const dockerComposeUp: (options: DockerComposeOptions, services?: string
|
|
2
|
+
export declare const dockerComposeUp: (options: DockerComposeOptions, services?: Array<string>) => Promise<void>;
|