@augment-vir/node 31.43.2 → 31.44.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.
Files changed (47) hide show
  1. package/README.md +0 -2
  2. package/dist/file-paths.mock.d.ts +0 -6
  3. package/dist/file-paths.mock.js +0 -6
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.js +0 -1
  6. package/package.json +4 -6
  7. package/src/file-paths.mock.ts +0 -7
  8. package/src/index.ts +0 -1
  9. package/dist/augments/docker.d.ts +0 -92
  10. package/dist/augments/docker.js +0 -87
  11. package/dist/docker/containers/container-info.d.ts +0 -57
  12. package/dist/docker/containers/container-info.js +0 -18
  13. package/dist/docker/containers/container-status.d.ts +0 -32
  14. package/dist/docker/containers/container-status.js +0 -68
  15. package/dist/docker/containers/copy-to-container.d.ts +0 -14
  16. package/dist/docker/containers/copy-to-container.js +0 -10
  17. package/dist/docker/containers/docker-command-inputs.d.ts +0 -74
  18. package/dist/docker/containers/docker-command-inputs.js +0 -45
  19. package/dist/docker/containers/kill-container.d.ts +0 -10
  20. package/dist/docker/containers/kill-container.js +0 -12
  21. package/dist/docker/containers/run-command.d.ts +0 -18
  22. package/dist/docker/containers/run-command.js +0 -24
  23. package/dist/docker/containers/run-container.d.ts +0 -23
  24. package/dist/docker/containers/run-container.js +0 -47
  25. package/dist/docker/containers/run-container.mock.d.ts +0 -2
  26. package/dist/docker/containers/run-container.mock.js +0 -16
  27. package/dist/docker/containers/try-or-kill-container.d.ts +0 -6
  28. package/dist/docker/containers/try-or-kill-container.js +0 -14
  29. package/dist/docker/docker-image.d.ts +0 -9
  30. package/dist/docker/docker-image.js +0 -50
  31. package/dist/docker/docker-startup.d.ts +0 -2
  32. package/dist/docker/docker-startup.js +0 -39
  33. package/dist/docker/run-docker-test.mock.d.ts +0 -2
  34. package/dist/docker/run-docker-test.mock.js +0 -23
  35. package/src/augments/docker.ts +0 -119
  36. package/src/docker/containers/container-info.ts +0 -83
  37. package/src/docker/containers/container-status.ts +0 -110
  38. package/src/docker/containers/copy-to-container.ts +0 -34
  39. package/src/docker/containers/docker-command-inputs.ts +0 -122
  40. package/src/docker/containers/kill-container.ts +0 -25
  41. package/src/docker/containers/run-command.ts +0 -51
  42. package/src/docker/containers/run-container.mock.ts +0 -22
  43. package/src/docker/containers/run-container.ts +0 -92
  44. package/src/docker/containers/try-or-kill-container.ts +0 -18
  45. package/src/docker/docker-image.ts +0 -61
  46. package/src/docker/docker-startup.ts +0 -49
  47. package/src/docker/run-docker-test.mock.ts +0 -26
