presidium 4.8.2 → 4.9.1

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/Docker.js CHANGED
@@ -16,6 +16,7 @@ const { spawn } = require('child_process')
16
16
  const Readable = require('./Readable')
17
17
  const HTTP = require('./HTTP')
18
18
  const querystring = require('querystring')
19
+ const Archive = require('./internal/Archive')
19
20
  const split = require('./internal/split')
20
21
  const join = require('./internal/join')
21
22
  const isArray = require('./internal/isArray')
@@ -47,9 +48,8 @@ const handleDockerHTTPResponse = require('./internal/handleDockerHTTPResponse')
47
48
  *
48
49
  * System dependencies:
49
50
  * * `docker`
50
- * * `tar`
51
51
  *
52
- * Note: the Presidium Docker client connects to the Docker socket `/var/run/docker.sock`. For security purposes, please avoid exposing any code using the Presidium Docker client to the internet, see [How would an attacker gain access to the host machine from within a Docker container?](https://www.google.com/search?hl=en&q=how+would+an+attacker+gain+access+to+the+host+machine+from+within+a+docker+container&ia=web).
52
+ * Note: the Presidium Docker client connects to the Docker socket at `/var/run/docker.sock`. For security purposes, please avoid exposing code running the Presidium Docker client to the internet.
53
53
  */
54
54
  class Docker {
55
55
  constructor(options = {}) {
@@ -82,7 +82,7 @@ class Docker {
82
82
  * Validates credentials for a Docker container registry. If available, gets an identity token for accessing the registry without password.
83
83
  *
84
84
  * Arguments:
85
- * * `options` - address used for inter-manager communication that is also advertised to other nodes.
85
+ * * `options` - address for inter-manager communication and discovery.
86
86
  * * `username` - authentication credentials.
87
87
  * * `password` - authentication credentials.
88
88
  * * `email` - authentication credentials.
@@ -91,7 +91,7 @@ class Docker {
91
91
  * Return:
92
92
  * * `data`
93
93
  * * `Status` - the status message of the authentication
94
- * * `IdentityToken` - a token used to authenticate the user in place of a username and password.
94
+ * * `IdentityToken` - a token for authenticating users in place of username and password.
95
95
  *
96
96
  * ```javascript
97
97
  * const docker = new Docker()
@@ -155,7 +155,7 @@ class Docker {
155
155
  * * `Created` - the date and time at which the image was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
156
156
  * * `Size` - the total size in bytes of the image including all layers that the image is composed of.
157
157
  * * `SharedSize` - total size of image layers that are shared between the image and other images. `-1` indicates that this value has not been calculated.
158
- * * `Labels` - object of user-defined key/value metadata.
158
+ * * `Labels` - object of key-value metadata.
159
159
  * * `Containers` - number of containers using this image. Includes both stopped and running containers. `-1` indicates that this value has not been calculated.
160
160
  * * `Manifests` - list of [image manifests](https://docs.docker.com/reference/cli/docker/manifest/) available in the image. Warning: `Manifests` is experimental and may change at any time without any backward compatibility.
161
161
  * * `Descriptor` - an object containing digest, media type, and size for the image, as defined in the [OCI Content Descriptors Specification](https://github.com/opencontainers/image-spec/blob/v1.0.1/descriptor.md).
@@ -217,20 +217,20 @@ class Docker {
217
217
  * * `data`
218
218
  * * `Id` - the Docker container ID
219
219
  * * `Names` - the names associated with the Docker container.
220
- * * `Image` - the name or ID of the image used to create the Docker container.
221
- * * `ImageID` - the ID of the image used to create the Docker container.
222
- * * `ImageManifestDescriptor` - an object containing digest, media type, and size for the image used to create the Docker container, as defined in the [OCI Content Descriptors Specification](https://github.com/opencontainers/image-spec/blob/v1.0.1/descriptor.md).
220
+ * * `Image` - the name or ID of the image of the Docker container.
221
+ * * `ImageID` - the ID of the image of the Docker container.
222
+ * * `ImageManifestDescriptor` - an object containing digest, media type, and size for the image of the Docker container, as defined in the [OCI Content Descriptors Specification](https://github.com/opencontainers/image-spec/blob/v1.0.1/descriptor.md).
223
223
  * * `Command` - the command to run when starting the Docker container.
224
224
  * * `Created` - the date and time at which the image was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
225
225
  * * `Ports` - port-mappings for the Docker container.
226
226
  * * `SizeRw` - the size of files that have been created or changed by the Docker container.
227
- * * `SizeRootFs` - the total size of all files in the read-only layers of the image that are used by the Docker container.
228
- * * `Labels` - object of user-defined key/value metadata.
227
+ * * `SizeRootFs` - the total size of all files in the read-only layers of the image of the Docker container.
228
+ * * `Labels` - object of key-value metadata.
229
229
  * * `State` - the state of the Docker container.
230
230
  * * `Status` - additional human-readable status of the Docker container, e.g. `'Exit 0'`.
231
231
  * * `HostConfig` - summary of host-specific runtime information of the Docker container.
232
232
  * * `NetworkSettings` - summary of the Docker container's network settings.
233
- * * `Mounts` - list of mounts used by the Docker container.
233
+ * * `Mounts` - list of mounts of the Docker container.
234
234
  * * `Health` - summary of the Docker container's health status.
235
235
  *
236
236
  * ```javascript
@@ -281,7 +281,7 @@ class Docker {
281
281
  * * `password` - authentication credentials.
282
282
  * * `email` - authentication credentials.
283
283
  * * `serveraddress` - domain or IP of the registry server.
284
- * * `identitytoken` - a token used to authenticate the user in place of a username and password.
284
+ * * `IdentityToken` - a token for authenticating users in place of username and password.
285
285
  *
286
286
  * Return:
287
287
  * * `dataStream` - a readable stream of the progress of the Docker `pullImage` operation.
@@ -408,54 +408,12 @@ class Docker {
408
408
  * * [Dockerfile](https://docs.docker.com/engine/reference/builder/)
409
409
  */
410
410
  async buildImage(path, options = {}) {
411
- path = path.endsWith('/') ? path : `${path}/`
412
-
413
- const archiveDir = `presidium-Docker-buildImage-tmp-${uniqid()}`
414
-
415
- await fs.promises.mkdir(archiveDir, { recursive: true })
416
-
417
- const archiveFilename = `${archiveDir}/archive.tar`
418
-
419
- const cmdArgs = []
420
-
421
- cmdArgs.push(`--exclude=${archiveDir}`)
422
- if (options.ignore) {
423
- for (const pattern of options.ignore) {
424
- cmdArgs.push(`--exclude=${pattern}`)
425
- }
426
- }
427
-
428
- cmdArgs.push('-cf', archiveFilename, '-C', path, '.')
429
-
430
- const cmd = spawn('tar', cmdArgs, { stdio: 'inherit' })
431
-
432
- await new Promise(resolve => {
433
- cmd.on('close', resolve)
411
+ const pack = Archive.tar(path, {
412
+ base: options.archive,
413
+ ignore: options.ignore ?? ['node_modules', '.git', '.nyc_output'],
434
414
  })
435
415
 
436
- if (options.archive) {
437
- for (const filename in options.archive) {
438
- await fs.promises.writeFile(
439
- `${archiveDir}/${filename}`, options.archive[filename]
440
- )
441
-
442
- const cmdArgs = [
443
- '-rf',
444
- archiveFilename,
445
- `--directory=${archiveDir}`,
446
- ]
447
-
448
- cmdArgs.push(filename)
449
-
450
- const cmd = spawn('tar', cmdArgs, { stdio: 'inherit' })
451
-
452
- await new Promise(resolve => {
453
- cmd.on('close', resolve)
454
- })
455
- }
456
- }
457
-
458
- const archive = fs.createReadStream(archiveFilename).pipe(zlib.createGzip())
416
+ const compressed = pack.pipe(zlib.createGzip())
459
417
 
460
418
  const response = await this.http.post(`/build?${querystring.stringify({
461
419
  dockerfile: options.archiveDockerfile ?? 'Dockerfile',
@@ -463,18 +421,13 @@ class Docker {
463
421
  forcerm: true,
464
422
  platform: options.platform ?? '',
465
423
  })}`, {
466
- body: archive,
424
+ body: compressed,
467
425
  headers: {
468
426
  'Content-Type': 'application/x-tar',
469
427
  },
470
428
  })
471
429
 
472
430
  const dataStream = await handleDockerHTTPResponse(response, { stream: true })
473
-
474
- dataStream.on('end', async () => {
475
- await fs.promises.rm(archiveDir, { recursive: true })
476
- })
477
-
478
431
  return dataStream
479
432
  }
480
433
 
@@ -508,7 +461,7 @@ class Docker {
508
461
  * * `password` - authentication credentials.
509
462
  * * `email` - authentication credentials.
510
463
  * * `serveraddress` - domain or IP of the registry server.
511
- * * `identitytoken` - a token used to authenticate the user in place of a username and password.
464
+ * * `IdentityToken` - a token for authenticating users in place of username and password.
512
465
  *
513
466
  * Return:
514
467
  * * `dataStream` - a readable stream of the progress of the Docker `pushImage` operation.
@@ -609,13 +562,13 @@ class Docker {
609
562
  * * `Comment` - optional message that was set when committing or importing the image.
610
563
  * * `Created` - the date and time at which the image was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
611
564
  * * `Author` - the name of the author that was specified when committing the image.
612
- * * `Config` - the configuration of the image. `Config` fields are used as defaults when starting a container from an image.
565
+ * * `Config` - the configuration of the image. `Config` fields are the defaults when starting a container from an image.
613
566
  * * `Architecture` - the CPU architecture that the image runs on.
614
567
  * * `Variant` - a CPU architecture variant.
615
568
  * * `Os` - the operating system that the image is built to run on.
616
569
  * * `OsVersion` - the version of the operating system that the image is built to run on.
617
570
  * * `Size` - the total size in bytes of the image including all layers that the image is composed of.
618
- * * `GraphDriver` - information about the storage driver that stores the filesystem used by the Docker container and the image.
571
+ * * `GraphDriver` - information about the storage driver that stores the filesystem of the Docker container and the image.
619
572
  * * `RootFS` - information about the image's RootFS, including the layer IDs.
620
573
  * * `Metadata` - additional metadata of the image in the local cache. This information is not part of the image itself.
621
574
  *
@@ -679,12 +632,12 @@ class Docker {
679
632
  * }) -> data Promise<Array<{ Untagged: string }|{ Deleted: string }>>
680
633
  * ```
681
634
  *
682
- * Removes a Docker image and any untagged parent images that were referenced by the Docker image from the server. Docker images can't be removed if they have descendant images, are being used by a running container, or are being used by a build.
635
+ * Removes a Docker image and any untagged parent images that were referenced by the Docker image from the server. Docker images can't be removed if they have descendant images, have a running container, or are being referenced by a build.
683
636
  *
684
637
  * Arguments:
685
638
  * * `image` - the name or ID of the image to remove.
686
639
  * * `options`
687
- * * `force` - if `true`, removes the image even if it is being used by stopped containers or has other tags. If `false`, the operation will error if the image is being used by stopped containers. Defaults to `false`.
640
+ * * `force` - if `true`, removes the image even if it is referenced by stopped containers or has other tags. If `false`, the operation will error if the image is referenced by stopped containers. Defaults to `false`.
688
641
  * * `noprune` - if `true`, the operation will not delete untagged parent images. If `false`, the operation will delete untagged parent images. Defaults to `false`.
689
642
  *
690
643
  * Return:
@@ -759,7 +712,7 @@ class Docker {
759
712
  * * `image` - the name and tag of the image.
760
713
  * * `rm` - automatically remove the Docker container when it exits.
761
714
  * * `restart` - the restart policy for the Docker container.
762
- * * `logDriver` - the logging driver used for the Docker container.
715
+ * * `logDriver` - the logging driver of the Docker container.
763
716
  * * `logDriverOptions` - driver-specific configuration options for the logging driver.
764
717
  * * `publish` - object of mappings of host ports to container ports with optional protocols.
765
718
  * * `healthCmd` - a command that checks the health of the Docker container. The health check fails if the command errors. The command is run inside the Docker container.
@@ -803,7 +756,7 @@ class Docker {
803
756
  * * `image` - mounts a Docker image.
804
757
  * * `npipe` - mounts a named pipe from the host into the Docker container.
805
758
  * * `tmpfs` - create a tmpfs with the given options. The `source` cannot be specified with mount type `tmpfs`.
806
- * * `volume` - creates a volume with the given name and options or uses a pre-existing volume with the same name and options. The volume persists when the Docker container is removed.
759
+ * * `volume` - creates or references a volume with the given name and options. The volume persists when the Docker container is removed.
807
760
  *
808
761
  * ```javascript
809
762
  * const docker = new Docker()
@@ -1038,7 +991,7 @@ class Docker {
1038
991
  * * `image` - the name and tag of the image.
1039
992
  * * `rm` - automatically remove the Docker container when it exits.
1040
993
  * * `restart` - the restart policy for the Docker container.
1041
- * * `logDriver` - the logging driver used for the Docker container.
994
+ * * `logDriver` - the logging driver of the Docker container.
1042
995
  * * `logDriverOptions` - driver-specific configuration options for the logging driver.
1043
996
  * * `publish` - object of mappings of host ports to container ports with optional protocols.
1044
997
  * * `healthCmd` - a command that checks the health of the Docker container. The health check fails if the command errors. The command is run inside the Docker container.
@@ -1080,7 +1033,7 @@ class Docker {
1080
1033
  * * `image` - mounts a Docker image.
1081
1034
  * * `npipe` - mounts a named pipe from the host into the Docker container.
1082
1035
  * * `tmpfs` - create a tmpfs with the given options. The `source` cannot be specified with mount type `tmpfs`.
1083
- * * `volume` - creates a volume with the given name and options or uses a pre-existing volume with the same name and options. The volume persists when the Docker container is removed.
1036
+ * * `volume` - creates or references a volume with the given name and options. The volume persists when the Docker container is removed.
1084
1037
  *
1085
1038
  * ```javascript
1086
1039
  * const docker = new Docker()
@@ -1335,16 +1288,16 @@ class Docker {
1335
1288
  * * `Id` - the ID of the Docker container.
1336
1289
  * * `Created` - the date and time at which the Docker container was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
1337
1290
  * * `Path` - the path to the command run by the Docker container.
1338
- * * `Args` - the arguments to the command being run by the Docker container.
1291
+ * * `Args` - the arguments to the command run by the Docker container.
1339
1292
  * * `State` - `DockerDocs.ContainerState` stores the Docker container's running state.
1340
1293
  * * `Image` - the ID (digest) of the image that the Docker container was created from.
1341
1294
  * * `ResolveConfPath` - the location of `/etc/resolve.conf` generated for the Docker container on the host.
1342
1295
  * * `HostnamePath` - the location of `/etc/hostname` generated for the Docker container on the host.
1343
1296
  * * `HostsPath` - the location of `/etc/hosts` generated for the Docker container on the host.
1344
- * * `LogPath` - the location of the file used to buffer the Docker container's logs.
1297
+ * * `LogPath` - the location of the file that buffers the Docker container's logs.
1345
1298
  * * `Name` - the name associated with the Docker container.
1346
1299
  * * `RestartCount` - the number of times the Docker container was restarted since it was created or since the Docker daemon was started.
1347
- * * `Driver` - the storage-driver used for the Docker container's filesystem.
1300
+ * * `Driver` - the storage-driver of the Docker container's filesystem.
1348
1301
  * * `Platform` - the platform (operating system) for which the Docker container was created.
1349
1302
  * * `ImageManifestDescriptor` - an object containing digest, media type, and size for the image from which the Docker container was created, as defined in the [OCI Content Descriptors Specification](https://github.com/opencontainers/image-spec/blob/v1.0.1/descriptor.md).
1350
1303
  * * `MountLabel` - the SELinux mount label set for the Docker container.
@@ -1352,11 +1305,11 @@ class Docker {
1352
1305
  * * `AppArmorProfile` - the AppArmor profile set for the Docker container.
1353
1306
  * * `ExecIDs` - the IDs of exec instances that are running in the Docker container.
1354
1307
  * * `HostConfig` - host configuration for the Docker container.
1355
- * * `GraphDriver` - information about the storage driver that stores the filesystem used by the Docker container and the image.
1356
- * * `Storage` - information about the storage used by the Docker container.
1308
+ * * `GraphDriver` - information about the storage driver that stores the filesystem of the Docker container and the image.
1309
+ * * `Storage` - information about the storage of the Docker container.
1357
1310
  * * `SizeRw` - the size of files that have been created or changed by the Docker container.
1358
- * * `SizeRootFs` - the total size of all files in the read-only layers of the image that are used by the Docker container.
1359
- * * `Mounts` - list of mounts used by the Docker container.
1311
+ * * `SizeRootFs` - the total size of all files in the read-only layers of the image of the Docker container.
1312
+ * * `Mounts` - list of mounts of the Docker container.
1360
1313
  * * `Config` - the configuration of the Docker container.
1361
1314
  * * `NetworkSettings` - summary of the Docker container's network settings.
1362
1315
  *
@@ -1423,8 +1376,8 @@ class Docker {
1423
1376
  * * `DefaultAddrPool` - the default subnet pools for global scope networks of the Docker swarm.
1424
1377
  * * `SubnetSize` - the subnet size of the networks created from the default address pool.
1425
1378
  * * `JoinTokens` - tokens for worker and manager nodes to join the Docker swarm.
1426
- * * `Worker` - the token that worker nodes can use to join the Docker swarm.
1427
- * * `Manager` - the token that manager nodes can use to join the Docker swarm.
1379
+ * * `Worker` - the token for worker nodes to join the Docker swarm.
1380
+ * * `Manager` - the token for manager nodes to join the Docker swarm.
1428
1381
  *
1429
1382
  * ```javascript
1430
1383
  * const docker = new Docker()
@@ -1451,7 +1404,7 @@ class Docker {
1451
1404
  * Initializes a new Docker swarm.
1452
1405
  *
1453
1406
  * Arguments:
1454
- * * `address` - address used for inter-manager communication that is also advertised to other nodes.
1407
+ * * `address` - address for inter-manager communication and discovery.
1455
1408
  *
1456
1409
  * Return:
1457
1410
  * * `nodeId` - the ID of the current Docker swarm manager node.
@@ -1492,9 +1445,9 @@ class Docker {
1492
1445
  * Joins the current node (server) to a Docker swarm.
1493
1446
  *
1494
1447
  * Arguments:
1495
- * * `address` - address used for inter-manager communication that is also advertised to other nodes.
1448
+ * * `address` - address for inter-manager communication and discovery.
1496
1449
  * * `options`
1497
- * * `RemoteAddrs` - address or interface for data path traffic. Used to separate data traffic from management traffic.
1450
+ * * `RemoteAddrs` - address or interface for data path traffic. Separates data traffic from management traffic.
1498
1451
  * * `JoinToken` - worker or manager token for joining the swarm.
1499
1452
  *
1500
1453
  * Return:
@@ -1624,11 +1577,11 @@ class Docker {
1624
1577
  * Arguments:
1625
1578
  * * `service` - the Docker service name.
1626
1579
  * * `options`
1627
- * * `image` - the Docker image that will be used by the Docker service.
1580
+ * * `image` - the Docker image of the Docker service.
1628
1581
  * * `replicas` - the number of containers that the Docker service will run across all nodes of the Docker swarm. If `replicas` is set to 'global', the Docker service will run containers on each node of the Docker swarm.
1629
1582
  * * `restart` - the restart policy for the Docker service.
1630
1583
  * * `restartDelay` - the delay between restarts for the Docker service.
1631
- * * `logDriver` - the logging driver used for the Docker service.
1584
+ * * `logDriver` - the logging driver of the Docker service.
1632
1585
  * * `logDriverOptions` - driver-specific configuration options for the logging driver.
1633
1586
  * * `publish` - object of mappings of host ports to Docker service ports with optional protocols.
1634
1587
  * * `healthCmd` - a command that checks the health of the Docker service. The health check fails if the command errors. The command is run inside each Docker container of the Docker service.
@@ -1659,7 +1612,7 @@ class Docker {
1659
1612
  * * `password` - authentication credentials.
1660
1613
  * * `email` - authentication credentials.
1661
1614
  * * `serveraddress` - domain or IP of the registry server.
1662
- * * `identitytoken` - a token used to authenticate the user in place of a username and password.
1615
+ * * `IdentityToken` - a token for authenticating users in place of username and password.
1663
1616
  *
1664
1617
  * Return:
1665
1618
  * * `data`
@@ -1906,7 +1859,7 @@ class Docker {
1906
1859
  * * `replicas` - the number of containers that the Docker service will run across all nodes of the Docker swarm. If `replicas` is set to 'global', the Docker service will run containers on each node of the Docker swarm.
1907
1860
  * * `restart` - the restart policy for the Docker service.
1908
1861
  * * `restartDelay` - the delay between restarts for the Docker service.
1909
- * * `logDriver` - the logging driver used for the Docker service.
1862
+ * * `logDriver` - the logging driver of the Docker service.
1910
1863
  * * `logDriverOptions` - driver-specific configuration options for the logging driver.
1911
1864
  * * `publish` - object of mappings of host ports to Docker service ports with optional protocols.
1912
1865
  * * `healthCmd` - a command that checks the health of the Docker service. The health check fails if the command errors. The command is run inside each Docker container of the Docker service.
@@ -2268,12 +2221,12 @@ class Docker {
2268
2221
  * * `CreatedAt` - the date and time at which the task was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
2269
2222
  * * `UpdatedAt` - the date and time at which the task was updated as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
2270
2223
  * * `Name` - the name of the task.
2271
- * * `Labels` - object of user-defined key/value metadata.
2224
+ * * `Labels` - object of key-value metadata.
2272
2225
  * * `Spec` - the task configuration.
2273
2226
  * * `ServiceID` - the ID of the Docker service that the task belongs to.
2274
- * * `Slot` - used by the orchestrator for scheduling purposes.
2227
+ * * `Slot` - for scheduling purposes.
2275
2228
  * * `NodeID` - the ID of the node that the task is on.
2276
- * * `AssignedGenericResources` - user-defined resources.
2229
+ * * `AssignedGenericResources` - resources.
2277
2230
  * * `Status` - the status of the task.
2278
2231
  * * `DesiredState` - the desired status of the task.
2279
2232
  * * `JobIteration` - the version number of the task.
@@ -2433,7 +2386,7 @@ class Docker {
2433
2386
  * }>
2434
2387
  * ```
2435
2388
  *
2436
- * Prunes Docker images. Deletes unused Docker images from the server.
2389
+ * Prunes Docker images. Deletes Docker images without containers from the server.
2437
2390
  *
2438
2391
  * Arguments:
2439
2392
  * * (none)
@@ -2501,7 +2454,7 @@ class Docker {
2501
2454
  * }>
2502
2455
  * ```
2503
2456
  *
2504
- * Prunes Docker volumes. Deletes unused volumes from the server.
2457
+ * Prunes Docker volumes. Deletes volumes without containers from the server.
2505
2458
  *
2506
2459
  * Arguments:
2507
2460
  * * (none)
@@ -2578,7 +2531,7 @@ class Docker {
2578
2531
  * Arguments:
2579
2532
  * * `options`
2580
2533
  * * `name` - the name of the network to create.
2581
- * * `driver` - the name of the network driver plugin to use.
2534
+ * * `driver` - the name of the network driver plugin.
2582
2535
  * * `ingress` - if `true`, creates an ingress network. The ingress network is the network that provides the routing-mesh in swarm mode. If `false`, does not create an ingress network.
2583
2536
  * * `subnet` - the subnet of the network.
2584
2537
  * * `gateway` - the gateway of the network.
@@ -2668,7 +2621,7 @@ class Docker {
2668
2621
  * * `Id` - the network ID.
2669
2622
  * * `Created` - the date and time at which the network was created as seconds since EPOCH (January 1, 1970 at midnight UTC/GMT).
2670
2623
  * * `Scope` - the level at which the network exists.
2671
- * * `Driver` - the name of the driver used to create the network.
2624
+ * * `Driver` - the name of the driver of the network.
2672
2625
  * * `EnableIPv4` - whether the network was created with IPv4 enabled.
2673
2626
  * * `EnableIPv6` - whether the network was created with IPv6 enabled.
2674
2627
  * * `IPAM` - the network's IPAM configuration.
@@ -2676,9 +2629,9 @@ class Docker {
2676
2629
  * * `Attachable` - whether the network is manually attachable by regular containers from worker nodes in a Docker swarm.
2677
2630
  * * `Ingress` - whether the network is providing the routing-mesh for a Docker swarm.
2678
2631
  * * `ConfigFrom` - the config-only network source that provides the configuration for the network.
2679
- * * `ConfigOnly` - whether the network is a config-only network. Config-only networks are placeholder networks for network configurations to be used by other networks. Config-only networks cannot be used directly to run containers or services.
2680
- * * `Options` - network-specific options used when creating the network.
2681
- * * `Labels` - object of user-defined key/value metadata.
2632
+ * * `ConfigOnly` - whether the network is a config-only network. Config-only networks are placeholder networks for network configurations for other networks. Containers and services cannot attach to config-only networks.
2633
+ * * `Options` - network-specific options for creating the network.
2634
+ * * `Labels` - object of key-value metadata.
2682
2635
  * * `Peers` - list of peer nodes for the network. `Peers` is only present if the network is an overlay network.
2683
2636
  *
2684
2637
  * ```javascript
package/HTTP.js CHANGED
@@ -57,6 +57,10 @@ const httpConfigure = require('./internal/httpConfigure')
57
57
  */
58
58
  class HTTP {
59
59
  constructor(baseUrl, requestOptions = {}) {
60
+ if (typeof baseUrl == "string" && !baseUrl.startsWith("http")) {
61
+ baseUrl = `http://${baseUrl}`
62
+ }
63
+
60
64
  if (
61
65
  typeof baseUrl == 'string'
62
66
  || typeof baseUrl?.toString == 'function'
@@ -0,0 +1,118 @@
1
+ require('rubico/global')
2
+ const tarStream = require('tar-stream')
3
+ const fs = require('fs')
4
+ const walk = require('./walk')
5
+
6
+ /**
7
+ * @name Archive
8
+ */
9
+ const Archive = {
10
+
11
+ /**
12
+ * @name tar
13
+ *
14
+ * @docs
15
+ * ```coffeescript [specscript]
16
+ * module tar 'https://github.com/mafintosh/tar-stream'
17
+ *
18
+ * Archive.tar(path string, options {
19
+ * ignore: Array<string>,
20
+ * base: Object<string>,
21
+ * }) -> pack tar.Pack
22
+ * ```
23
+ *
24
+ * Bundle multiple files and directories from a parent directory into a tarball.
25
+ *
26
+ * Arguments:
27
+ * * `path` - the path to the parent directory which contains the files and directories to bundle.
28
+ * * `options`
29
+ * * `ignore` - filepaths, filenames, or patterns to ignore.
30
+ */
31
+ tar(path, options) {
32
+ path = path.endsWith('/') ? path : `${path}/`
33
+ const ignore = get(options, 'ignore')
34
+ const pack = tarStream.pack()
35
+
36
+ pipe(
37
+ walk(path),
38
+
39
+ filter(path => {
40
+ for (const part of ignore) {
41
+ if (path.includes(part)) {
42
+ return false
43
+ }
44
+ }
45
+ return true
46
+ }),
47
+
48
+ reduce(async (pack, filepath) => {
49
+ const stats = await pipe(filepath, [
50
+ fs.promises.stat,
51
+ pick(['size', 'mode', 'mtime', 'uid', 'gid']),
52
+ ])
53
+
54
+ const entry = pack.entry({ ...stats, name: filepath.replace(path, '') })
55
+
56
+ const fileStream = fs.createReadStream(filepath)
57
+
58
+ fileStream.pipe(entry)
59
+
60
+ await new Promise(resolve => {
61
+ fileStream.on('end', resolve)
62
+ })
63
+
64
+ return pack
65
+ }, pack),
66
+
67
+ tap(pack => {
68
+ const base = options.base ?? {}
69
+ for (const filename in base) {
70
+ pack.entry({ name: filename }, base[filename])
71
+ }
72
+ pack.finalize()
73
+ }),
74
+ )
75
+
76
+ return pack
77
+ },
78
+
79
+ /**
80
+ * @name untar
81
+ *
82
+ * @docs
83
+ * ```coffeescript [specscript]
84
+ * module tar 'https://github.com/mafintosh/tar-stream'
85
+ * module Readable 'https://presidium.services/Readable'
86
+ *
87
+ * Archive.untar(pack tar.Pack) ->
88
+ * contentMap Promise<Map<(filepath string)=>(content Readable)> >
89
+ * ```
90
+ *
91
+ * Extract a tarball into a map of file paths to content streams.
92
+ *
93
+ * Arguments:
94
+ * * `pack` - a tarball represented by the `tar.Pack` type. Returned by the [tar](#tar) method.
95
+ */
96
+ untar(pack) {
97
+ const extractStream = tarStream.extract()
98
+ const extracted = new Map()
99
+ return new Promise((resolve, reject) => {
100
+ extractStream.on('entry', (header, stream, next) => {
101
+ stream.header = header
102
+ extracted.set(header.name, stream)
103
+ next()
104
+ })
105
+
106
+ extractStream.on('finish', () => {
107
+ resolve(extracted)
108
+ })
109
+
110
+ extractStream.on('error', reject)
111
+
112
+ pack.pipe(extractStream)
113
+ })
114
+ },
115
+
116
+ }
117
+
118
+ module.exports = Archive
@@ -0,0 +1,78 @@
1
+ const assert = require('assert')
2
+ const stream = require('stream')
3
+ const fs = require('fs/promises')
4
+ const Test = require('thunk-test')
5
+ const Archive = require('./Archive')
6
+ const resolvePath = require('./resolvePath')
7
+ const map = require('rubico/map')
8
+ const reduce = require('rubico/reduce')
9
+ const Readable = require('../Readable')
10
+
11
+ const test = new Test('Archive', async function integration() {
12
+
13
+ {
14
+ const pack = await Archive.tar(__dirname, {
15
+ ignore: ['Dockerfile', 'node_modules', '.git', '.nyc_output'],
16
+ })
17
+ const extracted = await Archive.untar(pack)
18
+ assert(extracted.size > 0)
19
+ for (const [path, entry] of extracted) {
20
+ assert('header' in entry)
21
+ assert(!path.startsWith('/'))
22
+ assert.equal(typeof path, 'string')
23
+ assert.equal(typeof entry[Symbol.asyncIterator], 'function')
24
+ assert(entry.readable)
25
+ }
26
+ }
27
+
28
+ {
29
+ const base = {
30
+ Dockerfile: 'FROM node:15-alpine'
31
+ }
32
+ const ignore = ['fixtures', 'tmp', 'google-chrome-for-testing']
33
+ const pack = await Archive.tar(__dirname, { ignore, base })
34
+ const extracted = await Archive.untar(pack)
35
+ const dir = await fs.readdir(__dirname)
36
+ .then(filter(filepath => {
37
+ for (const part of ignore) {
38
+ if (filepath.includes(part)) {
39
+ return false
40
+ }
41
+ }
42
+ return true
43
+ }))
44
+ const extractedKeys = [...extracted.keys()]
45
+ assert.equal(extracted.size, dir.length + 1) // extra Dockerfile
46
+ assert(extracted.has('Dockerfile'))
47
+ assert.equal(
48
+ await reduce(extracted.get('Dockerfile'), (a, b) => a + b, ''),
49
+ 'FROM node:15-alpine'
50
+ )
51
+ }
52
+
53
+ {
54
+ const base = {
55
+ Dockerfile: 'FROM busybox:1.32',
56
+ '.aws/credentials': '[presidium]\naccessKeyId\nsecretAccessKey',
57
+ }
58
+ const pack = await Archive.tar(`${__dirname}/`, {
59
+ ignore: ['hashJSON.js'],
60
+ base,
61
+ })
62
+ const extracted = await Archive.untar(pack)
63
+ assert(extracted.size > 0)
64
+ assert(extracted.has('Dockerfile'))
65
+ assert(extracted.has('.aws/credentials'))
66
+ assert.equal(
67
+ await reduce(extracted.get('Dockerfile'), (a, b) => a + b, ''),
68
+ 'FROM busybox:1.32'
69
+ )
70
+ }
71
+
72
+ }).case()
73
+
74
+ if (process.argv[1] == __filename) {
75
+ test()
76
+ }
77
+
78
+ module.exports = test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "4.8.2",
3
+ "version": "4.9.1",
4
4
  "description": "The Presidium library.",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",
@@ -71,6 +71,7 @@
71
71
  "presidium-db-client-server": ">=0.6.6",
72
72
  "presidium-websocket": ">=4.2.2",
73
73
  "rubico": "^2.21.0",
74
+ "tar-stream": "^3.2.2",
74
75
  "uniqid": "^5.4.0"
75
76
  },
76
77
  "scripts": {