@lakutata/docker 3.0.0-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/LICENSE +23 -0
- package/README.md +309 -0
- package/THIRD_PARTY_NOTICES.md +299 -0
- package/dist/cjs/client/BuildContext.d.ts +22 -0
- package/dist/cjs/client/BuildContext.js +76 -0
- package/dist/cjs/client/BuildKitProgress.d.ts +81 -0
- package/dist/cjs/client/BuildKitProgress.js +195 -0
- package/dist/cjs/client/DockerClient.d.ts +196 -0
- package/dist/cjs/client/DockerClient.js +312 -0
- package/dist/cjs/client/DockerConnection.d.ts +154 -0
- package/dist/cjs/client/DockerConnection.js +397 -0
- package/dist/cjs/client/DockerIgnore.d.ts +44 -0
- package/dist/cjs/client/DockerIgnore.js +186 -0
- package/dist/cjs/client/DockerRequestError.d.ts +17 -0
- package/dist/cjs/client/DockerRequestError.js +24 -0
- package/dist/cjs/client/DockerStreams.d.ts +35 -0
- package/dist/cjs/client/DockerStreams.js +117 -0
- package/dist/cjs/client/types/ContainerCreateResponse.d.ts +7 -0
- package/dist/cjs/client/types/ContainerCreateResponse.js +2 -0
- package/dist/cjs/client/types/ContainerStopQuery.d.ts +13 -0
- package/dist/cjs/client/types/ContainerStopQuery.js +2 -0
- package/dist/cjs/client/types/DeviceMapping.d.ts +8 -0
- package/dist/cjs/client/types/DeviceMapping.js +2 -0
- package/dist/cjs/client/types/IdResponse.d.ts +6 -0
- package/dist/cjs/client/types/IdResponse.js +2 -0
- package/dist/cjs/client/types/NetworkCreateResponse.d.ts +7 -0
- package/dist/cjs/client/types/NetworkCreateResponse.js +2 -0
- package/dist/cjs/client/types/PortBinding.d.ts +10 -0
- package/dist/cjs/client/types/PortBinding.js +2 -0
- package/dist/cjs/docker/ConnectionOptionsBuilder.d.ts +128 -0
- package/dist/cjs/docker/ConnectionOptionsBuilder.js +150 -0
- package/dist/cjs/docker/Docker.d.ts +301 -0
- package/dist/cjs/docker/Docker.js +703 -0
- package/dist/cjs/docker/exceptions/DockerConnectionException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerConnectionException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerImageBuildException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerImageBuildException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerImageImportException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerImageImportException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
- package/dist/cjs/docker/exceptions/DockerImageNotFoundException.js +17 -0
- package/dist/cjs/docker/exceptions/DockerImagePullException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerImagePullException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerImagePushException.d.ts +8 -0
- package/dist/cjs/docker/exceptions/DockerImagePushException.js +15 -0
- package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
- package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.js +15 -0
- package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
- package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.js +16 -0
- package/dist/cjs/docker/exceptions/DockerRequestException.d.ts +22 -0
- package/dist/cjs/docker/exceptions/DockerRequestException.js +24 -0
- package/dist/cjs/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
- package/dist/cjs/docker/interfaces/IDockerConnectionOptions.js +2 -0
- package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
- package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.js +2 -0
- package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
- package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.js +2 -0
- package/dist/cjs/docker/interfaces/IDockerKeyObject.d.ts +14 -0
- package/dist/cjs/docker/interfaces/IDockerKeyObject.js +2 -0
- package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
- package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.js +2 -0
- package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
- package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.js +2 -0
- package/dist/cjs/docker/lib/DockerContainer.d.ts +315 -0
- package/dist/cjs/docker/lib/DockerContainer.js +742 -0
- package/dist/cjs/docker/lib/DockerContainerTTY.d.ts +99 -0
- package/dist/cjs/docker/lib/DockerContainerTTY.js +157 -0
- package/dist/cjs/docker/lib/DockerImage.d.ts +153 -0
- package/dist/cjs/docker/lib/DockerImage.js +273 -0
- package/dist/cjs/docker/lib/EngineSettings.d.ts +41 -0
- package/dist/cjs/docker/lib/EngineSettings.js +86 -0
- package/dist/cjs/docker/lib/ParseBaseImages.d.ts +9 -0
- package/dist/cjs/docker/lib/ParseBaseImages.js +50 -0
- package/dist/cjs/docker/lib/ParseEnvToRecord.d.ts +14 -0
- package/dist/cjs/docker/lib/ParseEnvToRecord.js +25 -0
- package/dist/cjs/docker/lib/ParseRepositoryTag.d.ts +17 -0
- package/dist/cjs/docker/lib/ParseRepositoryTag.js +48 -0
- package/dist/cjs/docker/lib/RegistryAuth.d.ts +8 -0
- package/dist/cjs/docker/lib/RegistryAuth.js +15 -0
- package/dist/cjs/docker/options/DockerPruneOptions.d.ts +38 -0
- package/dist/cjs/docker/options/DockerPruneOptions.js +47 -0
- package/dist/cjs/docker/options/auth/DockerAuthOptions.d.ts +46 -0
- package/dist/cjs/docker/options/auth/DockerAuthOptions.js +59 -0
- package/dist/cjs/docker/options/container/ContainerCommitOptions.d.ts +28 -0
- package/dist/cjs/docker/options/container/ContainerCommitOptions.js +39 -0
- package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
- package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.js +43 -0
- package/dist/cjs/docker/options/container/ContainerExecOptions.d.ts +26 -0
- package/dist/cjs/docker/options/container/ContainerExecOptions.js +38 -0
- package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
- package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.js +39 -0
- package/dist/cjs/docker/options/container/ContainerKillOptions.d.ts +25 -0
- package/dist/cjs/docker/options/container/ContainerKillOptions.js +36 -0
- package/dist/cjs/docker/options/container/ContainerLogsOptions.d.ts +48 -0
- package/dist/cjs/docker/options/container/ContainerLogsOptions.js +56 -0
- package/dist/cjs/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
- package/dist/cjs/docker/options/container/ContainerRemoveOptions.js +34 -0
- package/dist/cjs/docker/options/container/ContainerSettingOptions.d.ts +137 -0
- package/dist/cjs/docker/options/container/ContainerSettingOptions.js +136 -0
- package/dist/cjs/docker/options/container/ContainerStopOptions.d.ts +28 -0
- package/dist/cjs/docker/options/container/ContainerStopOptions.js +40 -0
- package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
- package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.js +40 -0
- package/dist/cjs/docker/options/image/ImageBuildOptions.d.ts +117 -0
- package/dist/cjs/docker/options/image/ImageBuildOptions.js +111 -0
- package/dist/cjs/docker/options/image/ImageExportOptions.d.ts +33 -0
- package/dist/cjs/docker/options/image/ImageExportOptions.js +44 -0
- package/dist/cjs/docker/options/image/ImageImportOptions.d.ts +28 -0
- package/dist/cjs/docker/options/image/ImageImportOptions.js +42 -0
- package/dist/cjs/docker/options/image/ImagePullOptions.d.ts +49 -0
- package/dist/cjs/docker/options/image/ImagePullOptions.js +63 -0
- package/dist/cjs/docker/options/image/ImagePushOptions.d.ts +41 -0
- package/dist/cjs/docker/options/image/ImagePushOptions.js +56 -0
- package/dist/cjs/docker/options/image/ImageRemoveOptions.d.ts +26 -0
- package/dist/cjs/docker/options/image/ImageRemoveOptions.js +38 -0
- package/dist/cjs/docker/options/image/ImageTagOptions.d.ts +25 -0
- package/dist/cjs/docker/options/image/ImageTagOptions.js +38 -0
- package/dist/cjs/docker/options/network/NetworkCreateOptions.d.ts +54 -0
- package/dist/cjs/docker/options/network/NetworkCreateOptions.js +63 -0
- package/dist/cjs/docker/types/ContainerBind.d.ts +19 -0
- package/dist/cjs/docker/types/ContainerBind.js +2 -0
- package/dist/cjs/docker/types/ContainerCapability.d.ts +286 -0
- package/dist/cjs/docker/types/ContainerCapability.js +290 -0
- package/dist/cjs/docker/types/ContainerConfig.d.ts +67 -0
- package/dist/cjs/docker/types/ContainerConfig.js +2 -0
- package/dist/cjs/docker/types/ContainerDevice.d.ts +19 -0
- package/dist/cjs/docker/types/ContainerDevice.js +2 -0
- package/dist/cjs/docker/types/ContainerExecResult.d.ts +20 -0
- package/dist/cjs/docker/types/ContainerExecResult.js +2 -0
- package/dist/cjs/docker/types/ContainerNetwork.d.ts +46 -0
- package/dist/cjs/docker/types/ContainerNetwork.js +2 -0
- package/dist/cjs/docker/types/ContainerPort.d.ts +25 -0
- package/dist/cjs/docker/types/ContainerPort.js +2 -0
- package/dist/cjs/docker/types/ContainerRestartPolicy.d.ts +11 -0
- package/dist/cjs/docker/types/ContainerRestartPolicy.js +2 -0
- package/dist/cjs/docker/types/ContainerState.d.ts +48 -0
- package/dist/cjs/docker/types/ContainerState.js +2 -0
- package/dist/cjs/docker/types/ContainerStats.d.ts +408 -0
- package/dist/cjs/docker/types/ContainerStats.js +2 -0
- package/dist/cjs/docker/types/DockerOutputCallback.d.ts +8 -0
- package/dist/cjs/docker/types/DockerOutputCallback.js +2 -0
- package/dist/cjs/docker/types/ImageConfig.d.ts +34 -0
- package/dist/cjs/docker/types/ImageConfig.js +2 -0
- package/dist/cjs/docker/types/ImageExposePort.d.ts +17 -0
- package/dist/cjs/docker/types/ImageExposePort.js +2 -0
- package/dist/cjs/docker/types/NetworkInfo.d.ts +59 -0
- package/dist/cjs/docker/types/NetworkInfo.js +2 -0
- package/dist/cjs/docker/types/RepositoryTag.d.ts +15 -0
- package/dist/cjs/docker/types/RepositoryTag.js +2 -0
- package/dist/cjs/exports/Docker.d.ts +73 -0
- package/dist/cjs/exports/Docker.js +92 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/client/BuildContext.js +70 -0
- package/dist/esm/client/BuildKitProgress.js +190 -0
- package/dist/esm/client/DockerClient.js +307 -0
- package/dist/esm/client/DockerConnection.js +355 -0
- package/dist/esm/client/DockerIgnore.js +179 -0
- package/dist/esm/client/DockerRequestError.js +20 -0
- package/dist/esm/client/DockerStreams.js +111 -0
- package/dist/esm/client/types/ContainerCreateResponse.js +1 -0
- package/dist/esm/client/types/ContainerStopQuery.js +1 -0
- package/dist/esm/client/types/DeviceMapping.js +1 -0
- package/dist/esm/client/types/IdResponse.js +1 -0
- package/dist/esm/client/types/NetworkCreateResponse.js +1 -0
- package/dist/esm/client/types/PortBinding.js +1 -0
- package/dist/esm/docker/ConnectionOptionsBuilder.js +142 -0
- package/dist/esm/docker/Docker.js +697 -0
- package/dist/esm/docker/exceptions/DockerConnectionException.js +12 -0
- package/dist/esm/docker/exceptions/DockerContainerNotFoundException.js +12 -0
- package/dist/esm/docker/exceptions/DockerImageBuildException.js +12 -0
- package/dist/esm/docker/exceptions/DockerImageImportException.js +12 -0
- package/dist/esm/docker/exceptions/DockerImageNotFoundException.js +13 -0
- package/dist/esm/docker/exceptions/DockerImagePullException.js +12 -0
- package/dist/esm/docker/exceptions/DockerImagePushException.js +11 -0
- package/dist/esm/docker/exceptions/DockerImageRepoTagNotFoundException.js +11 -0
- package/dist/esm/docker/exceptions/DockerNetworkNotFoundException.js +12 -0
- package/dist/esm/docker/exceptions/DockerRequestException.js +20 -0
- package/dist/esm/docker/interfaces/IDockerConnectionOptions.js +1 -0
- package/dist/esm/docker/interfaces/IDockerHttpConnectionOptions.js +1 -0
- package/dist/esm/docker/interfaces/IDockerHttpsConnectionOptions.js +1 -0
- package/dist/esm/docker/interfaces/IDockerKeyObject.js +1 -0
- package/dist/esm/docker/interfaces/IDockerSSHConnectionOptions.js +1 -0
- package/dist/esm/docker/interfaces/IDockerSocketConnectionOptions.js +1 -0
- package/dist/esm/docker/lib/DockerContainer.js +739 -0
- package/dist/esm/docker/lib/DockerContainerTTY.js +154 -0
- package/dist/esm/docker/lib/DockerImage.js +270 -0
- package/dist/esm/docker/lib/EngineSettings.js +78 -0
- package/dist/esm/docker/lib/ParseBaseImages.js +47 -0
- package/dist/esm/docker/lib/ParseEnvToRecord.js +22 -0
- package/dist/esm/docker/lib/ParseRepositoryTag.js +45 -0
- package/dist/esm/docker/lib/RegistryAuth.js +12 -0
- package/dist/esm/docker/options/DockerPruneOptions.js +43 -0
- package/dist/esm/docker/options/auth/DockerAuthOptions.js +55 -0
- package/dist/esm/docker/options/container/ContainerCommitOptions.js +35 -0
- package/dist/esm/docker/options/container/ContainerCreateTTYOptions.js +39 -0
- package/dist/esm/docker/options/container/ContainerExecOptions.js +34 -0
- package/dist/esm/docker/options/container/ContainerExportDirectoryOptions.js +35 -0
- package/dist/esm/docker/options/container/ContainerKillOptions.js +32 -0
- package/dist/esm/docker/options/container/ContainerLogsOptions.js +52 -0
- package/dist/esm/docker/options/container/ContainerRemoveOptions.js +30 -0
- package/dist/esm/docker/options/container/ContainerSettingOptions.js +132 -0
- package/dist/esm/docker/options/container/ContainerStopOptions.js +36 -0
- package/dist/esm/docker/options/container/ContainerTTYConsoleSizeOptions.js +36 -0
- package/dist/esm/docker/options/image/ImageBuildOptions.js +107 -0
- package/dist/esm/docker/options/image/ImageExportOptions.js +40 -0
- package/dist/esm/docker/options/image/ImageImportOptions.js +38 -0
- package/dist/esm/docker/options/image/ImagePullOptions.js +59 -0
- package/dist/esm/docker/options/image/ImagePushOptions.js +52 -0
- package/dist/esm/docker/options/image/ImageRemoveOptions.js +34 -0
- package/dist/esm/docker/options/image/ImageTagOptions.js +34 -0
- package/dist/esm/docker/options/network/NetworkCreateOptions.js +59 -0
- package/dist/esm/docker/types/ContainerBind.js +1 -0
- package/dist/esm/docker/types/ContainerCapability.js +287 -0
- package/dist/esm/docker/types/ContainerConfig.js +1 -0
- package/dist/esm/docker/types/ContainerDevice.js +1 -0
- package/dist/esm/docker/types/ContainerExecResult.js +1 -0
- package/dist/esm/docker/types/ContainerNetwork.js +1 -0
- package/dist/esm/docker/types/ContainerPort.js +1 -0
- package/dist/esm/docker/types/ContainerRestartPolicy.js +1 -0
- package/dist/esm/docker/types/ContainerState.js +1 -0
- package/dist/esm/docker/types/ContainerStats.js +1 -0
- package/dist/esm/docker/types/DockerOutputCallback.js +1 -0
- package/dist/esm/docker/types/ImageConfig.js +1 -0
- package/dist/esm/docker/types/ImageExposePort.js +1 -0
- package/dist/esm/docker/types/NetworkInfo.js +1 -0
- package/dist/esm/docker/types/RepositoryTag.js +1 -0
- package/dist/esm/exports/Docker.js +73 -0
- package/dist/types/client/BuildContext.d.ts +22 -0
- package/dist/types/client/BuildKitProgress.d.ts +81 -0
- package/dist/types/client/DockerClient.d.ts +196 -0
- package/dist/types/client/DockerConnection.d.ts +154 -0
- package/dist/types/client/DockerIgnore.d.ts +44 -0
- package/dist/types/client/DockerRequestError.d.ts +17 -0
- package/dist/types/client/DockerStreams.d.ts +35 -0
- package/dist/types/client/types/ContainerCreateResponse.d.ts +7 -0
- package/dist/types/client/types/ContainerStopQuery.d.ts +13 -0
- package/dist/types/client/types/DeviceMapping.d.ts +8 -0
- package/dist/types/client/types/IdResponse.d.ts +6 -0
- package/dist/types/client/types/NetworkCreateResponse.d.ts +7 -0
- package/dist/types/client/types/PortBinding.d.ts +10 -0
- package/dist/types/docker/ConnectionOptionsBuilder.d.ts +128 -0
- package/dist/types/docker/Docker.d.ts +301 -0
- package/dist/types/docker/exceptions/DockerConnectionException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerImageBuildException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerImageImportException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
- package/dist/types/docker/exceptions/DockerImagePullException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerImagePushException.d.ts +8 -0
- package/dist/types/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
- package/dist/types/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
- package/dist/types/docker/exceptions/DockerRequestException.d.ts +22 -0
- package/dist/types/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
- package/dist/types/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
- package/dist/types/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
- package/dist/types/docker/interfaces/IDockerKeyObject.d.ts +14 -0
- package/dist/types/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
- package/dist/types/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
- package/dist/types/docker/lib/DockerContainer.d.ts +315 -0
- package/dist/types/docker/lib/DockerContainerTTY.d.ts +99 -0
- package/dist/types/docker/lib/DockerImage.d.ts +153 -0
- package/dist/types/docker/lib/EngineSettings.d.ts +41 -0
- package/dist/types/docker/lib/ParseBaseImages.d.ts +9 -0
- package/dist/types/docker/lib/ParseEnvToRecord.d.ts +14 -0
- package/dist/types/docker/lib/ParseRepositoryTag.d.ts +17 -0
- package/dist/types/docker/lib/RegistryAuth.d.ts +8 -0
- package/dist/types/docker/options/DockerPruneOptions.d.ts +38 -0
- package/dist/types/docker/options/auth/DockerAuthOptions.d.ts +46 -0
- package/dist/types/docker/options/container/ContainerCommitOptions.d.ts +28 -0
- package/dist/types/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
- package/dist/types/docker/options/container/ContainerExecOptions.d.ts +26 -0
- package/dist/types/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
- package/dist/types/docker/options/container/ContainerKillOptions.d.ts +25 -0
- package/dist/types/docker/options/container/ContainerLogsOptions.d.ts +48 -0
- package/dist/types/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
- package/dist/types/docker/options/container/ContainerSettingOptions.d.ts +137 -0
- package/dist/types/docker/options/container/ContainerStopOptions.d.ts +28 -0
- package/dist/types/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
- package/dist/types/docker/options/image/ImageBuildOptions.d.ts +117 -0
- package/dist/types/docker/options/image/ImageExportOptions.d.ts +33 -0
- package/dist/types/docker/options/image/ImageImportOptions.d.ts +28 -0
- package/dist/types/docker/options/image/ImagePullOptions.d.ts +49 -0
- package/dist/types/docker/options/image/ImagePushOptions.d.ts +41 -0
- package/dist/types/docker/options/image/ImageRemoveOptions.d.ts +26 -0
- package/dist/types/docker/options/image/ImageTagOptions.d.ts +25 -0
- package/dist/types/docker/options/network/NetworkCreateOptions.d.ts +54 -0
- package/dist/types/docker/types/ContainerBind.d.ts +19 -0
- package/dist/types/docker/types/ContainerCapability.d.ts +286 -0
- package/dist/types/docker/types/ContainerConfig.d.ts +67 -0
- package/dist/types/docker/types/ContainerDevice.d.ts +19 -0
- package/dist/types/docker/types/ContainerExecResult.d.ts +20 -0
- package/dist/types/docker/types/ContainerNetwork.d.ts +46 -0
- package/dist/types/docker/types/ContainerPort.d.ts +25 -0
- package/dist/types/docker/types/ContainerRestartPolicy.d.ts +11 -0
- package/dist/types/docker/types/ContainerState.d.ts +48 -0
- package/dist/types/docker/types/ContainerStats.d.ts +408 -0
- package/dist/types/docker/types/DockerOutputCallback.d.ts +8 -0
- package/dist/types/docker/types/ImageConfig.d.ts +34 -0
- package/dist/types/docker/types/ImageExposePort.d.ts +17 -0
- package/dist/types/docker/types/NetworkInfo.d.ts +59 -0
- package/dist/types/docker/types/RepositoryTag.d.ts +15 -0
- package/dist/types/exports/Docker.d.ts +73 -0
- package/package.json +57 -0
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Docker = void 0;
|
|
16
|
+
const core_1 = require("@lakutata/core");
|
|
17
|
+
const di_1 = require("@lakutata/core/decorator/di");
|
|
18
|
+
const DockerImage_js_1 = require("./lib/DockerImage.js");
|
|
19
|
+
const DockerContainer_js_1 = require("./lib/DockerContainer.js");
|
|
20
|
+
const DockerConnectionException_js_1 = require("./exceptions/DockerConnectionException.js");
|
|
21
|
+
const DockerImageNotFoundException_js_1 = require("./exceptions/DockerImageNotFoundException.js");
|
|
22
|
+
const ImagePullOptions_js_1 = require("./options/image/ImagePullOptions.js");
|
|
23
|
+
const dto_1 = require("@lakutata/core/decorator/dto");
|
|
24
|
+
const DockerImagePullException_js_1 = require("./exceptions/DockerImagePullException.js");
|
|
25
|
+
const utils_1 = require("@lakutata/utils");
|
|
26
|
+
const ImageBuildOptions_js_1 = require("./options/image/ImageBuildOptions.js");
|
|
27
|
+
const DockerImageBuildException_js_1 = require("./exceptions/DockerImageBuildException.js");
|
|
28
|
+
const ImageImportOptions_js_1 = require("./options/image/ImageImportOptions.js");
|
|
29
|
+
const DockerImageImportException_js_1 = require("./exceptions/DockerImageImportException.js");
|
|
30
|
+
const tar_stream_1 = require("tar-stream");
|
|
31
|
+
const node_fs_1 = require("node:fs");
|
|
32
|
+
const node_stream_1 = require("node:stream");
|
|
33
|
+
const NetworkCreateOptions_js_1 = require("./options/network/NetworkCreateOptions.js");
|
|
34
|
+
const Time_1 = require("@lakutata/utils/Time");
|
|
35
|
+
const ContainerSettingOptions_js_1 = require("./options/container/ContainerSettingOptions.js");
|
|
36
|
+
const DockerContainerTTY_js_1 = require("./lib/DockerContainerTTY.js");
|
|
37
|
+
const DockerPruneOptions_js_1 = require("./options/DockerPruneOptions.js");
|
|
38
|
+
const DockerAuthOptions_js_1 = require("./options/auth/DockerAuthOptions.js");
|
|
39
|
+
const promises_1 = require("node:fs/promises");
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const DockerClient_js_1 = require("../client/DockerClient.js");
|
|
42
|
+
const BuildContext_js_1 = require("../client/BuildContext.js");
|
|
43
|
+
const BuildKitProgress_js_1 = require("../client/BuildKitProgress.js");
|
|
44
|
+
const DockerStreams_js_1 = require("../client/DockerStreams.js");
|
|
45
|
+
const ParseBaseImages_js_1 = require("./lib/ParseBaseImages.js");
|
|
46
|
+
const DockerContainerNotFoundException_js_1 = require("./exceptions/DockerContainerNotFoundException.js");
|
|
47
|
+
const RegistryAuth_js_1 = require("./lib/RegistryAuth.js");
|
|
48
|
+
const EngineSettings_js_1 = require("./lib/EngineSettings.js");
|
|
49
|
+
/**
|
|
50
|
+
* The Docker component: drives a Docker daemon over the Docker Engine API, to pull, build, import, export, tag and push
|
|
51
|
+
* images, to create, run and manage containers (exec, TTYs, logs, stats, commit, archives) and to manage networks.
|
|
52
|
+
* Register it in the `components` of an application (`{class: Docker}`, or the result of one of the
|
|
53
|
+
* `BuildDocker*ConnectionOptions` functions) and get it with `getObject()` or `@Inject`; it is a singleton.
|
|
54
|
+
*
|
|
55
|
+
* Without `socketPath` nor `host`, it connects to the Docker of the environment: `DOCKER_HOST` (with
|
|
56
|
+
* `DOCKER_TLS_VERIFY`, `DOCKER_CERT_PATH` and `DOCKER_CLIENT_TIMEOUT`), else the named pipe `//./pipe/docker_engine` on
|
|
57
|
+
* Windows, the socket of Docker Desktop (`~/.docker/run/docker.sock`) when it exists, or `/var/run/docker.sock`; the
|
|
58
|
+
* other options given (`timeout`, `headers`, `version`…) apply over the environment's. No Docker CLI is needed locally
|
|
59
|
+
* (the SSH connections need it on the remote host).
|
|
60
|
+
*
|
|
61
|
+
* When it is created, the component pings the daemon and negotiates the API version (the newest one supported by both,
|
|
62
|
+
* from 1.41 to 1.56): a daemon which cannot be reached fails its creation with {@link DockerConnectionException}.
|
|
63
|
+
* Afterwards, a daemon which cannot be reached rejects the calls with the network error of Node.js (`ECONNREFUSED`,
|
|
64
|
+
* `ENOENT`…). A request the daemon refuses rejects with the exception of what is missing
|
|
65
|
+
* ({@link DockerContainerNotFoundException}, {@link DockerImageNotFoundException},
|
|
66
|
+
* {@link DockerNetworkNotFoundException}), else with a {@link DockerRequestException}, whose `statusCode` is the HTTP
|
|
67
|
+
* status and whose message is the daemon's. The pulls, builds, imports and pushes wrap their failures in their own
|
|
68
|
+
* exceptions ({@link DockerImagePullException}…).
|
|
69
|
+
*
|
|
70
|
+
* When the component is destroyed (the application stopping), the pulls and builds in progress are aborted (they reject
|
|
71
|
+
* with their exception), the listings in progress resolve with an empty list, and its connections are closed.
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import {Application} from 'lakutata'
|
|
75
|
+
* import {Docker, type DockerContainer, type DockerImage} from 'lakutata/com/docker'
|
|
76
|
+
*
|
|
77
|
+
* Application
|
|
78
|
+
* .run(() => ({
|
|
79
|
+
* id: 'docker.app',
|
|
80
|
+
* name: 'Docker',
|
|
81
|
+
* components: {
|
|
82
|
+
* //The Docker of the environment: DOCKER_HOST, else the local socket
|
|
83
|
+
* docker: {class: Docker}
|
|
84
|
+
* }
|
|
85
|
+
* }))
|
|
86
|
+
* .onLaunched(async (app: Application): Promise<void> => {
|
|
87
|
+
* const docker: Docker = await app.getObject('docker')
|
|
88
|
+
* const image: DockerImage = await docker.pullImage({repo: 'alpine', tag: '3.20'})
|
|
89
|
+
* //Created, then started
|
|
90
|
+
* const container: DockerContainer = await image.run({name: 'hello', cmd: ['sleep', '60']})
|
|
91
|
+
* console.log((await container.exec({cmd: ['echo', 'hello']})).stdout)
|
|
92
|
+
* await container.remove({force: true})
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
let Docker = class Docker extends core_1.Component {
|
|
97
|
+
#client;
|
|
98
|
+
#abortController = new AbortController();
|
|
99
|
+
#internalNetworkNames = ['bridge', 'host', 'none'];
|
|
100
|
+
/**
|
|
101
|
+
* Connect to the daemon: ping it, then negotiate the API version.
|
|
102
|
+
* @throws {DockerConnectionException} When the daemon cannot be reached or does not answer, or when an SSH
|
|
103
|
+
* connection is configured without the package `ssh2`.
|
|
104
|
+
* @protected
|
|
105
|
+
*/
|
|
106
|
+
async init() {
|
|
107
|
+
await Promise.all([
|
|
108
|
+
this.container.register(DockerImage_js_1.DockerImage),
|
|
109
|
+
this.container.register(DockerContainer_js_1.DockerContainer),
|
|
110
|
+
this.container.register(DockerContainerTTY_js_1.DockerContainerTTY)
|
|
111
|
+
]);
|
|
112
|
+
//Without a socket nor a host, the Docker of the environment (DOCKER_HOST, the socket of Docker Desktop or of the
|
|
113
|
+
//system, the named pipe of Windows), with the options given applied over it
|
|
114
|
+
this.#client = new DockerClient_js_1.DockerClient({
|
|
115
|
+
socketPath: this.socketPath,
|
|
116
|
+
host: this.host,
|
|
117
|
+
port: this.port,
|
|
118
|
+
username: this.username,
|
|
119
|
+
headers: this.headers,
|
|
120
|
+
ca: this.ca,
|
|
121
|
+
cert: this.cert,
|
|
122
|
+
key: this.key,
|
|
123
|
+
protocol: this.protocol,
|
|
124
|
+
timeout: this.timeout,
|
|
125
|
+
version: this.version,
|
|
126
|
+
sshAuthAgent: this.sshAuthAgent
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
await this.#client.ping();
|
|
130
|
+
//The API version of the requests: the newest one supported by the daemon and this client
|
|
131
|
+
await this.#client.connection.negotiate();
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
throw new DockerConnectionException_js_1.DockerConnectionException(e.message ? e.message : 'Cannot connect to docker');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Abort the pulls, builds and listings in progress (the pulls and builds then reject), then close the connections
|
|
139
|
+
* to the daemon.
|
|
140
|
+
* @protected
|
|
141
|
+
*/
|
|
142
|
+
async destroy() {
|
|
143
|
+
this.#abortController.abort();
|
|
144
|
+
this.#client?.close();
|
|
145
|
+
}
|
|
146
|
+
/** Docker Common Operations **/
|
|
147
|
+
/**
|
|
148
|
+
* Remove the daemon's unused resources, as `docker <kind> prune` does without options: the stopped containers, then
|
|
149
|
+
* the dangling images (untagged and unused), the unused networks and the unused anonymous volumes. Without
|
|
150
|
+
* options, the containers and the images are pruned; the networks and the volumes only when asked.
|
|
151
|
+
* @param options The kinds of resources pruned: `containers` and `images` default to `true`, `networks` and
|
|
152
|
+
* `volumes` to `false`.
|
|
153
|
+
* @throws {InvalidMethodAcceptException} When the options are invalid.
|
|
154
|
+
* @throws {DockerRequestException} When the daemon refuses a prune (one already running: HTTP 409).
|
|
155
|
+
*/
|
|
156
|
+
async prune(options) {
|
|
157
|
+
if (!options)
|
|
158
|
+
return await this.prune({});
|
|
159
|
+
if (options.containers)
|
|
160
|
+
await this.#client.pruneContainers();
|
|
161
|
+
if (options.images)
|
|
162
|
+
await this.#client.pruneImages();
|
|
163
|
+
if (options.networks)
|
|
164
|
+
await this.#client.pruneNetworks();
|
|
165
|
+
if (options.volumes)
|
|
166
|
+
await this.#client.pruneVolumes();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Check credentials against a registry, as `docker login` does. The credentials are not kept: each pull, build or
|
|
170
|
+
* push which needs them is given its own `auth`.
|
|
171
|
+
* @param options The registry (`serverAddress`, a host name without protocol: `registry.example.com:5000`) and its
|
|
172
|
+
* credentials (a password, or a token).
|
|
173
|
+
* @throws {DockerRequestException} When the registry refuses the credentials or cannot be reached (the daemon's
|
|
174
|
+
* status: HTTP 401, 500).
|
|
175
|
+
*/
|
|
176
|
+
async loginRepository(options) {
|
|
177
|
+
await this.#client.checkAuth((0, RegistryAuth_js_1.registryAuth)(options));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Whether a registry accepts credentials ({@link Docker.loginRepository} without its error).
|
|
181
|
+
* @param options The registry (`serverAddress`, a host name without protocol) and its credentials.
|
|
182
|
+
* @returns `true` when they are accepted; `false` on any failure, the daemon unreachable included.
|
|
183
|
+
*/
|
|
184
|
+
async checkRepositoryAuth(options) {
|
|
185
|
+
try {
|
|
186
|
+
await this.loginRepository(options);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** Docker Image Operations **/
|
|
194
|
+
/**
|
|
195
|
+
* List the daemon's images (as `docker images`, without the intermediate ones). Each image is inspected with a request
|
|
196
|
+
* of its own, so the call costs one request per image; an image removed during the listing is not listed.
|
|
197
|
+
* @returns The images, in the daemon's order.
|
|
198
|
+
*/
|
|
199
|
+
async listImages() {
|
|
200
|
+
const rawImages = await this.#client.listImages();
|
|
201
|
+
const images = await Promise.all(rawImages.map(async (rawImage) => {
|
|
202
|
+
try {
|
|
203
|
+
return await this.#image(rawImage.Id);
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
//Removed since it was listed
|
|
207
|
+
if (e instanceof DockerImageNotFoundException_js_1.DockerImageNotFoundException)
|
|
208
|
+
return undefined;
|
|
209
|
+
throw e;
|
|
210
|
+
}
|
|
211
|
+
}));
|
|
212
|
+
return images.filter((image) => !!image);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The object of an image, inspected
|
|
216
|
+
* @param id
|
|
217
|
+
*/
|
|
218
|
+
async #image(id) {
|
|
219
|
+
return await this.container.get(DockerImage_js_1.DockerImage, {
|
|
220
|
+
id: id,
|
|
221
|
+
getClient: () => this.#client,
|
|
222
|
+
getDocker: () => this
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Pull an image from its registry, as `docker pull`, and wait for its end.
|
|
227
|
+
* @param options The repository (`alpine`, `registry.example.com:5000/team/app`), the tag (`'latest'` by default),
|
|
228
|
+
* the platform (`linux/arm64`, the daemon's by default), the registry credentials, and a callback receiving each
|
|
229
|
+
* progress message.
|
|
230
|
+
* @returns The image pulled, found as `repo:tag` the way the daemon names it (`docker.io/library/alpine` is
|
|
231
|
+
* `alpine`).
|
|
232
|
+
* @throws {DockerImagePullException} When the pull fails: the image or the registry not found, refused credentials,
|
|
233
|
+
* the daemon unreachable, or the component destroyed during the pull (its message then says it was aborted).
|
|
234
|
+
*/
|
|
235
|
+
async pullImage(options) {
|
|
236
|
+
const auth = (0, RegistryAuth_js_1.registryAuth)(options.auth);
|
|
237
|
+
const tag = options.tag ? options.tag : 'latest';
|
|
238
|
+
try {
|
|
239
|
+
const readableStream = await this.#client.pullImage({ fromImage: options.repo, tag: tag, platform: options.platform }, auth, this.#abortController.signal);
|
|
240
|
+
let pullError;
|
|
241
|
+
await (0, DockerStreams_js_1.followProgress)(readableStream, (outputObject) => {
|
|
242
|
+
if (options.outputCallback)
|
|
243
|
+
options.outputCallback(outputObject);
|
|
244
|
+
if (outputObject.error && !pullError)
|
|
245
|
+
pullError = outputObject.error;
|
|
246
|
+
});
|
|
247
|
+
if (pullError)
|
|
248
|
+
throw new Error(pullError);
|
|
249
|
+
//A tag or a digest
|
|
250
|
+
return await this.getImage(tag.includes(':') ? `${options.repo}@${tag}` : `${options.repo}:${tag}`);
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
if ((0, utils_1.isAbortError)(e))
|
|
254
|
+
throw new DockerImagePullException_js_1.DockerImagePullException('The pull of {0} was aborted: the Docker component was destroyed', [options.repo]);
|
|
255
|
+
throw new DockerImagePullException_js_1.DockerImagePullException(e.message);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Build an image with BuildKit, as `docker build`, and wait for its end. The build context is made of the `files`
|
|
260
|
+
* of the `workdir` (relative paths; a directory with its content), without the ones its `.dockerignore` excludes,
|
|
261
|
+
* and always with the Dockerfile. The progress is given to the output callback as the lines of
|
|
262
|
+
* `docker build --progress=plain` (`{id: 'moby.buildkit.trace', stream: '#2 [1/2] FROM alpine'}`).
|
|
263
|
+
*
|
|
264
|
+
* With `auth`, the base images of the Dockerfile (its `FROM` lines) are pulled first with these credentials, as
|
|
265
|
+
* BuildKit is not given them.
|
|
266
|
+
* @param options The context (`workdir`, `files`), the Dockerfile, the name of the image (`repoTag`; a generated
|
|
267
|
+
* `unnamed_img_…` name by default), the platform, the target stage, the build arguments, the registry credentials
|
|
268
|
+
* and the output callback.
|
|
269
|
+
* @returns The image built.
|
|
270
|
+
* @throws {DockerImageBuildException} When the build fails: a step failing, the Dockerfile or a file of the context
|
|
271
|
+
* missing, a base image which cannot be pulled, the daemon unreachable, or the component destroyed during the build
|
|
272
|
+
* (its message then says it was aborted).
|
|
273
|
+
*/
|
|
274
|
+
async buildImage(options) {
|
|
275
|
+
const dockerfile = options.dockerfile ? options.dockerfile : 'Dockerfile';
|
|
276
|
+
const auth = (0, RegistryAuth_js_1.registryAuth)(options.auth);
|
|
277
|
+
try {
|
|
278
|
+
//The base images of a private registry are pulled with the credentials (BuildKit is not given them)
|
|
279
|
+
if (auth) {
|
|
280
|
+
const content = await (0, promises_1.readFile)(node_path_1.default.resolve(options.workdir, dockerfile), { encoding: 'utf-8' });
|
|
281
|
+
for (const baseImage of (0, ParseBaseImages_js_1.parseBaseImages)(content, options.buildargs)) {
|
|
282
|
+
const [repo, tag] = [baseImage.replace(/:([^:/@]+)$/, ''), /:([^:/@]+)$/.exec(baseImage)?.[1]];
|
|
283
|
+
await this.pullImage({ repo: repo, tag: tag, platform: options.platform, auth: options.auth, outputCallback: options.outputCallback });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const context = (0, BuildContext_js_1.packBuildContext)({ directory: options.workdir, entries: options.files, always: [dockerfile] });
|
|
287
|
+
const registryConfig = auth ? { [auth.serveraddress ?? 'https://index.docker.io/v1/']: auth } : undefined;
|
|
288
|
+
const readableStream = await this.#client.buildImage(context, {
|
|
289
|
+
dockerfile: dockerfile,
|
|
290
|
+
t: options.repoTag ? options.repoTag : `unnamed_img_${Date.now().toString(16)}${Math.floor(Math.random() * 255).toString(16).padStart(2, '0')}`,
|
|
291
|
+
remote: options.remote,
|
|
292
|
+
q: options.quiet || options.quite,
|
|
293
|
+
nocache: options.nocache,
|
|
294
|
+
rm: options.rm,
|
|
295
|
+
forcerm: options.forcerm,
|
|
296
|
+
platform: options.platform,
|
|
297
|
+
target: options.target,
|
|
298
|
+
shmsize: options.shmsize,
|
|
299
|
+
buildargs: options.buildargs,
|
|
300
|
+
version: '2'
|
|
301
|
+
}, registryConfig, this.#abortController.signal);
|
|
302
|
+
const progress = new BuildKitProgress_js_1.BuildKitProgress();
|
|
303
|
+
let imageId;
|
|
304
|
+
let buildError;
|
|
305
|
+
await (0, DockerStreams_js_1.followProgress)(readableStream, (outputObject) => {
|
|
306
|
+
if (outputObject.error && !buildError)
|
|
307
|
+
buildError = outputObject.error;
|
|
308
|
+
if (outputObject.id === 'moby.buildkit.trace' && typeof outputObject.aux === 'string') {
|
|
309
|
+
for (const line of progress.lines((0, BuildKitProgress_js_1.decodeBuildKitStatus)(outputObject.aux)))
|
|
310
|
+
options.outputCallback?.({ id: outputObject.id, stream: line });
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (outputObject.aux && typeof outputObject.aux === 'object' && outputObject.aux.ID)
|
|
314
|
+
imageId = outputObject.aux.ID;
|
|
315
|
+
options.outputCallback?.(outputObject);
|
|
316
|
+
});
|
|
317
|
+
if (buildError)
|
|
318
|
+
throw new DockerImageBuildException_js_1.DockerImageBuildException(buildError);
|
|
319
|
+
if (!imageId)
|
|
320
|
+
throw new DockerImageBuildException_js_1.DockerImageBuildException('Build image failed');
|
|
321
|
+
return await this.getImage(imageId);
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
if ((0, utils_1.isAbortError)(e))
|
|
325
|
+
throw new DockerImageBuildException_js_1.DockerImageBuildException('The build was aborted: the Docker component was destroyed');
|
|
326
|
+
if (e instanceof DockerImageBuildException_js_1.DockerImageBuildException)
|
|
327
|
+
throw e;
|
|
328
|
+
throw new DockerImageBuildException_js_1.DockerImageBuildException(e.message);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Load an image from a tar archive written by `docker save` (or {@link DockerImage.export}), as `docker load`. The
|
|
333
|
+
* tags saved in the archive are restored.
|
|
334
|
+
* @param options The archive (`source`, a file path or a readable stream) and `quiet` (`false` by default).
|
|
335
|
+
* @returns The image loaded.
|
|
336
|
+
* @throws {DockerImageImportException} When the daemon rejects the archive, or when the loaded image is unknown.
|
|
337
|
+
* @throws {Error} The error of the source when it cannot be read (`ENOENT` for a missing file), or the network
|
|
338
|
+
* error when the archive cannot be sent.
|
|
339
|
+
* @throws {DockerRequestException} When the daemon refuses the request.
|
|
340
|
+
*/
|
|
341
|
+
async importImage(options) {
|
|
342
|
+
const imageSourceReadableStream = typeof options.source === 'string' ? (0, node_fs_1.createReadStream)(options.source) : options.source;
|
|
343
|
+
const tarExtractPassThrough = new node_stream_1.PassThrough();
|
|
344
|
+
const loadImagePassThrough = new node_stream_1.PassThrough();
|
|
345
|
+
//An error of the source (a file which cannot be opened) fails the request sending it, then the call
|
|
346
|
+
let sourceError;
|
|
347
|
+
loadImagePassThrough.on('error', () => undefined);
|
|
348
|
+
imageSourceReadableStream.once('error', (error) => {
|
|
349
|
+
sourceError = error;
|
|
350
|
+
tarExtractPassThrough.destroy();
|
|
351
|
+
loadImagePassThrough.destroy(error);
|
|
352
|
+
});
|
|
353
|
+
imageSourceReadableStream.pipe(tarExtractPassThrough);
|
|
354
|
+
imageSourceReadableStream.pipe(loadImagePassThrough);
|
|
355
|
+
const tarExtractor = (0, tar_stream_1.extract)();
|
|
356
|
+
//The manifest only completes the daemon's answer: an archive it cannot read is reported by the daemon
|
|
357
|
+
tarExtractor.on('error', () => undefined);
|
|
358
|
+
let manifestImageId;
|
|
359
|
+
tarExtractor
|
|
360
|
+
//The types of tar-stream are its own (3.2): the stream of the entry is the one of streamx
|
|
361
|
+
.on('entry', (header, stream, next) => {
|
|
362
|
+
if (header.name === 'manifest.json') {
|
|
363
|
+
const chunks = [];
|
|
364
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
365
|
+
stream.once('end', () => {
|
|
366
|
+
try {
|
|
367
|
+
const manifestObject = JSON.parse(Buffer.concat(chunks).toString())[0];
|
|
368
|
+
manifestImageId = manifestObject.Config.toString().replace('blobs/', '').replace('.json', '').replace('/', ':');
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
//Not a manifest of docker save
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
stream.on('end', () => next());
|
|
376
|
+
stream.resume();
|
|
377
|
+
});
|
|
378
|
+
tarExtractPassThrough.pipe(tarExtractor);
|
|
379
|
+
let importError;
|
|
380
|
+
let loadedImage;
|
|
381
|
+
try {
|
|
382
|
+
const readableStream = await this.#client.loadImage(loadImagePassThrough, { quiet: options.quiet });
|
|
383
|
+
await (0, DockerStreams_js_1.followProgress)(readableStream, (outputObject) => {
|
|
384
|
+
if (outputObject.error && !importError)
|
|
385
|
+
importError = outputObject.error;
|
|
386
|
+
//"Loaded image ID: sha256:…" or "Loaded image: repo:tag"
|
|
387
|
+
const loaded = /Loaded image(?: ID)?: (\S+)/.exec(outputObject.stream ?? '');
|
|
388
|
+
if (loaded && !loadedImage)
|
|
389
|
+
loadedImage = loaded[1];
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch (e) {
|
|
393
|
+
throw sourceError ?? e;
|
|
394
|
+
}
|
|
395
|
+
if (sourceError)
|
|
396
|
+
throw sourceError;
|
|
397
|
+
if (importError)
|
|
398
|
+
throw new DockerImageImportException_js_1.DockerImageImportException(importError);
|
|
399
|
+
const image = loadedImage ?? manifestImageId;
|
|
400
|
+
if (!image)
|
|
401
|
+
throw new DockerImageImportException_js_1.DockerImageImportException('The imported image is unknown');
|
|
402
|
+
return await this.getImage(image);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get an image by its ID or its name, resolved by the daemon as `docker image inspect` does: the full ID
|
|
406
|
+
* (`sha256:…`), a unique prefix of it (`d9e853e8`), a tag (`alpine:3.20`), a name without its tag for `:latest`
|
|
407
|
+
* (`alpine`), a name with its registry (`docker.io/library/alpine:3.20`) or a digest (`alpine@sha256:…`).
|
|
408
|
+
* @param repoTagOrId The ID, the short ID, the name or the digest of the image.
|
|
409
|
+
* @returns The image.
|
|
410
|
+
* @throws {DockerImageNotFoundException} When the daemon finds no image with this ID or name.
|
|
411
|
+
*/
|
|
412
|
+
async getImage(repoTagOrId) {
|
|
413
|
+
const inspectInfo = await this.#client.inspectImage(repoTagOrId);
|
|
414
|
+
return await this.#image(inspectInfo.Id);
|
|
415
|
+
}
|
|
416
|
+
/** Docker Container Operations **/
|
|
417
|
+
/**
|
|
418
|
+
* List the daemon's containers, the stopped ones included (as `docker ps -a`). Each container is inspected, with its
|
|
419
|
+
* image (see {@link Docker.getContainer}); a container removed during the listing is not listed.
|
|
420
|
+
* @returns The containers; an empty list when the component is destroyed during the call.
|
|
421
|
+
*/
|
|
422
|
+
async listContainers() {
|
|
423
|
+
try {
|
|
424
|
+
const rawContainers = await this.#client.listContainers({ all: true }, this.#abortController.signal);
|
|
425
|
+
const containers = await Promise.all(rawContainers.map(async (containerInfo) => {
|
|
426
|
+
try {
|
|
427
|
+
return await this.getContainer(containerInfo.Id);
|
|
428
|
+
}
|
|
429
|
+
catch (e) {
|
|
430
|
+
//Removed since it was listed
|
|
431
|
+
if (e instanceof DockerContainerNotFoundException_js_1.DockerContainerNotFoundException)
|
|
432
|
+
return undefined;
|
|
433
|
+
throw e;
|
|
434
|
+
}
|
|
435
|
+
}));
|
|
436
|
+
return containers.filter((container) => !!container);
|
|
437
|
+
}
|
|
438
|
+
catch (e) {
|
|
439
|
+
if (!(0, utils_1.isAbortError)(e))
|
|
440
|
+
throw e;
|
|
441
|
+
return [];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get a container by its ID, short ID or name, inspected with its image (`image` is `undefined` when its image no
|
|
446
|
+
* longer exists, removed with force). The object is a snapshot: its properties are refreshed by its own operations
|
|
447
|
+
* (`start()`, `stop()`…), not by the changes made by others.
|
|
448
|
+
* @param id The ID, a unique prefix of it, or the name of the container.
|
|
449
|
+
* @returns The container.
|
|
450
|
+
* @throws {DockerContainerNotFoundException} When the daemon has no such container.
|
|
451
|
+
*/
|
|
452
|
+
async getContainer(id) {
|
|
453
|
+
return await this.getObject(DockerContainer_js_1.DockerContainer, {
|
|
454
|
+
getClient: () => this.#client,
|
|
455
|
+
getDocker: () => this,
|
|
456
|
+
id: id
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
async createContainer(imageId, platformOrOptions, settingOptions) {
|
|
460
|
+
//The platform is optional: the one of the image by default
|
|
461
|
+
const platform = typeof platformOrOptions === 'string' ? platformOrOptions : undefined;
|
|
462
|
+
const options = typeof platformOrOptions === 'string' ? settingOptions ?? {} : platformOrOptions;
|
|
463
|
+
const containerEnvRecord = options.env ? options.env : {};
|
|
464
|
+
const rawContainer = await this.#client.createContainer({
|
|
465
|
+
Image: imageId,
|
|
466
|
+
Hostname: options.hostname,
|
|
467
|
+
Tty: options.tty,
|
|
468
|
+
Env: Object.keys(containerEnvRecord).map(envKey => `${envKey}=${containerEnvRecord[envKey]}`),
|
|
469
|
+
Cmd: options.cmd,
|
|
470
|
+
Entrypoint: options.entrypoint,
|
|
471
|
+
HostConfig: {
|
|
472
|
+
Memory: options.memoryLimit,
|
|
473
|
+
CpusetCpus: options.cpuSet ? options.cpuSet.join(',') : undefined,
|
|
474
|
+
Privileged: options.privileged,
|
|
475
|
+
RestartPolicy: options.restartPolicy ? (0, EngineSettings_js_1.engineRestartPolicy)(options.restartPolicy) : undefined,
|
|
476
|
+
OomKillDisable: options.OOMKillDisable,
|
|
477
|
+
PortBindings: (0, EngineSettings_js_1.enginePortBindings)(options.ports ?? []),
|
|
478
|
+
Binds: (0, EngineSettings_js_1.engineBinds)(options.binds ?? []),
|
|
479
|
+
Devices: (0, EngineSettings_js_1.engineDevices)(options.devices ?? []),
|
|
480
|
+
CapAdd: options.capabilities,
|
|
481
|
+
Cgroup: options.cgroup,
|
|
482
|
+
CgroupParent: options.cgroupParent,
|
|
483
|
+
PidMode: options.pidMode
|
|
484
|
+
},
|
|
485
|
+
NetworkingConfig: {
|
|
486
|
+
EndpointsConfig: (0, EngineSettings_js_1.engineEndpoints)(options.networks ?? [])
|
|
487
|
+
}
|
|
488
|
+
}, { name: options.name, platform: platform });
|
|
489
|
+
return await this.getContainer(rawContainer.Id);
|
|
490
|
+
}
|
|
491
|
+
/** Docker Network Operations **/
|
|
492
|
+
/**
|
|
493
|
+
* Create a network, as `docker network create`.
|
|
494
|
+
* @param options The name, the driver (`'bridge'` by default, `'ipvlan'`, `'macvlan'`), its options, the subnets
|
|
495
|
+
* (`NetworkIPAMConfigs`; chosen by the daemon when empty or absent), `internal` and `enableIPv6`.
|
|
496
|
+
* @returns The network created.
|
|
497
|
+
* @throws {DockerRequestException} When the daemon refuses the network: the name already used (HTTP 409), a subnet
|
|
498
|
+
* overlapping another network's (HTTP 400).
|
|
499
|
+
*/
|
|
500
|
+
async createNetwork(options) {
|
|
501
|
+
const network = await this.#client.createNetwork({
|
|
502
|
+
Name: options.name,
|
|
503
|
+
Driver: options.driver,
|
|
504
|
+
Internal: options.internal,
|
|
505
|
+
Options: options.options,
|
|
506
|
+
IPAM: {
|
|
507
|
+
Driver: 'default',
|
|
508
|
+
Options: {},
|
|
509
|
+
Config: (options.NetworkIPAMConfigs ?? []).map((config) => ({
|
|
510
|
+
Subnet: config.subnet,
|
|
511
|
+
IPRange: config.range,
|
|
512
|
+
Gateway: config.gateway
|
|
513
|
+
}))
|
|
514
|
+
},
|
|
515
|
+
EnableIPv6: options.enableIPv6
|
|
516
|
+
});
|
|
517
|
+
return await this.getNetwork(network.Id);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Remove a network, as `docker network rm`.
|
|
521
|
+
* @param id The ID, a unique prefix of it, or the name of the network.
|
|
522
|
+
* @throws {DockerNetworkNotFoundException} When the daemon has no such network.
|
|
523
|
+
* @throws {DockerRequestException} When the network has containers connected (HTTP 409), or is reserved (`bridge`,
|
|
524
|
+
* `host`, `none`: HTTP 403).
|
|
525
|
+
*/
|
|
526
|
+
async removeNetwork(id) {
|
|
527
|
+
const network = await this.getNetwork(id);
|
|
528
|
+
await this.#client.removeNetwork(network.id);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* List the daemon's networks, the reserved ones (`bridge`, `host`, `none`) included.
|
|
532
|
+
* @returns The networks; an empty list when the component is destroyed during the call.
|
|
533
|
+
*/
|
|
534
|
+
async listNetworks() {
|
|
535
|
+
try {
|
|
536
|
+
const rawNetworks = await this.#client.listNetworks(undefined, this.#abortController.signal);
|
|
537
|
+
return rawNetworks.map((rawNetwork) => this.#networkInfo(rawNetwork));
|
|
538
|
+
}
|
|
539
|
+
catch (e) {
|
|
540
|
+
if (!(0, utils_1.isAbortError)(e))
|
|
541
|
+
throw e;
|
|
542
|
+
return [];
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Get a network by its ID, a unique prefix of it, or its name, as `docker network inspect`.
|
|
547
|
+
* @param id The ID, a unique prefix of it, or the name of the network.
|
|
548
|
+
* @returns The network.
|
|
549
|
+
* @throws {DockerNetworkNotFoundException} When the daemon has no such network.
|
|
550
|
+
*/
|
|
551
|
+
async getNetwork(id) {
|
|
552
|
+
return this.#networkInfo(await this.#client.inspectNetwork(id));
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* The information of a network, from the daemon's
|
|
556
|
+
* @param rawNetwork
|
|
557
|
+
*/
|
|
558
|
+
#networkInfo(rawNetwork) {
|
|
559
|
+
return {
|
|
560
|
+
id: rawNetwork.Id,
|
|
561
|
+
name: rawNetwork.Name,
|
|
562
|
+
driver: rawNetwork.Driver,
|
|
563
|
+
reserved: this.#internalNetworkNames.includes(rawNetwork.Name),
|
|
564
|
+
internal: rawNetwork.Internal,
|
|
565
|
+
enableIPv6: rawNetwork.EnableIPv6,
|
|
566
|
+
IPAMConfigs: rawNetwork.IPAM?.Config
|
|
567
|
+
? rawNetwork.IPAM.Config.map((item) => ({
|
|
568
|
+
subnet: item.Subnet,
|
|
569
|
+
range: item.IPRange,
|
|
570
|
+
gateway: item.Gateway
|
|
571
|
+
}))
|
|
572
|
+
: [],
|
|
573
|
+
createdAt: new Time_1.Time(rawNetwork.Created)
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
exports.Docker = Docker;
|
|
578
|
+
__decorate([
|
|
579
|
+
(0, di_1.Configurable)(core_1.DTO.String().optional()),
|
|
580
|
+
__metadata("design:type", Object)
|
|
581
|
+
], Docker.prototype, "socketPath", void 0);
|
|
582
|
+
__decorate([
|
|
583
|
+
(0, di_1.Configurable)(core_1.DTO.String().optional()),
|
|
584
|
+
__metadata("design:type", Object)
|
|
585
|
+
], Docker.prototype, "host", void 0);
|
|
586
|
+
__decorate([
|
|
587
|
+
(0, di_1.Configurable)(core_1.DTO.Alternatives(core_1.DTO.Number().port(), core_1.DTO.String()).optional()),
|
|
588
|
+
__metadata("design:type", Object)
|
|
589
|
+
], Docker.prototype, "port", void 0);
|
|
590
|
+
__decorate([
|
|
591
|
+
(0, di_1.Configurable)(core_1.DTO.String().optional()),
|
|
592
|
+
__metadata("design:type", Object)
|
|
593
|
+
], Docker.prototype, "username", void 0);
|
|
594
|
+
__decorate([
|
|
595
|
+
(0, di_1.Configurable)(core_1.DTO.Object().pattern(core_1.DTO.String(), core_1.DTO.String()).optional()),
|
|
596
|
+
__metadata("design:type", Object)
|
|
597
|
+
], Docker.prototype, "headers", void 0);
|
|
598
|
+
__decorate([
|
|
599
|
+
(0, di_1.Configurable)(core_1.DTO.Alternatives(core_1.DTO.String(), core_1.DTO.Array(core_1.DTO.String()), core_1.DTO.Binary(), core_1.DTO.Array(core_1.DTO.Binary())).optional()),
|
|
600
|
+
__metadata("design:type", Object)
|
|
601
|
+
], Docker.prototype, "ca", void 0);
|
|
602
|
+
__decorate([
|
|
603
|
+
(0, di_1.Configurable)(core_1.DTO.Alternatives(core_1.DTO.String(), core_1.DTO.Array(core_1.DTO.String()), core_1.DTO.Binary(), core_1.DTO.Array(core_1.DTO.Binary())).optional()),
|
|
604
|
+
__metadata("design:type", Object)
|
|
605
|
+
], Docker.prototype, "cert", void 0);
|
|
606
|
+
__decorate([
|
|
607
|
+
(0, di_1.Configurable)(core_1.DTO.Alternatives(core_1.DTO.String(), core_1.DTO.Array(core_1.DTO.String()), core_1.DTO.Binary(), core_1.DTO.Array(core_1.DTO.Binary()), core_1.DTO.Array(core_1.DTO.Object({
|
|
608
|
+
pem: core_1.DTO.Alternatives(core_1.DTO.String(), core_1.DTO.Binary()).required(),
|
|
609
|
+
passphrase: core_1.DTO.String().optional()
|
|
610
|
+
}))).optional()),
|
|
611
|
+
__metadata("design:type", Object)
|
|
612
|
+
], Docker.prototype, "key", void 0);
|
|
613
|
+
__decorate([
|
|
614
|
+
(0, di_1.Configurable)(core_1.DTO.String().valid('https', 'http', 'ssh').optional()),
|
|
615
|
+
__metadata("design:type", Object)
|
|
616
|
+
], Docker.prototype, "protocol", void 0);
|
|
617
|
+
__decorate([
|
|
618
|
+
(0, di_1.Configurable)(core_1.DTO.Number().optional()),
|
|
619
|
+
__metadata("design:type", Object)
|
|
620
|
+
], Docker.prototype, "timeout", void 0);
|
|
621
|
+
__decorate([
|
|
622
|
+
(0, di_1.Configurable)(core_1.DTO.String().optional()),
|
|
623
|
+
__metadata("design:type", Object)
|
|
624
|
+
], Docker.prototype, "version", void 0);
|
|
625
|
+
__decorate([
|
|
626
|
+
(0, di_1.Configurable)(core_1.DTO.String().optional()),
|
|
627
|
+
__metadata("design:type", Object)
|
|
628
|
+
], Docker.prototype, "sshAuthAgent", void 0);
|
|
629
|
+
__decorate([
|
|
630
|
+
(0, dto_1.Accept)(DockerPruneOptions_js_1.DockerPruneOptions.optional()),
|
|
631
|
+
__metadata("design:type", Function),
|
|
632
|
+
__metadata("design:paramtypes", [DockerPruneOptions_js_1.DockerPruneOptions]),
|
|
633
|
+
__metadata("design:returntype", Promise)
|
|
634
|
+
], Docker.prototype, "prune", null);
|
|
635
|
+
__decorate([
|
|
636
|
+
(0, dto_1.Accept)(DockerAuthOptions_js_1.DockerAuthOptions.required()),
|
|
637
|
+
__metadata("design:type", Function),
|
|
638
|
+
__metadata("design:paramtypes", [DockerAuthOptions_js_1.DockerAuthOptions]),
|
|
639
|
+
__metadata("design:returntype", Promise)
|
|
640
|
+
], Docker.prototype, "loginRepository", null);
|
|
641
|
+
__decorate([
|
|
642
|
+
(0, dto_1.Accept)(DockerAuthOptions_js_1.DockerAuthOptions.required()),
|
|
643
|
+
__metadata("design:type", Function),
|
|
644
|
+
__metadata("design:paramtypes", [DockerAuthOptions_js_1.DockerAuthOptions]),
|
|
645
|
+
__metadata("design:returntype", Promise)
|
|
646
|
+
], Docker.prototype, "checkRepositoryAuth", null);
|
|
647
|
+
__decorate([
|
|
648
|
+
(0, dto_1.Accept)(ImagePullOptions_js_1.ImagePullOptions.required()),
|
|
649
|
+
__metadata("design:type", Function),
|
|
650
|
+
__metadata("design:paramtypes", [ImagePullOptions_js_1.ImagePullOptions]),
|
|
651
|
+
__metadata("design:returntype", Promise)
|
|
652
|
+
], Docker.prototype, "pullImage", null);
|
|
653
|
+
__decorate([
|
|
654
|
+
(0, dto_1.Accept)(ImageBuildOptions_js_1.ImageBuildOptions.required()),
|
|
655
|
+
__metadata("design:type", Function),
|
|
656
|
+
__metadata("design:paramtypes", [ImageBuildOptions_js_1.ImageBuildOptions]),
|
|
657
|
+
__metadata("design:returntype", Promise)
|
|
658
|
+
], Docker.prototype, "buildImage", null);
|
|
659
|
+
__decorate([
|
|
660
|
+
(0, dto_1.Accept)(ImageImportOptions_js_1.ImageImportOptions.required()),
|
|
661
|
+
__metadata("design:type", Function),
|
|
662
|
+
__metadata("design:paramtypes", [ImageImportOptions_js_1.ImageImportOptions]),
|
|
663
|
+
__metadata("design:returntype", Promise)
|
|
664
|
+
], Docker.prototype, "importImage", null);
|
|
665
|
+
__decorate([
|
|
666
|
+
(0, dto_1.Accept)(core_1.DTO.String().required()),
|
|
667
|
+
__metadata("design:type", Function),
|
|
668
|
+
__metadata("design:paramtypes", [String]),
|
|
669
|
+
__metadata("design:returntype", Promise)
|
|
670
|
+
], Docker.prototype, "getImage", null);
|
|
671
|
+
__decorate([
|
|
672
|
+
(0, dto_1.Accept)(core_1.DTO.String().required()),
|
|
673
|
+
__metadata("design:type", Function),
|
|
674
|
+
__metadata("design:paramtypes", [String]),
|
|
675
|
+
__metadata("design:returntype", Promise)
|
|
676
|
+
], Docker.prototype, "getContainer", null);
|
|
677
|
+
__decorate([
|
|
678
|
+
(0, dto_1.Accept)(core_1.DTO.String().required(), core_1.DTO.Alternatives(core_1.DTO.String(), ContainerSettingOptions_js_1.ContainerSettingOptions.required()).required(), ContainerSettingOptions_js_1.ContainerSettingOptions.optional()),
|
|
679
|
+
__metadata("design:type", Function),
|
|
680
|
+
__metadata("design:paramtypes", [String, Object, ContainerSettingOptions_js_1.ContainerSettingOptions]),
|
|
681
|
+
__metadata("design:returntype", Promise)
|
|
682
|
+
], Docker.prototype, "createContainer", null);
|
|
683
|
+
__decorate([
|
|
684
|
+
(0, dto_1.Accept)(NetworkCreateOptions_js_1.NetworkCreateOptions.required()),
|
|
685
|
+
__metadata("design:type", Function),
|
|
686
|
+
__metadata("design:paramtypes", [NetworkCreateOptions_js_1.NetworkCreateOptions]),
|
|
687
|
+
__metadata("design:returntype", Promise)
|
|
688
|
+
], Docker.prototype, "createNetwork", null);
|
|
689
|
+
__decorate([
|
|
690
|
+
(0, dto_1.Accept)(core_1.DTO.String().required()),
|
|
691
|
+
__metadata("design:type", Function),
|
|
692
|
+
__metadata("design:paramtypes", [String]),
|
|
693
|
+
__metadata("design:returntype", Promise)
|
|
694
|
+
], Docker.prototype, "removeNetwork", null);
|
|
695
|
+
__decorate([
|
|
696
|
+
(0, dto_1.Accept)(core_1.DTO.String().required()),
|
|
697
|
+
__metadata("design:type", Function),
|
|
698
|
+
__metadata("design:paramtypes", [String]),
|
|
699
|
+
__metadata("design:returntype", Promise)
|
|
700
|
+
], Docker.prototype, "getNetwork", null);
|
|
701
|
+
exports.Docker = Docker = __decorate([
|
|
702
|
+
(0, di_1.Singleton)()
|
|
703
|
+
], Docker);
|