@@ -1,122 +0,0 @@
1
- import {wrapString} from '@augment-vir/common';
2
-
3
- /**
4
- * Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running
5
- * Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property
6
- * empty (`undefined`).
7
- *
8
- * @category Node : Docker : Util
9
- * @category Package : @augment-vir/node
10
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
- */
12
- export enum DockerVolumeMappingType {
13
- Cached = 'cached',
14
- Delegated = 'delegated',
15
- }
16
-
17
- /**
18
- * A mapping of a single docker volume for mounting host files to a container.
19
- *
20
- * @category Node : Docker : Util
21
- * @category Package : @augment-vir/node
22
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
23
- */
24
- export type DockerVolumeMap = {
25
- hostAbsolutePath: string;
26
- containerAbsolutePath: string;
27
- type?: DockerVolumeMappingType | undefined;
28
- };
29
-
30
- export function makeVolumeFlags(volumeMapping?: ReadonlyArray<DockerVolumeMap>): string {
31
- if (!volumeMapping) {
32
- return '';
33
- }
34
-
35
- const parts = volumeMapping.map((volume) => {
36
- const mountType = volume.type ? `:${volume.type}` : '';
37
- return `-v '${volume.hostAbsolutePath}':'${volume.containerAbsolutePath}'${mountType}`;
38
- });
39
-
40
- return parts.join(' ');
41
- }
42
- /**
43
- * A single docker container port mapping. This is usually used in an array.
44
- *
45
- * @category Node : Docker : Util
46
- * @category Package : @augment-vir/node
47
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
48
- */
49
- export type DockerPortMap = {
50
- hostPort: number;
51
- containerPort: number;
52
- };
53
-
54
- /**
55
- * A set of environment mappings for a docker container.
56
- *
57
- * - Each key in this object represents the env var name within the Docker container.
58
- * - Each `value` property can be either the value that the env var should be set to _or_ an existing
59
- * env var's interpolation into the value.
60
- * - If the value string is meant to be interpolated within the shell context, make sure to set
61
- * `allowInterpolation` to `true`. Otherwise, it's best to leave it as `false`.
62
- *
63
- * @category Node : Docker : Util
64
- * @category Package : @augment-vir/node
65
- * @example
66
- *
67
- * ```ts
68
- * const envMapping: DockerEnvMap = {
69
- * VAR_1: {
70
- * value: 'hi',
71
- * // set to false because this is a raw string value that is not meant to be interpolated
72
- * allowInterpolation: false,
73
- * },
74
- * VAR_2: {
75
- * // the value here will be interpolated from the current shell's value for `EXISTING_VAR`
76
- * value: '$EXISTING_VAR',
77
- * // set to true to allow '$EXISTING_VAR' to be interpolated by the shell
78
- * allowInterpolation: true,
79
- * },
80
- * };
81
- * ```
82
- *
83
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
84
- */
85
- export type DockerEnvMap<RequiredKeys extends string = string> = Readonly<
86
- Record<
87
- RequiredKeys | string,
88
- {
89
- value: string;
90
- allowInterpolation: boolean;
91
- }
92
- >
93
- >;
94
-
95
- export function makePortMapFlags(portMapping?: ReadonlyArray<DockerPortMap> | undefined): string {
96
- if (!portMapping) {
97
- return '';
98
- }
99
-
100
- return portMapping
101
- .map((portMap) => {
102
- return `-p ${portMap.hostPort}:${portMap.containerPort}`;
103
- })
104
- .join(' ');
105
- }
106
-
107
- export function makeEnvFlags(envMapping?: DockerEnvMap | undefined): string {
108
- if (!envMapping) {
109
- return '';
110
- }
111
- const flags: ReadonlyArray<string> = Object.entries(envMapping).map(
112
- ([
113
- key,
114
- {value, allowInterpolation},
115
- ]) => {
116
- const quote = allowInterpolation ? '"' : "'";
117
- return `-e ${key}=${wrapString({value, wrapper: quote})}`;
118
- },
119
- );
120
-
121
- return flags.join(' ');
122
- }
@@ -1,25 +0,0 @@
1
- import {type PartialWithUndefined} from '@augment-vir/core';
2
- import {runShellCommand} from '../../augments/terminal/shell.js';
3
- import {waitUntilContainerExited, waitUntilContainerRemoved} from './container-status.js';
4
-
5
- export async function killContainer(
6
- containerNameOrId: string,
7
- options: PartialWithUndefined<{
8
- /**
9
- * If set to `true`, the container will be killed but won't be removed. (You'll still see it
10
- * in your Docker Dashboard but it'll have a status of exited.)
11
- *
12
- * @default false
13
- */
14
- keepContainer: boolean;
15
- }> = {},
16
- ): Promise<void> {
17
- await runShellCommand(`docker kill '${containerNameOrId}'`);
18
-
19
- if (options.keepContainer) {
20
- await waitUntilContainerExited(containerNameOrId);
21
- } else {
22
- await runShellCommand(`docker rm '${containerNameOrId}'`);
23
- await waitUntilContainerRemoved(containerNameOrId);
24
- }
25
- }
@@ -1,51 +0,0 @@
1
- import {check} from '@augment-vir/assert';
2
- import {runShellCommand} from '../../augments/terminal/shell.js';
3
- import {type DockerEnvMap, makeEnvFlags} from './docker-command-inputs.js';
4
-
5
- /**
6
- * Parameters for `docker.container.runCommand`.
7
- *
8
- * @category Node : Docker : Util
9
- * @category Package : @augment-vir/node
10
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
- */
12
- export type RunDockerContainerCommandParams = {
13
- /** Creates an interactive shell connection. */
14
- tty?: boolean | undefined;
15
- containerNameOrId: string;
16
- command: string;
17
- envMapping?: DockerEnvMap | undefined;
18
- executionEnv?: Record<string, string> | undefined;
19
- dockerFlags?: ReadonlyArray<string> | undefined;
20
- };
21
-
22
- export async function runContainerCommand({
23
- tty,
24
- containerNameOrId,
25
- command,
26
- envMapping,
27
- executionEnv,
28
- dockerFlags = [],
29
- }: RunDockerContainerCommandParams) {
30
- const envFlags = makeEnvFlags(envMapping);
31
- /** Can't test tty in automated tests. */
32
- /* node:coverage ignore next 1 */
33
- const ttyFlag = tty ? '-it' : '';
34
-
35
- const fullCommand = [
36
- 'docker',
37
- 'exec',
38
- ttyFlag,
39
- envFlags,
40
- ...dockerFlags,
41
- containerNameOrId,
42
- command,
43
- ]
44
- .filter(check.isTruthy)
45
- .join(' ');
46
-
47
- return await runShellCommand(fullCommand, {
48
- env: executionEnv,
49
- rejectOnError: true,
50
- });
51
- }
@@ -1,22 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-deprecated */
2
-
3
- import {docker} from '../../augments/docker.js';
4
- import {type RunDockerContainerParams} from './run-container.js';
5
-
6
- export async function runMockLongLivingContainer(
7
- containerName: string,
8
- args: Partial<RunDockerContainerParams> = {},
9
- ) {
10
- await docker.container.run({
11
- containerName,
12
- detach: true,
13
- imageName: 'alpine:3.20.2',
14
- dockerFlags: [
15
- '-i',
16
- '-t',
17
- ],
18
- command: 'sh',
19
- platform: 'amd64',
20
- ...args,
21
- });
22
- }
@@ -1,92 +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 {
6
- type DockerEnvMap,
7
- type DockerPortMap,
8
- type DockerVolumeMap,
9
- makeEnvFlags,
10
- makePortMapFlags,
11
- makeVolumeFlags,
12
- } from './docker-command-inputs.js';
13
- import {killContainer} from './kill-container.js';
14
-
15
- /**
16
- * Parameters for `docker.container.run`.
17
- *
18
- * @category Node : Docker : Util
19
- * @category Package : @augment-vir/node
20
- * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
21
- */
22
- export type RunDockerContainerParams = {
23
- imageName: string;
24
- detach: boolean;
25
- command?: string;
26
- containerName: string;
27
- volumeMapping?: ReadonlyArray<DockerVolumeMap> | undefined;
28
- portMapping?: ReadonlyArray<DockerPortMap> | undefined;
29
- envMapping?: DockerEnvMap | undefined;
30
- executionEnv?: Record<string, string>;
31
- removeWhenDone?: boolean;
32
- dockerFlags?: ReadonlyArray<string>;
33
- useCurrentUser?: boolean;
34
- platform?: string;
35
- };
36
-
37
- export async function runContainer({
38
- containerName,
39
- imageName,
40
- detach,
41
- command,
42
- portMapping,
43
- volumeMapping,
44
- envMapping,
45
- executionEnv,
46
- removeWhenDone,
47
- useCurrentUser,
48
- dockerFlags = [],
49
- platform,
50
- }: RunDockerContainerParams) {
51
- try {
52
- const portMapFlags = makePortMapFlags(portMapping);
53
- const envFlags = makeEnvFlags(envMapping);
54
- const detachFlag = detach ? '-d' : '';
55
- const volumeMapFlags = makeVolumeFlags(volumeMapping);
56
- const rmFlag = removeWhenDone ? '--rm' : '';
57
- const userFlag = useCurrentUser ? '--user "$(id -u)":"$(id -g)"' : '';
58
-
59
- await updateImage(imageName, platform);
60
-
61
- const fullCommand = [
62
- 'docker',
63
- 'run',
64
- portMapFlags,
65
- userFlag,
66
- volumeMapFlags,
67
- envFlags,
68
- rmFlag,
69
- detachFlag,
70
- `--name='${containerName}'`,
71
- ...dockerFlags,
72
- imageName,
73
- command,
74
- ]
75
- .filter(check.isTruthy)
76
- .join(' ');
77
-
78
- await runShellCommand(fullCommand, {
79
- env: executionEnv,
80
- rejectOnError: true,
81
- });
82
-
83
- if (removeWhenDone) {
84
- await killContainer(containerName);
85
- } else if (detach) {
86
- await waitUntilContainerRunning(containerName);
87
- }
88
- } catch (error) {
89
- await killContainer(containerName);
90
- throw error;
91
- }
92
- }
@@ -1,18 +0,0 @@
1
- import {type MaybePromise} from '@augment-vir/core';
2
- import {killContainer} from './kill-container.js';
3
-
4
- /**
5
- * Runs a callback (which presumably runs a command within the given `containerName`) and kills the
6
- * given `containerName` container if the callback fails.
7
- */
8
- export async function tryOrKillContainer<T>(
9
- containerNameOrId: string,
10
- callback: (containerNameOrId: string) => MaybePromise<T>,
11
- ): Promise<Awaited<T>> {
12
- try {
13
- return await callback(containerNameOrId);
14
- } catch (error) {
15
- await killContainer(containerNameOrId);
16
- throw error;
17
- }
18
- }
@@ -1,61 +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
-
5
- export async function updateImage(
6
- /** @example 'alpine:3.20.2' */
7
- imageName: string,
8
- platform?: string,
9
- ) {
10
- if (await isImageInLocalRegistry(imageName)) {
11
- /** If image already exists then we don't need to update it. */
12
- return;
13
- }
14
-
15
- const command = [
16
- 'docker',
17
- 'pull',
18
- ...(platform
19
- ? [
20
- '--platform',
21
- platform,
22
- ]
23
- : []),
24
- wrapString({value: imageName, wrapper: "'"}),
25
- ].join(' ');
26
-
27
- await runShellCommand(command, {
28
- rejectOnError: true,
29
- });
30
- }
31
-
32
- export async function isImageInLocalRegistry(
33
- /** @example 'alpine:3.20.2' */
34
- imageName: string,
35
- ): Promise<boolean> {
36
- const output = await runShellCommand(`docker inspect '${imageName}'`);
37
-
38
- return output.exitCode === 0;
39
- }
40
-
41
- export async function removeImageFromLocalRegistry(
42
- /** @example 'alpine:3.20.2' */
43
- imageName: string,
44
- ) {
45
- try {
46
- await runShellCommand(`docker image rm '${imageName}'`, {
47
- rejectOnError: true,
48
- });
49
- } catch (caught) {
50
- const error = ensureError(caught);
51
-
52
- if (error.message.includes('No such image:')) {
53
- /** Ignore the case where the image has already been deleted. */
54
- return;
55
- }
56
-
57
- /** An edge case that I don't know how to intentionally trigger. */
58
- /* node:coverage ignore next 2 */
59
- throw error;
60
- }
61
- }
@@ -1,49 +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
-
5
- export async function isDockerRunning() {
6
- const output = await runShellCommand('docker info');
7
-
8
- return output.exitCode === 0;
9
- }
10
-
11
- const startDockerCommands: Record<OperatingSystem, string> = {
12
- /**
13
- * Officially supported for the following distros:
14
- *
15
- * - [Ubuntu](https://docs.docker.com/desktop/install/ubuntu/#launch-docker-desktop)
16
- * - [Debian](https://docs.docker.com/desktop/install/debian/#launch-docker-desktop)
17
- * - [Fedora](https://docs.docker.com/desktop/install/fedora/#launch-docker-desktop)
18
- * - [Arch](https://docs.docker.com/desktop/install/archlinux/#launch-docker-desktop)
19
- */
20
- [OperatingSystem.Linux]: 'systemctl --user start docker-desktop',
21
- [OperatingSystem.Mac]: 'open -a Docker',
22
- [OperatingSystem.Windows]: String.raw`/c/Program\ Files/Docker/Docker/Docker\ Desktop.exe`,
23
- };
24
-
25
- export async function startDocker() {
26
- const command = startDockerCommands[currentOperatingSystem];
27
-
28
- /* node:coverage disable */
29
- if (await isDockerRunning()) {
30
- /** Docker is already running. Nothing to do. */
31
- return;
32
- }
33
-
34
- await waitUntil.isTrue(
35
- async () => {
36
- await runShellCommand(command, {rejectOnError: true});
37
- return isDockerRunning();
38
- },
39
- {
40
- interval: {
41
- seconds: 1,
42
- },
43
- timeout: {
44
- minutes: 1,
45
- },
46
- },
47
- 'Failed to start Docker.',
48
- );
49
- }
@@ -1,26 +0,0 @@
1
- import {type MaybePromise} from '@augment-vir/common';
2
- import {isOperatingSystem, OperatingSystem} from '../augments/os/operating-system.js';
3
-
4
- export function dockerTest(callback: () => MaybePromise<void>) {
5
- if (!isOperatingSystem(OperatingSystem.Linux) && process.env.CI) {
6
- /**
7
- * We cannot test Docker on macOS GitHub Actions runners.
8
- *
9
- * @see
10
- * - https://github.com/actions/runner-images/issues/8104
11
- * - 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
12
- * - https://github.com/actions/runner-images/issues/2150
13
- * - https://github.com/actions/runner/issues/1456
14
- */
15
- /**
16
- * We cannot test Docker on Windows GitHub Actions runners because Docker cannot run in
17
- * Linux container mode on Windows GitHub Actions runners.
18
- *
19
- * @see
20
- * - https://github.com/orgs/community/discussions/25491#discussioncomment-3248089
21
- */
22
- return () => {};
23
- }
24
-
25
- return callback;
26
- }