@augment-vir/node 31.43.3 → 31.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/augments/npm/npm-deps.d.ts +38 -0
- package/dist/augments/npm/npm-deps.js +47 -0
- package/dist/augments/npm/package-json.d.ts +21 -0
- package/dist/augments/npm/package-json.js +48 -0
- package/dist/file-paths.mock.d.ts +0 -6
- package/dist/file-paths.mock.js +0 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +4 -6
- package/src/augments/npm/npm-deps.ts +85 -0
- package/src/augments/npm/package-json.ts +75 -0
- package/src/file-paths.mock.ts +0 -7
- package/src/index.ts +2 -1
- package/dist/augments/docker.d.ts +0 -92
- package/dist/augments/docker.js +0 -87
- package/dist/docker/containers/container-info.d.ts +0 -57
- package/dist/docker/containers/container-info.js +0 -18
- package/dist/docker/containers/container-status.d.ts +0 -32
- package/dist/docker/containers/container-status.js +0 -68
- package/dist/docker/containers/copy-to-container.d.ts +0 -14
- package/dist/docker/containers/copy-to-container.js +0 -10
- package/dist/docker/containers/docker-command-inputs.d.ts +0 -74
- package/dist/docker/containers/docker-command-inputs.js +0 -45
- package/dist/docker/containers/kill-container.d.ts +0 -10
- package/dist/docker/containers/kill-container.js +0 -12
- package/dist/docker/containers/run-command.d.ts +0 -18
- package/dist/docker/containers/run-command.js +0 -24
- package/dist/docker/containers/run-container.d.ts +0 -23
- package/dist/docker/containers/run-container.js +0 -47
- package/dist/docker/containers/run-container.mock.d.ts +0 -2
- package/dist/docker/containers/run-container.mock.js +0 -16
- package/dist/docker/containers/try-or-kill-container.d.ts +0 -6
- package/dist/docker/containers/try-or-kill-container.js +0 -14
- package/dist/docker/docker-image.d.ts +0 -9
- package/dist/docker/docker-image.js +0 -50
- package/dist/docker/docker-startup.d.ts +0 -2
- package/dist/docker/docker-startup.js +0 -39
- package/dist/docker/run-docker-test.mock.d.ts +0 -2
- package/dist/docker/run-docker-test.mock.js +0 -23
- package/src/augments/docker.ts +0 -119
- package/src/docker/containers/container-info.ts +0 -83
- package/src/docker/containers/container-status.ts +0 -110
- package/src/docker/containers/copy-to-container.ts +0 -34
- package/src/docker/containers/docker-command-inputs.ts +0 -122
- package/src/docker/containers/kill-container.ts +0 -25
- package/src/docker/containers/run-command.ts +0 -51
- package/src/docker/containers/run-container.mock.ts +0 -22
- package/src/docker/containers/run-container.ts +0 -92
- package/src/docker/containers/try-or-kill-container.ts +0 -18
- package/src/docker/docker-image.ts +0 -61
- package/src/docker/docker-startup.ts +0 -49
- package/src/docker/run-docker-test.mock.ts +0 -26
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type JsonCompatibleArray, type JsonCompatibleObject } from '@augment-vir/common';
|
|
2
|
-
import { type DockerContainerStatus } from './container-status.js';
|
|
3
|
-
/**
|
|
4
|
-
* Properties on {@link DockerContainerInfo}.State, retrieved from `docker.container.getInfo()`.
|
|
5
|
-
*
|
|
6
|
-
* @category Node : Docker : Util
|
|
7
|
-
* @category Package : @augment-vir/node
|
|
8
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
|
-
*/
|
|
10
|
-
export type DockerContainerInfoState = {
|
|
11
|
-
Status: DockerContainerStatus;
|
|
12
|
-
Running: boolean;
|
|
13
|
-
Paused: boolean;
|
|
14
|
-
Restarting: boolean;
|
|
15
|
-
OOMKilled: boolean;
|
|
16
|
-
Dead: boolean;
|
|
17
|
-
Pid: number;
|
|
18
|
-
ExitCode: number;
|
|
19
|
-
Error: string;
|
|
20
|
-
StartedAt: string;
|
|
21
|
-
FinishedAt: string;
|
|
22
|
-
};
|
|
23
|
-
/** This type signature is incomplete. Add to it as necessary. */
|
|
24
|
-
/**
|
|
25
|
-
* Properties on the output from `docker.container.getInfo()`. Not all these properties are filled
|
|
26
|
-
* in all the way, particularly most of properties with nested objects.
|
|
27
|
-
*
|
|
28
|
-
* @category Node : Docker : Util
|
|
29
|
-
* @category Package : @augment-vir/node
|
|
30
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
31
|
-
*/
|
|
32
|
-
export type DockerContainerInfo = Readonly<{
|
|
33
|
-
Id: string;
|
|
34
|
-
Created: string;
|
|
35
|
-
Path: string;
|
|
36
|
-
Args: ReadonlyArray<string>;
|
|
37
|
-
State: DockerContainerInfoState;
|
|
38
|
-
Image: string;
|
|
39
|
-
ResolvConfPath: string;
|
|
40
|
-
HostnamePath: string;
|
|
41
|
-
HostsPath: string;
|
|
42
|
-
LogPath: string;
|
|
43
|
-
Name: string;
|
|
44
|
-
RestartCount: number;
|
|
45
|
-
Driver: string;
|
|
46
|
-
Platform: string;
|
|
47
|
-
MountLabel: string;
|
|
48
|
-
ProcessLabel: string;
|
|
49
|
-
AppArmorProfile: string;
|
|
50
|
-
ExecIDs: unknown;
|
|
51
|
-
HostConfig: JsonCompatibleObject;
|
|
52
|
-
GraphDriver: JsonCompatibleObject;
|
|
53
|
-
Mounts: JsonCompatibleArray;
|
|
54
|
-
Config: JsonCompatibleObject;
|
|
55
|
-
NetworkSettings: JsonCompatibleObject;
|
|
56
|
-
}>;
|
|
57
|
-
export declare function getContainerInfo(containerNameOrId: string): Promise<DockerContainerInfo | undefined>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
2
|
-
export async function getContainerInfo(containerNameOrId) {
|
|
3
|
-
const command = `docker inspect '${containerNameOrId}'`;
|
|
4
|
-
const output = await runShellCommand(command);
|
|
5
|
-
if (output.stderr.includes('Error: No such object')) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const parsedOutput = JSON.parse(output.stdout);
|
|
9
|
-
/** Edge cases that I don't know how to intentionally trigger. */
|
|
10
|
-
/* node:coverage ignore next 5 */
|
|
11
|
-
if (parsedOutput.length === 0) {
|
|
12
|
-
throw new Error(`Got no output from "${command}"`);
|
|
13
|
-
}
|
|
14
|
-
else if (parsedOutput.length > 1) {
|
|
15
|
-
throw new Error(`Got more than one output from "${command}"`);
|
|
16
|
-
}
|
|
17
|
-
return parsedOutput[0];
|
|
18
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare function getContainerLogs(containerNameOrId: string, latestLineCount?: number): Promise<string>;
|
|
2
|
-
/**
|
|
3
|
-
* All possible statuses for an existing container.
|
|
4
|
-
*
|
|
5
|
-
* @category Node : Docker : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export declare enum DockerContainerStatus {
|
|
10
|
-
Created = "created",
|
|
11
|
-
Running = "running",
|
|
12
|
-
Paused = "paused",
|
|
13
|
-
Restarting = "restarting",
|
|
14
|
-
Exited = "exited",
|
|
15
|
-
Removing = "removing",
|
|
16
|
-
Dead = "dead",
|
|
17
|
-
/** This is not a native Docker status but indicates that the container does not exist. */
|
|
18
|
-
Removed = "removed"
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Statuses from {@link DockerContainerStatus} that indicate that a container has been exited in some
|
|
22
|
-
* way.
|
|
23
|
-
*
|
|
24
|
-
* @category Node : Docker : Util
|
|
25
|
-
* @category Package : @augment-vir/node
|
|
26
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
27
|
-
*/
|
|
28
|
-
export declare const exitedDockerContainerStatuses: DockerContainerStatus[];
|
|
29
|
-
export declare function getContainerStatus(containerNameOrId: string): Promise<DockerContainerStatus>;
|
|
30
|
-
export declare function waitUntilContainerRunning(containerNameOrId: string, failureMessage?: string | undefined): Promise<void>;
|
|
31
|
-
export declare function waitUntilContainerRemoved(containerNameOrId: string, failureMessage?: string | undefined): Promise<void>;
|
|
32
|
-
export declare function waitUntilContainerExited(containerNameOrId: string, failureMessage?: string | undefined): Promise<void>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { assert, waitUntil } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
|
-
export async function getContainerLogs(containerNameOrId, latestLineCount) {
|
|
4
|
-
const latestLinesArg = latestLineCount == undefined ? '' : `--tail ${latestLineCount}`;
|
|
5
|
-
const logResult = await runShellCommand(`docker logs ${latestLinesArg} '${containerNameOrId}'`, { rejectOnError: true });
|
|
6
|
-
return logResult.stdout;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* All possible statuses for an existing container.
|
|
10
|
-
*
|
|
11
|
-
* @category Node : Docker : Util
|
|
12
|
-
* @category Package : @augment-vir/node
|
|
13
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
14
|
-
*/
|
|
15
|
-
export var DockerContainerStatus;
|
|
16
|
-
(function (DockerContainerStatus) {
|
|
17
|
-
DockerContainerStatus["Created"] = "created";
|
|
18
|
-
DockerContainerStatus["Running"] = "running";
|
|
19
|
-
DockerContainerStatus["Paused"] = "paused";
|
|
20
|
-
DockerContainerStatus["Restarting"] = "restarting";
|
|
21
|
-
DockerContainerStatus["Exited"] = "exited";
|
|
22
|
-
DockerContainerStatus["Removing"] = "removing";
|
|
23
|
-
DockerContainerStatus["Dead"] = "dead";
|
|
24
|
-
/** This is not a native Docker status but indicates that the container does not exist. */
|
|
25
|
-
DockerContainerStatus["Removed"] = "removed";
|
|
26
|
-
})(DockerContainerStatus || (DockerContainerStatus = {}));
|
|
27
|
-
/**
|
|
28
|
-
* Statuses from {@link DockerContainerStatus} that indicate that a container has been exited in some
|
|
29
|
-
* way.
|
|
30
|
-
*
|
|
31
|
-
* @category Node : Docker : Util
|
|
32
|
-
* @category Package : @augment-vir/node
|
|
33
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
34
|
-
*/
|
|
35
|
-
export const exitedDockerContainerStatuses = [
|
|
36
|
-
DockerContainerStatus.Dead,
|
|
37
|
-
DockerContainerStatus.Removed,
|
|
38
|
-
DockerContainerStatus.Exited,
|
|
39
|
-
];
|
|
40
|
-
export async function getContainerStatus(containerNameOrId) {
|
|
41
|
-
const statusResult = await runShellCommand(`docker container inspect -f '{{.State.Status}}' '${containerNameOrId}'`);
|
|
42
|
-
if (statusResult.exitCode !== 0) {
|
|
43
|
-
return DockerContainerStatus.Removed;
|
|
44
|
-
}
|
|
45
|
-
const status = statusResult.stdout.trim();
|
|
46
|
-
assert.isEnumValue(status, DockerContainerStatus, 'Unexpected container status value');
|
|
47
|
-
return status;
|
|
48
|
-
}
|
|
49
|
-
export async function waitUntilContainerRunning(containerNameOrId, failureMessage) {
|
|
50
|
-
await waitUntil.isTrue(async () => {
|
|
51
|
-
/** Check if logs can be accessed yet. */
|
|
52
|
-
await getContainerLogs(containerNameOrId, 1);
|
|
53
|
-
const status = await getContainerStatus(containerNameOrId);
|
|
54
|
-
return status === DockerContainerStatus.Running;
|
|
55
|
-
}, {}, failureMessage);
|
|
56
|
-
}
|
|
57
|
-
export async function waitUntilContainerRemoved(containerNameOrId, failureMessage) {
|
|
58
|
-
await waitUntil.isTrue(async () => {
|
|
59
|
-
const status = await getContainerStatus(containerNameOrId);
|
|
60
|
-
return status === DockerContainerStatus.Removed;
|
|
61
|
-
}, {}, failureMessage);
|
|
62
|
-
}
|
|
63
|
-
export async function waitUntilContainerExited(containerNameOrId, failureMessage) {
|
|
64
|
-
await waitUntil.isTrue(async () => {
|
|
65
|
-
const status = await getContainerStatus(containerNameOrId);
|
|
66
|
-
return exitedDockerContainerStatuses.includes(status);
|
|
67
|
-
}, {}, failureMessage);
|
|
68
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parameters for `docker.container.copyTo`.
|
|
3
|
-
*
|
|
4
|
-
* @category Node : Docker : Util
|
|
5
|
-
* @category Package : @augment-vir/node
|
|
6
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
7
|
-
*/
|
|
8
|
-
export type CopyToDockerContainerParams = {
|
|
9
|
-
hostPath: string;
|
|
10
|
-
containerAbsolutePath: string;
|
|
11
|
-
containerNameOrId: string;
|
|
12
|
-
dockerFlags?: ReadonlyArray<string>;
|
|
13
|
-
};
|
|
14
|
-
export declare function copyToContainer({ containerAbsolutePath, hostPath, containerNameOrId, dockerFlags, }: CopyToDockerContainerParams): Promise<void>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { addSuffix } from '@augment-vir/common';
|
|
2
|
-
import { stat } from 'node:fs/promises';
|
|
3
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
4
|
-
export async function copyToContainer({ containerAbsolutePath, hostPath, containerNameOrId, dockerFlags = [], }) {
|
|
5
|
-
const isDir = (await stat(hostPath)).isDirectory();
|
|
6
|
-
const suffix = isDir ? '/.' : '';
|
|
7
|
-
const fullHostPath = addSuffix({ value: hostPath, suffix });
|
|
8
|
-
const extraInputs = dockerFlags.join(' ');
|
|
9
|
-
await runShellCommand(`docker cp ${extraInputs} '${fullHostPath}' '${containerNameOrId}:${containerAbsolutePath}'`, { rejectOnError: true });
|
|
10
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
|
|
3
|
-
* Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
|
|
4
|
-
* empty (`undefined`).
|
|
5
|
-
*
|
|
6
|
-
* @category Node : Docker : Util
|
|
7
|
-
* @category Package : @augment-vir/node
|
|
8
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
9
|
-
*/
|
|
10
|
-
export declare enum DockerVolumeMappingType {
|
|
11
|
-
Cached = "cached",
|
|
12
|
-
Delegated = "delegated"
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A mapping of a single docker volume for mounting host files to a container.
|
|
16
|
-
*
|
|
17
|
-
* @category Node : Docker : Util
|
|
18
|
-
* @category Package : @augment-vir/node
|
|
19
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
20
|
-
*/
|
|
21
|
-
export type DockerVolumeMap = {
|
|
22
|
-
hostAbsolutePath: string;
|
|
23
|
-
containerAbsolutePath: string;
|
|
24
|
-
type?: DockerVolumeMappingType | undefined;
|
|
25
|
-
};
|
|
26
|
-
export declare function makeVolumeFlags(volumeMapping?: ReadonlyArray<DockerVolumeMap>): string;
|
|
27
|
-
/**
|
|
28
|
-
* A single docker container port mapping. This is usually used in an array.
|
|
29
|
-
*
|
|
30
|
-
* @category Node : Docker : Util
|
|
31
|
-
* @category Package : @augment-vir/node
|
|
32
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
33
|
-
*/
|
|
34
|
-
export type DockerPortMap = {
|
|
35
|
-
hostPort: number;
|
|
36
|
-
containerPort: number;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* A set of environment mappings for a docker container.
|
|
40
|
-
*
|
|
41
|
-
* - Each key in this object represents the env var name within the Docker container.
|
|
42
|
-
* - Each `value` property can be either the value that the env var should be set to _or_ an existing
|
|
43
|
-
* env var's interpolation into the value.
|
|
44
|
-
* - If the value string is meant to be interpolated within the shell context, make sure to set
|
|
45
|
-
* `allowInterpolation` to `true`. Otherwise, it's best to leave it as `false`.
|
|
46
|
-
*
|
|
47
|
-
* @category Node : Docker : Util
|
|
48
|
-
* @category Package : @augment-vir/node
|
|
49
|
-
* @example
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* const envMapping: DockerEnvMap = {
|
|
53
|
-
* VAR_1: {
|
|
54
|
-
* value: 'hi',
|
|
55
|
-
* // set to false because this is a raw string value that is not meant to be interpolated
|
|
56
|
-
* allowInterpolation: false,
|
|
57
|
-
* },
|
|
58
|
-
* VAR_2: {
|
|
59
|
-
* // the value here will be interpolated from the current shell's value for `EXISTING_VAR`
|
|
60
|
-
* value: '$EXISTING_VAR',
|
|
61
|
-
* // set to true to allow '$EXISTING_VAR' to be interpolated by the shell
|
|
62
|
-
* allowInterpolation: true,
|
|
63
|
-
* },
|
|
64
|
-
* };
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
68
|
-
*/
|
|
69
|
-
export type DockerEnvMap<RequiredKeys extends string = string> = Readonly<Record<RequiredKeys | string, {
|
|
70
|
-
value: string;
|
|
71
|
-
allowInterpolation: boolean;
|
|
72
|
-
}>>;
|
|
73
|
-
export declare function makePortMapFlags(portMapping?: ReadonlyArray<DockerPortMap> | undefined): string;
|
|
74
|
-
export declare function makeEnvFlags(envMapping?: DockerEnvMap | undefined): string;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { wrapString } from '@augment-vir/common';
|
|
2
|
-
/**
|
|
3
|
-
* Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
|
|
4
|
-
* Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
|
|
5
|
-
* empty (`undefined`).
|
|
6
|
-
*
|
|
7
|
-
* @category Node : Docker : Util
|
|
8
|
-
* @category Package : @augment-vir/node
|
|
9
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
10
|
-
*/
|
|
11
|
-
export var DockerVolumeMappingType;
|
|
12
|
-
(function (DockerVolumeMappingType) {
|
|
13
|
-
DockerVolumeMappingType["Cached"] = "cached";
|
|
14
|
-
DockerVolumeMappingType["Delegated"] = "delegated";
|
|
15
|
-
})(DockerVolumeMappingType || (DockerVolumeMappingType = {}));
|
|
16
|
-
export function makeVolumeFlags(volumeMapping) {
|
|
17
|
-
if (!volumeMapping) {
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
const parts = volumeMapping.map((volume) => {
|
|
21
|
-
const mountType = volume.type ? `:${volume.type}` : '';
|
|
22
|
-
return `-v '${volume.hostAbsolutePath}':'${volume.containerAbsolutePath}'${mountType}`;
|
|
23
|
-
});
|
|
24
|
-
return parts.join(' ');
|
|
25
|
-
}
|
|
26
|
-
export function makePortMapFlags(portMapping) {
|
|
27
|
-
if (!portMapping) {
|
|
28
|
-
return '';
|
|
29
|
-
}
|
|
30
|
-
return portMapping
|
|
31
|
-
.map((portMap) => {
|
|
32
|
-
return `-p ${portMap.hostPort}:${portMap.containerPort}`;
|
|
33
|
-
})
|
|
34
|
-
.join(' ');
|
|
35
|
-
}
|
|
36
|
-
export function makeEnvFlags(envMapping) {
|
|
37
|
-
if (!envMapping) {
|
|
38
|
-
return '';
|
|
39
|
-
}
|
|
40
|
-
const flags = Object.entries(envMapping).map(([key, { value, allowInterpolation },]) => {
|
|
41
|
-
const quote = allowInterpolation ? '"' : "'";
|
|
42
|
-
return `-e ${key}=${wrapString({ value, wrapper: quote })}`;
|
|
43
|
-
});
|
|
44
|
-
return flags.join(' ');
|
|
45
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type PartialWithUndefined } from '@augment-vir/core';
|
|
2
|
-
export declare function killContainer(containerNameOrId: string, options?: PartialWithUndefined<{
|
|
3
|
-
/**
|
|
4
|
-
* If set to `true`, the container will be killed but won't be removed. (You'll still see it
|
|
5
|
-
* in your Docker Dashboard but it'll have a status of exited.)
|
|
6
|
-
*
|
|
7
|
-
* @default false
|
|
8
|
-
*/
|
|
9
|
-
keepContainer: boolean;
|
|
10
|
-
}>): Promise<void>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
2
|
-
import { waitUntilContainerExited, waitUntilContainerRemoved } from './container-status.js';
|
|
3
|
-
export async function killContainer(containerNameOrId, options = {}) {
|
|
4
|
-
await runShellCommand(`docker kill '${containerNameOrId}'`);
|
|
5
|
-
if (options.keepContainer) {
|
|
6
|
-
await waitUntilContainerExited(containerNameOrId);
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
await runShellCommand(`docker rm '${containerNameOrId}'`);
|
|
10
|
-
await waitUntilContainerRemoved(containerNameOrId);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type DockerEnvMap } from './docker-command-inputs.js';
|
|
2
|
-
/**
|
|
3
|
-
* Parameters for `docker.container.runCommand`.
|
|
4
|
-
*
|
|
5
|
-
* @category Node : Docker : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export type RunDockerContainerCommandParams = {
|
|
10
|
-
/** Creates an interactive shell connection. */
|
|
11
|
-
tty?: boolean | undefined;
|
|
12
|
-
containerNameOrId: string;
|
|
13
|
-
command: string;
|
|
14
|
-
envMapping?: DockerEnvMap | undefined;
|
|
15
|
-
executionEnv?: Record<string, string> | undefined;
|
|
16
|
-
dockerFlags?: ReadonlyArray<string> | undefined;
|
|
17
|
-
};
|
|
18
|
-
export declare function runContainerCommand({ tty, containerNameOrId, command, envMapping, executionEnv, dockerFlags, }: RunDockerContainerCommandParams): Promise<import("../../augments/terminal/shell.js").ShellOutput>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
|
-
import { makeEnvFlags } from './docker-command-inputs.js';
|
|
4
|
-
export async function runContainerCommand({ tty, containerNameOrId, command, envMapping, executionEnv, dockerFlags = [], }) {
|
|
5
|
-
const envFlags = makeEnvFlags(envMapping);
|
|
6
|
-
/** Can't test tty in automated tests. */
|
|
7
|
-
/* node:coverage ignore next 1 */
|
|
8
|
-
const ttyFlag = tty ? '-it' : '';
|
|
9
|
-
const fullCommand = [
|
|
10
|
-
'docker',
|
|
11
|
-
'exec',
|
|
12
|
-
ttyFlag,
|
|
13
|
-
envFlags,
|
|
14
|
-
...dockerFlags,
|
|
15
|
-
containerNameOrId,
|
|
16
|
-
command,
|
|
17
|
-
]
|
|
18
|
-
.filter(check.isTruthy)
|
|
19
|
-
.join(' ');
|
|
20
|
-
return await runShellCommand(fullCommand, {
|
|
21
|
-
env: executionEnv,
|
|
22
|
-
rejectOnError: true,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type DockerEnvMap, type DockerPortMap, type DockerVolumeMap } from './docker-command-inputs.js';
|
|
2
|
-
/**
|
|
3
|
-
* Parameters for `docker.container.run`.
|
|
4
|
-
*
|
|
5
|
-
* @category Node : Docker : Util
|
|
6
|
-
* @category Package : @augment-vir/node
|
|
7
|
-
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
|
|
8
|
-
*/
|
|
9
|
-
export type RunDockerContainerParams = {
|
|
10
|
-
imageName: string;
|
|
11
|
-
detach: boolean;
|
|
12
|
-
command?: string;
|
|
13
|
-
containerName: string;
|
|
14
|
-
volumeMapping?: ReadonlyArray<DockerVolumeMap> | undefined;
|
|
15
|
-
portMapping?: ReadonlyArray<DockerPortMap> | undefined;
|
|
16
|
-
envMapping?: DockerEnvMap | undefined;
|
|
17
|
-
executionEnv?: Record<string, string>;
|
|
18
|
-
removeWhenDone?: boolean;
|
|
19
|
-
dockerFlags?: ReadonlyArray<string>;
|
|
20
|
-
useCurrentUser?: boolean;
|
|
21
|
-
platform?: string;
|
|
22
|
-
};
|
|
23
|
-
export declare function runContainer({ containerName, imageName, detach, command, portMapping, volumeMapping, envMapping, executionEnv, removeWhenDone, useCurrentUser, dockerFlags, platform, }: RunDockerContainerParams): Promise<void>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { runShellCommand } from '../../augments/terminal/shell.js';
|
|
3
|
-
import { updateImage } from '../docker-image.js';
|
|
4
|
-
import { waitUntilContainerRunning } from './container-status.js';
|
|
5
|
-
import { makeEnvFlags, makePortMapFlags, makeVolumeFlags, } from './docker-command-inputs.js';
|
|
6
|
-
import { killContainer } from './kill-container.js';
|
|
7
|
-
export async function runContainer({ containerName, imageName, detach, command, portMapping, volumeMapping, envMapping, executionEnv, removeWhenDone, useCurrentUser, dockerFlags = [], platform, }) {
|
|
8
|
-
try {
|
|
9
|
-
const portMapFlags = makePortMapFlags(portMapping);
|
|
10
|
-
const envFlags = makeEnvFlags(envMapping);
|
|
11
|
-
const detachFlag = detach ? '-d' : '';
|
|
12
|
-
const volumeMapFlags = makeVolumeFlags(volumeMapping);
|
|
13
|
-
const rmFlag = removeWhenDone ? '--rm' : '';
|
|
14
|
-
const userFlag = useCurrentUser ? '--user "$(id -u)":"$(id -g)"' : '';
|
|
15
|
-
await updateImage(imageName, platform);
|
|
16
|
-
const fullCommand = [
|
|
17
|
-
'docker',
|
|
18
|
-
'run',
|
|
19
|
-
portMapFlags,
|
|
20
|
-
userFlag,
|
|
21
|
-
volumeMapFlags,
|
|
22
|
-
envFlags,
|
|
23
|
-
rmFlag,
|
|
24
|
-
detachFlag,
|
|
25
|
-
`--name='${containerName}'`,
|
|
26
|
-
...dockerFlags,
|
|
27
|
-
imageName,
|
|
28
|
-
command,
|
|
29
|
-
]
|
|
30
|
-
.filter(check.isTruthy)
|
|
31
|
-
.join(' ');
|
|
32
|
-
await runShellCommand(fullCommand, {
|
|
33
|
-
env: executionEnv,
|
|
34
|
-
rejectOnError: true,
|
|
35
|
-
});
|
|
36
|
-
if (removeWhenDone) {
|
|
37
|
-
await killContainer(containerName);
|
|
38
|
-
}
|
|
39
|
-
else if (detach) {
|
|
40
|
-
await waitUntilContainerRunning(containerName);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
await killContainer(containerName);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { docker } from '../../augments/docker.js';
|
|
3
|
-
export async function runMockLongLivingContainer(containerName, args = {}) {
|
|
4
|
-
await docker.container.run({
|
|
5
|
-
containerName,
|
|
6
|
-
detach: true,
|
|
7
|
-
imageName: 'alpine:3.20.2',
|
|
8
|
-
dockerFlags: [
|
|
9
|
-
'-i',
|
|
10
|
-
'-t',
|
|
11
|
-
],
|
|
12
|
-
command: 'sh',
|
|
13
|
-
platform: 'amd64',
|
|
14
|
-
...args,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type MaybePromise } from '@augment-vir/core';
|
|
2
|
-
/**
|
|
3
|
-
* Runs a callback (which presumably runs a command within the given `containerName`) and kills the
|
|
4
|
-
* given `containerName` container if the callback fails.
|
|
5
|
-
*/
|
|
6
|
-
export declare function tryOrKillContainer<T>(containerNameOrId: string, callback: (containerNameOrId: string) => MaybePromise<T>): Promise<Awaited<T>>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { killContainer } from './kill-container.js';
|
|
2
|
-
/**
|
|
3
|
-
* Runs a callback (which presumably runs a command within the given `containerName`) and kills the
|
|
4
|
-
* given `containerName` container if the callback fails.
|
|
5
|
-
*/
|
|
6
|
-
export async function tryOrKillContainer(containerNameOrId, callback) {
|
|
7
|
-
try {
|
|
8
|
-
return await callback(containerNameOrId);
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
await killContainer(containerNameOrId);
|
|
12
|
-
throw error;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare function updateImage(
|
|
2
|
-
/** @example 'alpine:3.20.2' */
|
|
3
|
-
imageName: string, platform?: string): Promise<void>;
|
|
4
|
-
export declare function isImageInLocalRegistry(
|
|
5
|
-
/** @example 'alpine:3.20.2' */
|
|
6
|
-
imageName: string): Promise<boolean>;
|
|
7
|
-
export declare function removeImageFromLocalRegistry(
|
|
8
|
-
/** @example 'alpine:3.20.2' */
|
|
9
|
-
imageName: string): Promise<void>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { wrapString } from '@augment-vir/common';
|
|
2
|
-
import { ensureError } from '@augment-vir/core';
|
|
3
|
-
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
4
|
-
export async function updateImage(
|
|
5
|
-
/** @example 'alpine:3.20.2' */
|
|
6
|
-
imageName, platform) {
|
|
7
|
-
if (await isImageInLocalRegistry(imageName)) {
|
|
8
|
-
/** If image already exists then we don't need to update it. */
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const command = [
|
|
12
|
-
'docker',
|
|
13
|
-
'pull',
|
|
14
|
-
...(platform
|
|
15
|
-
? [
|
|
16
|
-
'--platform',
|
|
17
|
-
platform,
|
|
18
|
-
]
|
|
19
|
-
: []),
|
|
20
|
-
wrapString({ value: imageName, wrapper: "'" }),
|
|
21
|
-
].join(' ');
|
|
22
|
-
await runShellCommand(command, {
|
|
23
|
-
rejectOnError: true,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export async function isImageInLocalRegistry(
|
|
27
|
-
/** @example 'alpine:3.20.2' */
|
|
28
|
-
imageName) {
|
|
29
|
-
const output = await runShellCommand(`docker inspect '${imageName}'`);
|
|
30
|
-
return output.exitCode === 0;
|
|
31
|
-
}
|
|
32
|
-
export async function removeImageFromLocalRegistry(
|
|
33
|
-
/** @example 'alpine:3.20.2' */
|
|
34
|
-
imageName) {
|
|
35
|
-
try {
|
|
36
|
-
await runShellCommand(`docker image rm '${imageName}'`, {
|
|
37
|
-
rejectOnError: true,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (caught) {
|
|
41
|
-
const error = ensureError(caught);
|
|
42
|
-
if (error.message.includes('No such image:')) {
|
|
43
|
-
/** Ignore the case where the image has already been deleted. */
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
/** An edge case that I don't know how to intentionally trigger. */
|
|
47
|
-
/* node:coverage ignore next 2 */
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { waitUntil } from '@augment-vir/assert';
|
|
2
|
-
import { currentOperatingSystem, OperatingSystem } from '../augments/os/operating-system.js';
|
|
3
|
-
import { runShellCommand } from '../augments/terminal/shell.js';
|
|
4
|
-
export async function isDockerRunning() {
|
|
5
|
-
const output = await runShellCommand('docker info');
|
|
6
|
-
return output.exitCode === 0;
|
|
7
|
-
}
|
|
8
|
-
const startDockerCommands = {
|
|
9
|
-
/**
|
|
10
|
-
* Officially supported for the following distros:
|
|
11
|
-
*
|
|
12
|
-
* - [Ubuntu](https://docs.docker.com/desktop/install/ubuntu/#launch-docker-desktop)
|
|
13
|
-
* - [Debian](https://docs.docker.com/desktop/install/debian/#launch-docker-desktop)
|
|
14
|
-
* - [Fedora](https://docs.docker.com/desktop/install/fedora/#launch-docker-desktop)
|
|
15
|
-
* - [Arch](https://docs.docker.com/desktop/install/archlinux/#launch-docker-desktop)
|
|
16
|
-
*/
|
|
17
|
-
[OperatingSystem.Linux]: 'systemctl --user start docker-desktop',
|
|
18
|
-
[OperatingSystem.Mac]: 'open -a Docker',
|
|
19
|
-
[OperatingSystem.Windows]: String.raw `/c/Program\ Files/Docker/Docker/Docker\ Desktop.exe`,
|
|
20
|
-
};
|
|
21
|
-
export async function startDocker() {
|
|
22
|
-
const command = startDockerCommands[currentOperatingSystem];
|
|
23
|
-
/* node:coverage disable */
|
|
24
|
-
if (await isDockerRunning()) {
|
|
25
|
-
/** Docker is already running. Nothing to do. */
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
await waitUntil.isTrue(async () => {
|
|
29
|
-
await runShellCommand(command, { rejectOnError: true });
|
|
30
|
-
return isDockerRunning();
|
|
31
|
-
}, {
|
|
32
|
-
interval: {
|
|
33
|
-
seconds: 1,
|
|
34
|
-
},
|
|
35
|
-
timeout: {
|
|
36
|
-
minutes: 1,
|
|
37
|
-
},
|
|
38
|
-
}, 'Failed to start Docker.');
|
|
39
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isOperatingSystem, OperatingSystem } from '../augments/os/operating-system.js';
|
|
2
|
-
export function dockerTest(callback) {
|
|
3
|
-
if (!isOperatingSystem(OperatingSystem.Linux) && process.env.CI) {
|
|
4
|
-
/**
|
|
5
|
-
* We cannot test Docker on macOS GitHub Actions runners.
|
|
6
|
-
*
|
|
7
|
-
* @see
|
|
8
|
-
* - https://github.com/actions/runner-images/issues/8104
|
|
9
|
-
* - https://github.com/douglascamata/setup-docker-macos-action?tab=readme-ov-file#arm64-processors-m1-m2-m3-series-used-on-macos-14-images-are-unsupported
|
|
10
|
-
* - https://github.com/actions/runner-images/issues/2150
|
|
11
|
-
* - https://github.com/actions/runner/issues/1456
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* We cannot test Docker on Windows GitHub Actions runners because Docker cannot run in
|
|
15
|
-
* Linux container mode on Windows GitHub Actions runners.
|
|
16
|
-
*
|
|
17
|
-
* @see
|
|
18
|
-
* - https://github.com/orgs/community/discussions/25491#discussioncomment-3248089
|
|
19
|
-
*/
|
|
20
|
-
return () => { };
|
|
21
|
-
}
|
|
22
|
-
return callback;
|
|
23
|
-
}
|