@zukhruf/docker 0.0.0-stage → 0.3.33
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 +21 -0
- package/README.md +888 -2
- package/dist/api-version.d.ts +7 -0
- package/dist/api-version.d.ts.map +1 -0
- package/dist/api-version.js +22 -0
- package/dist/api-version.js.map +1 -0
- package/dist/context-store.d.ts +22 -0
- package/dist/context-store.d.ts.map +1 -0
- package/dist/context-store.js +128 -0
- package/dist/context-store.js.map +1 -0
- package/dist/docker.d.ts +34 -0
- package/dist/docker.d.ts.map +1 -0
- package/dist/docker.js +60 -0
- package/dist/docker.js.map +1 -0
- package/dist/engine-api.d.ts +21 -0
- package/dist/engine-api.d.ts.map +1 -0
- package/dist/engine-api.js +4 -0
- package/dist/engine-api.js.map +1 -0
- package/dist/engine-client.d.ts +26 -0
- package/dist/engine-client.d.ts.map +1 -0
- package/dist/engine-client.js +117 -0
- package/dist/engine-client.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +64 -0
- package/dist/errors.js.map +1 -0
- package/dist/host.d.ts +13 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +22 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +7 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -0
- package/dist/ssh-connection.d.ts +20 -0
- package/dist/ssh-connection.d.ts.map +1 -0
- package/dist/ssh-connection.js +189 -0
- package/dist/ssh-connection.js.map +1 -0
- package/dist/transport.d.ts +19 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +24 -0
- package/dist/transport.js.map +1 -0
- package/package.json +40 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** From 1.44 on, a create of a network with a taken name fails, and networks.createOrGet() needs that. */
|
|
2
|
+
export declare const LOWEST_API_VERSION = "1.44";
|
|
3
|
+
/** The highest API version that the tests of the package run on. */
|
|
4
|
+
export declare const HIGHEST_API_VERSION = "1.56";
|
|
5
|
+
/** The lower of the engine's highest version and the package's highest version. */
|
|
6
|
+
export declare function negotiateApiVersion(host: string, engineVersion: string): string;
|
|
7
|
+
//# sourceMappingURL=api-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-version.d.ts","sourceRoot":"","sources":["../src/api-version.ts"],"names":[],"mappings":"AAEA,0GAA0G;AAC1G,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAS1C,mFAAmF;AACnF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,GACpB,MAAM,CAUR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UnsupportedEngineError } from "./errors.js";
|
|
2
|
+
/** From 1.44 on, a create of a network with a taken name fails, and networks.createOrGet() needs that. */
|
|
3
|
+
export const LOWEST_API_VERSION = '1.44';
|
|
4
|
+
/** The highest API version that the tests of the package run on. */
|
|
5
|
+
export const HIGHEST_API_VERSION = '1.56';
|
|
6
|
+
/** Compares the numbers of two versions, so that 1.9 is lower than 1.10. */
|
|
7
|
+
function compareApiVersions(left, right) {
|
|
8
|
+
const [leftMajor = 0, leftMinor = 0] = left.split('.').map(Number);
|
|
9
|
+
const [rightMajor = 0, rightMinor = 0] = right.split('.').map(Number);
|
|
10
|
+
return leftMajor - rightMajor || leftMinor - rightMinor;
|
|
11
|
+
}
|
|
12
|
+
/** The lower of the engine's highest version and the package's highest version. */
|
|
13
|
+
export function negotiateApiVersion(host, engineVersion) {
|
|
14
|
+
if (!/^\d+\.\d+$/.test(engineVersion) ||
|
|
15
|
+
compareApiVersions(engineVersion, LOWEST_API_VERSION) < 0) {
|
|
16
|
+
throw new UnsupportedEngineError(host, engineVersion, LOWEST_API_VERSION);
|
|
17
|
+
}
|
|
18
|
+
return compareApiVersions(engineVersion, HIGHEST_API_VERSION) < 0
|
|
19
|
+
? engineVersion
|
|
20
|
+
: HIGHEST_API_VERSION;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=api-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-version.js","sourceRoot":"","sources":["../src/api-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAE1C,4EAA4E;AAC5E,SAAS,kBAAkB,CAAC,IAAY,EAAE,KAAa;IACrD,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACnE,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtE,OAAO,SAAS,GAAG,UAAU,IAAI,SAAS,GAAG,UAAU,CAAC;AAC1D,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,aAAqB;IAErB,IACE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC;QACjC,kBAAkB,CAAC,aAAa,EAAE,kBAAkB,CAAC,GAAG,CAAC,EACzD,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC,IAAI,EAAE,aAAa,EAAE,kBAAkB,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,kBAAkB,CAAC,aAAa,EAAE,mBAAmB,CAAC,GAAG,CAAC;QAC/D,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,mBAAmB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface DockerContext {
|
|
2
|
+
name: string;
|
|
3
|
+
host: string;
|
|
4
|
+
/** The context that connect() selects with no options. */
|
|
5
|
+
current: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** An engine as the selection gives it: the context that selected it, and its host. */
|
|
8
|
+
export interface SelectedEngine {
|
|
9
|
+
context: string;
|
|
10
|
+
host: string;
|
|
11
|
+
}
|
|
12
|
+
/** The environment of the host program, such as process.env. The package reads only DOCKER_HOST, DOCKER_CONTEXT and DOCKER_CONFIG. */
|
|
13
|
+
export type Environment = Readonly<Record<string, string | undefined>>;
|
|
14
|
+
/** Selects the engine in the order of the Docker CLI, or the engine that the options name. */
|
|
15
|
+
export declare function selectEngine(options: {
|
|
16
|
+
context?: string | undefined;
|
|
17
|
+
host?: string | undefined;
|
|
18
|
+
environment?: Environment | undefined;
|
|
19
|
+
}): Promise<SelectedEngine>;
|
|
20
|
+
/** Each context of the context store, and the default context. */
|
|
21
|
+
export declare function listContexts(environment?: Environment): Promise<DockerContext[]>;
|
|
22
|
+
//# sourceMappingURL=context-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store.d.ts","sourceRoot":"","sources":["../src/context-store.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAWD,sIAAsI;AACtI,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAyGvE,8FAA8F;AAC9F,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CACvC,GAAG,OAAO,CAAC,cAAc,CAAC,CAO1B;AAED,kEAAkE;AAClE,wBAAsB,YAAY,CAChC,WAAW,GAAE,WAAgB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CAO1B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { ContextNotFoundError } from "./errors.js";
|
|
6
|
+
const DEFAULT_CONTEXT = 'default';
|
|
7
|
+
/** The host of the default context when DOCKER_HOST is not set. */
|
|
8
|
+
function platformHost() {
|
|
9
|
+
return process.platform === 'win32'
|
|
10
|
+
? 'npipe:////./pipe/docker_engine'
|
|
11
|
+
: 'unix:///var/run/docker.sock';
|
|
12
|
+
}
|
|
13
|
+
/** An empty variable is the same as an unset one, as in the Docker CLI. */
|
|
14
|
+
function variable(environment, name) {
|
|
15
|
+
const value = environment[name];
|
|
16
|
+
return value === '' ? undefined : value;
|
|
17
|
+
}
|
|
18
|
+
/** The Docker configuration directory: DOCKER_CONFIG, or ~/.docker. */
|
|
19
|
+
function configDirectory(environment) {
|
|
20
|
+
return variable(environment, 'DOCKER_CONFIG') ?? join(homedir(), '.docker');
|
|
21
|
+
}
|
|
22
|
+
function isMissingFile(error) {
|
|
23
|
+
return (error instanceof Error &&
|
|
24
|
+
'code' in error &&
|
|
25
|
+
(error.code === 'ENOENT' || error.code === 'ENOTDIR'));
|
|
26
|
+
}
|
|
27
|
+
function stringField(value, key) {
|
|
28
|
+
if (typeof value !== 'object' || value === null || !(key in value)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const field = Reflect.get(value, key);
|
|
32
|
+
return typeof field === 'string' && field !== '' ? field : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** currentContext in config.json, or undefined when the file or the field is absent. */
|
|
35
|
+
async function configuredContext(environment) {
|
|
36
|
+
try {
|
|
37
|
+
const config = JSON.parse(await readFile(join(configDirectory(environment), 'config.json'), 'utf8'));
|
|
38
|
+
return stringField(config, 'currentContext');
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (isMissingFile(error))
|
|
42
|
+
return undefined;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The context that the Docker CLI selects when a command names none. */
|
|
47
|
+
async function currentContext(environment) {
|
|
48
|
+
if (variable(environment, 'DOCKER_HOST'))
|
|
49
|
+
return DEFAULT_CONTEXT;
|
|
50
|
+
return (variable(environment, 'DOCKER_CONTEXT') ??
|
|
51
|
+
(await configuredContext(environment)) ??
|
|
52
|
+
DEFAULT_CONTEXT);
|
|
53
|
+
}
|
|
54
|
+
/** The host of the default context: DOCKER_HOST, or the default host of the platform. */
|
|
55
|
+
function defaultHost(environment) {
|
|
56
|
+
return variable(environment, 'DOCKER_HOST') ?? platformHost();
|
|
57
|
+
}
|
|
58
|
+
function metaDirectory(environment) {
|
|
59
|
+
return join(configDirectory(environment), 'contexts', 'meta');
|
|
60
|
+
}
|
|
61
|
+
/** Endpoints.docker.Host of meta.json, or undefined when the context has no docker endpoint. */
|
|
62
|
+
function hostOfMeta(meta) {
|
|
63
|
+
const endpoints = Reflect.get(Object(meta), 'Endpoints');
|
|
64
|
+
const docker = Reflect.get(Object(endpoints), 'docker');
|
|
65
|
+
return stringField(docker, 'Host');
|
|
66
|
+
}
|
|
67
|
+
/** The host of a context of the context store. */
|
|
68
|
+
async function storedHost(environment, name) {
|
|
69
|
+
const id = createHash('sha256').update(name).digest('hex');
|
|
70
|
+
try {
|
|
71
|
+
const meta = JSON.parse(await readFile(join(metaDirectory(environment), id, 'meta.json'), 'utf8'));
|
|
72
|
+
const host = hostOfMeta(meta);
|
|
73
|
+
if (host === undefined)
|
|
74
|
+
throw new ContextNotFoundError(name);
|
|
75
|
+
return host;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (isMissingFile(error))
|
|
79
|
+
throw new ContextNotFoundError(name, { cause: error });
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The host of a context: the default context takes it from DOCKER_HOST, as the Docker CLI defines it. */
|
|
84
|
+
async function hostOfContext(environment, name) {
|
|
85
|
+
return name === DEFAULT_CONTEXT
|
|
86
|
+
? defaultHost(environment)
|
|
87
|
+
: storedHost(environment, name);
|
|
88
|
+
}
|
|
89
|
+
/** Selects the engine in the order of the Docker CLI, or the engine that the options name. */
|
|
90
|
+
export async function selectEngine(options) {
|
|
91
|
+
if (options.host !== undefined) {
|
|
92
|
+
return { context: DEFAULT_CONTEXT, host: options.host };
|
|
93
|
+
}
|
|
94
|
+
const environment = options.environment ?? {};
|
|
95
|
+
const context = options.context ?? (await currentContext(environment));
|
|
96
|
+
return { context, host: await hostOfContext(environment, context) };
|
|
97
|
+
}
|
|
98
|
+
/** Each context of the context store, and the default context. */
|
|
99
|
+
export async function listContexts(environment = {}) {
|
|
100
|
+
const current = await currentContext(environment);
|
|
101
|
+
const stored = await storedContexts(environment);
|
|
102
|
+
return [
|
|
103
|
+
{ name: DEFAULT_CONTEXT, host: defaultHost(environment) },
|
|
104
|
+
...stored.toSorted((left, right) => left.name.localeCompare(right.name)),
|
|
105
|
+
].map(({ name, host }) => ({ name, host, current: name === current }));
|
|
106
|
+
}
|
|
107
|
+
async function storedContexts(environment) {
|
|
108
|
+
const directory = metaDirectory(environment);
|
|
109
|
+
const ids = await readdir(directory).catch((error) => {
|
|
110
|
+
if (isMissingFile(error))
|
|
111
|
+
return [];
|
|
112
|
+
throw error;
|
|
113
|
+
});
|
|
114
|
+
const contexts = await Promise.all(ids.map(async (id) => {
|
|
115
|
+
const meta = JSON.parse(await readFile(join(directory, id, 'meta.json'), 'utf8').catch((error) => {
|
|
116
|
+
if (isMissingFile(error))
|
|
117
|
+
return 'null';
|
|
118
|
+
throw error;
|
|
119
|
+
}));
|
|
120
|
+
const name = stringField(meta, 'Name');
|
|
121
|
+
const host = hostOfMeta(meta);
|
|
122
|
+
return name === undefined || host === undefined
|
|
123
|
+
? undefined
|
|
124
|
+
: { name, host };
|
|
125
|
+
}));
|
|
126
|
+
return contexts.filter((context) => context !== undefined);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=context-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store.js","sourceRoot":"","sources":["../src/context-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAenD,MAAM,eAAe,GAAG,SAAS,CAAC;AAElC,mEAAmE;AACnE,SAAS,YAAY;IACnB,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO;QACjC,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,6BAA6B,CAAC;AACpC,CAAC;AAOD,2EAA2E;AAC3E,SAAS,QAAQ,CACf,WAAwB,EACxB,IAAc;IAEd,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1C,CAAC;AAED,uEAAuE;A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ACX,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACrB,CAAC,CAAC,CACH,CAAC;IACF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC;AAC7D,CAAC"}
|
package/dist/docker.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type DockerContext, type Environment } from './context-store.ts';
|
|
2
|
+
import type * as EngineApi from './engine-api.ts';
|
|
3
|
+
import type { CancelOptions } from './options.ts';
|
|
4
|
+
/** A context or a host, never both. */
|
|
5
|
+
export type ConnectOptions = CancelOptions & {
|
|
6
|
+
environment?: Environment;
|
|
7
|
+
} & ({
|
|
8
|
+
context?: string;
|
|
9
|
+
host?: never;
|
|
10
|
+
} | {
|
|
11
|
+
host?: string;
|
|
12
|
+
context?: never;
|
|
13
|
+
});
|
|
14
|
+
/** A client of one engine. Dispose it to close its connections. */
|
|
15
|
+
export declare class Docker implements AsyncDisposable {
|
|
16
|
+
#private;
|
|
17
|
+
/** The context that selected the engine: 'default' for DOCKER_HOST or a host option. */
|
|
18
|
+
readonly context: string;
|
|
19
|
+
readonly host: string;
|
|
20
|
+
readonly apiVersion: string;
|
|
21
|
+
/** Sends the Docker CLI to this engine: { DOCKER_HOST, DOCKER_CONTEXT: undefined }. */
|
|
22
|
+
readonly cliEnvironment: Readonly<Record<string, string | undefined>>;
|
|
23
|
+
private constructor();
|
|
24
|
+
/** Selects the engine in the order of the Docker CLI, pings it and negotiates the API version. */
|
|
25
|
+
static connect(options?: ConnectOptions): Promise<Docker>;
|
|
26
|
+
/** Each context of the context store, and the default context. */
|
|
27
|
+
static contexts(options?: {
|
|
28
|
+
environment?: Environment;
|
|
29
|
+
}): Promise<DockerContext[]>;
|
|
30
|
+
info(options?: CancelOptions): Promise<EngineApi.SystemInfo>;
|
|
31
|
+
/** Closes the connections of the client. For an SSH engine, it resolves when each `ssh` process exited. */
|
|
32
|
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,CAAC,SAAS,CAAC,UAAU,CAAC;IAItE,2GAA2G;IACrG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
package/dist/docker.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { negotiateApiVersion } from "./api-version.js";
|
|
2
|
+
import { listContexts, selectEngine, } from "./context-store.js";
|
|
3
|
+
import { EngineClient } from "./engine-client.js";
|
|
4
|
+
import { parseHost } from "./host.js";
|
|
5
|
+
import { SshTransport } from "./ssh-connection.js";
|
|
6
|
+
import { SocketTransport } from "./transport.js";
|
|
7
|
+
/** A client of one engine. Dispose it to close its connections. */
|
|
8
|
+
export class Docker {
|
|
9
|
+
/** The context that selected the engine: 'default' for DOCKER_HOST or a host option. */
|
|
10
|
+
context;
|
|
11
|
+
host;
|
|
12
|
+
apiVersion;
|
|
13
|
+
/** Sends the Docker CLI to this engine: { DOCKER_HOST, DOCKER_CONTEXT: undefined }. */
|
|
14
|
+
cliEnvironment;
|
|
15
|
+
#client;
|
|
16
|
+
#transport;
|
|
17
|
+
constructor(context, host, apiVersion, client, transport) {
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.host = host;
|
|
20
|
+
this.apiVersion = apiVersion;
|
|
21
|
+
this.cliEnvironment = Object.freeze({
|
|
22
|
+
DOCKER_HOST: host,
|
|
23
|
+
DOCKER_CONTEXT: undefined,
|
|
24
|
+
});
|
|
25
|
+
this.#client = client;
|
|
26
|
+
this.#transport = transport;
|
|
27
|
+
}
|
|
28
|
+
/** Selects the engine in the order of the Docker CLI, pings it and negotiates the API version. */
|
|
29
|
+
static async connect(options = {}) {
|
|
30
|
+
const { signal } = options;
|
|
31
|
+
const engine = await selectEngine(options);
|
|
32
|
+
const parsed = parseHost(engine.host);
|
|
33
|
+
const transport = parsed.kind === 'ssh'
|
|
34
|
+
? new SshTransport(parsed.url)
|
|
35
|
+
: new SocketTransport(parsed.socketPath);
|
|
36
|
+
try {
|
|
37
|
+
const unversioned = new EngineClient(engine.host, transport);
|
|
38
|
+
const ping = await unversioned.request('GET', '/_ping', { signal });
|
|
39
|
+
const engineVersion = ping.headers['api-version'];
|
|
40
|
+
const apiVersion = negotiateApiVersion(engine.host, typeof engineVersion === 'string' ? engineVersion : '');
|
|
41
|
+
return new Docker(engine.context, engine.host, apiVersion, unversioned.versioned(apiVersion), transport);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
await transport.close();
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Each context of the context store, and the default context. */
|
|
49
|
+
static async contexts(options = {}) {
|
|
50
|
+
return listContexts(options.environment);
|
|
51
|
+
}
|
|
52
|
+
async info(options = {}) {
|
|
53
|
+
return this.#client.json('GET', '/info', options);
|
|
54
|
+
}
|
|
55
|
+
/** Closes the connections of the client. For an SSH engine, it resolves when each `ssh` process exited. */
|
|
56
|
+
async [Symbol.asyncDispose]() {
|
|
57
|
+
await this.#transport.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.js","sourceRoot":"","sources":["../src/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAGL,YAAY,EACZ,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAOjE,mEAAmE;AACnE,MAAM,OAAO,MAAM;IACjB,wFAAwF;IAC/E,OAAO,CAAS;IAChB,IAAI,CAAS;IACb,UAAU,CAAS;IAC5B,uFAAuF;IAC9E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X,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CACvD,CAAC;YACF,OAAO,IAAI,MAAM,CACf,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,IAAI,EACX,UAAU,EACV,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,EACjC,SAAS,CACV,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;YACxB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,MAAM,CAAC,KAAK,CAAC,QAAQ,CACnB,UAAyC,EAAE;QAE3C,OAAO,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAyB,EAAE;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAuB,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;IAED,2GAA2G;IAC3G,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The answer of GET /info. Each field is optional, as in the reference. */
|
|
2
|
+
export interface SystemInfo {
|
|
3
|
+
ID?: string;
|
|
4
|
+
Name?: string;
|
|
5
|
+
ServerVersion?: string;
|
|
6
|
+
OperatingSystem?: string;
|
|
7
|
+
OSType?: string;
|
|
8
|
+
Architecture?: string;
|
|
9
|
+
KernelVersion?: string;
|
|
10
|
+
NCPU?: number;
|
|
11
|
+
MemTotal?: number;
|
|
12
|
+
Containers?: number;
|
|
13
|
+
ContainersRunning?: number;
|
|
14
|
+
ContainersPaused?: number;
|
|
15
|
+
ContainersStopped?: number;
|
|
16
|
+
Images?: number;
|
|
17
|
+
Driver?: string;
|
|
18
|
+
DockerRootDir?: string;
|
|
19
|
+
Labels?: string[];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=engine-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-api.d.ts","sourceRoot":"","sources":["../src/engine-api.ts"],"names":[],"mappings":"AAGA,4EAA4E;AAC5E,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-api.js","sourceRoot":"","sources":["../src/engine-api.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+DAA+D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
2
|
+
import type { Filters } from './options.ts';
|
|
3
|
+
import type { Transport } from './transport.ts';
|
|
4
|
+
/** The query of a request. `filters` goes to the engine as JSON. */
|
|
5
|
+
export type Query = Record<string, string | number | boolean | Filters | undefined>;
|
|
6
|
+
export interface EngineRequestOptions {
|
|
7
|
+
query?: Query | undefined;
|
|
8
|
+
signal?: AbortSignal | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface EngineResponse {
|
|
11
|
+
status: number;
|
|
12
|
+
headers: IncomingHttpHeaders;
|
|
13
|
+
body: Buffer;
|
|
14
|
+
}
|
|
15
|
+
/** Sends requests of the Engine API to one engine. */
|
|
16
|
+
export declare class EngineClient {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(host: string, transport: Transport, apiVersion?: string);
|
|
19
|
+
/** The same engine and connections, with the API version in the path of each request. */
|
|
20
|
+
versioned(apiVersion: string): EngineClient;
|
|
21
|
+
/** Sends a request. A status that is not 2xx rejects with DockerEngineError. */
|
|
22
|
+
request(method: string, path: string, options?: EngineRequestOptions): Promise<EngineResponse>;
|
|
23
|
+
/** Sends a request and gives its JSON body. */
|
|
24
|
+
json<T>(method: string, path: string, options?: EngineRequestOptions): Promise<T>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=engine-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-client.d.ts","sourceRoot":"","sources":["../src/engine-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,oEAAoE;AACpE,MAAM,MAAM,KAAK,GAAG,MAAM,CACxB,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAChD,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,mBAAmB,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AA4CD,sDAAsD;AACtD,qBAAa,YAAY;;gBAKX,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,MAAM;IAMnE,yFAAyF;IACzF,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAI3C,gFAAgF;IAC1E,OAAO,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,cAAc,CAAC;IAY1B,+CAA+C;IACzC,IAAI,CAAC,CAAC,EACV,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,CAAC,CAAC;CAwDd"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ConnectionFailedError, DockerEngineError } from "./errors.js";
|
|
2
|
+
import { SshExitError } from "./ssh-connection.js";
|
|
3
|
+
/** The socket errors that mean the engine did not accept the connection. ENOENT is also an absent `ssh`. */
|
|
4
|
+
const CONNECTION_FAILURES = new Set([
|
|
5
|
+
'ENOENT',
|
|
6
|
+
'ECONNREFUSED',
|
|
7
|
+
'EPIPE',
|
|
8
|
+
'ECONNRESET',
|
|
9
|
+
]);
|
|
10
|
+
function errorCode(error) {
|
|
11
|
+
return error instanceof Error &&
|
|
12
|
+
'code' in error &&
|
|
13
|
+
typeof error.code === 'string'
|
|
14
|
+
? error.code
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
function search(query) {
|
|
18
|
+
const parameters = new URLSearchParams();
|
|
19
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
parameters.set(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
23
|
+
}
|
|
24
|
+
const text = parameters.toString();
|
|
25
|
+
return text ? `?${text}` : '';
|
|
26
|
+
}
|
|
27
|
+
/** The message of an error answer of the engine: {"message": "..."}, or the text itself. */
|
|
28
|
+
function engineMessage(response) {
|
|
29
|
+
const text = response.body.toString('utf8');
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(text);
|
|
32
|
+
const message = Reflect.get(Object(parsed), 'message');
|
|
33
|
+
if (typeof message === 'string')
|
|
34
|
+
return message;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// The answer is not JSON: its text is the message.
|
|
38
|
+
}
|
|
39
|
+
return text.trim();
|
|
40
|
+
}
|
|
41
|
+
/** Sends requests of the Engine API to one engine. */
|
|
42
|
+
export class EngineClient {
|
|
43
|
+
#host;
|
|
44
|
+
#transport;
|
|
45
|
+
#apiVersion;
|
|
46
|
+
constructor(host, transport, apiVersion) {
|
|
47
|
+
this.#host = host;
|
|
48
|
+
this.#transport = transport;
|
|
49
|
+
this.#apiVersion = apiVersion;
|
|
50
|
+
}
|
|
51
|
+
/** The same engine and connections, with the API version in the path of each request. */
|
|
52
|
+
versioned(apiVersion) {
|
|
53
|
+
return new EngineClient(this.#host, this.#transport, apiVersion);
|
|
54
|
+
}
|
|
55
|
+
/** Sends a request. A status that is not 2xx rejects with DockerEngineError. */
|
|
56
|
+
async request(method, path, options = {}) {
|
|
57
|
+
const response = await this.#send(method, path, options);
|
|
58
|
+
if (response.status < 200 || response.status > 299) {
|
|
59
|
+
throw new DockerEngineError(engineMessage(response), {
|
|
60
|
+
status: response.status,
|
|
61
|
+
method,
|
|
62
|
+
path,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
/** Sends a request and gives its JSON body. */
|
|
68
|
+
async json(method, path, options = {}) {
|
|
69
|
+
const response = await this.request(method, path, options);
|
|
70
|
+
const body = JSON.parse(response.body.toString('utf8'));
|
|
71
|
+
return body;
|
|
72
|
+
}
|
|
73
|
+
async #send(method, path, { query, signal }) {
|
|
74
|
+
signal?.throwIfAborted();
|
|
75
|
+
const prefix = this.#apiVersion === undefined ? '' : `/v${this.#apiVersion}`;
|
|
76
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
77
|
+
const request = this.#transport.request({
|
|
78
|
+
method,
|
|
79
|
+
path: `${prefix}${path}${search(query)}`,
|
|
80
|
+
});
|
|
81
|
+
const abort = () => {
|
|
82
|
+
reject(signal?.reason);
|
|
83
|
+
request.destroy();
|
|
84
|
+
};
|
|
85
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
86
|
+
let answered = false;
|
|
87
|
+
request.on('error', (error) => {
|
|
88
|
+
// An error after the answer started is not a connection failure.
|
|
89
|
+
reject(!answered &&
|
|
90
|
+
(error instanceof SshExitError ||
|
|
91
|
+
CONNECTION_FAILURES.has(errorCode(error) ?? ''))
|
|
92
|
+
? new ConnectionFailedError(this.#host, { cause: error })
|
|
93
|
+
: error);
|
|
94
|
+
});
|
|
95
|
+
request.on('response', (response) => {
|
|
96
|
+
answered = true;
|
|
97
|
+
response.on('error', reject);
|
|
98
|
+
const chunks = [];
|
|
99
|
+
response.on('data', (chunk) => chunks.push(chunk));
|
|
100
|
+
response.on('end', () => {
|
|
101
|
+
resolve({
|
|
102
|
+
status: response.statusCode ?? 0,
|
|
103
|
+
headers: response.headers,
|
|
104
|
+
body: Buffer.concat(chunks),
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
request.end();
|
|
109
|
+
try {
|
|
110
|
+
return await promise;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
signal?.removeEventListener('abort', abort);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=engine-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-client.js","sourceRoot":"","sources":["../src/engine-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EA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,qBAAqB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;gBACzD,CAAC,CAAC,KAAK,CACV,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;YAClC,QAAQ,GAAG,IAAI,CAAC;YAChB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACtB,OAAO,CAAC;oBACN,MAAM,EAAE,QAAQ,CAAC,UAAU,IAAI,CAAC;oBAChC,OAAO,EAAE,QAAQ,CAAC,OAAO;oBACzB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,EAAE,CAAC;QACd,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC;QACvB,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** The base of every error of the package. */
|
|
2
|
+
export declare class DockerError extends Error {
|
|
3
|
+
constructor(message: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
/** The engine did not accept the connection: its socket does not exist, or it refuses the connection. */
|
|
6
|
+
export declare class ConnectionFailedError extends DockerError {
|
|
7
|
+
readonly host: string;
|
|
8
|
+
constructor(host: string, options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
/** The host is not unix://, npipe:// or ssh://. */
|
|
11
|
+
export declare class UnsupportedHostError extends DockerError {
|
|
12
|
+
readonly host: string;
|
|
13
|
+
constructor(host: string);
|
|
14
|
+
}
|
|
15
|
+
/** The context store does not have the context. */
|
|
16
|
+
export declare class ContextNotFoundError extends DockerError {
|
|
17
|
+
readonly context: string;
|
|
18
|
+
constructor(context: string, options?: ErrorOptions);
|
|
19
|
+
}
|
|
20
|
+
/** The highest API version of the engine is lower than the lowest one that the package supports. */
|
|
21
|
+
export declare class UnsupportedEngineError extends DockerError {
|
|
22
|
+
readonly host: string;
|
|
23
|
+
/** The highest API version of the engine. */
|
|
24
|
+
readonly engineVersion: string;
|
|
25
|
+
/** The lowest API version that the package supports. */
|
|
26
|
+
readonly minimumVersion: string;
|
|
27
|
+
constructor(host: string, engineVersion: string, minimumVersion: string);
|
|
28
|
+
}
|
|
29
|
+
export interface EngineRequest {
|
|
30
|
+
/** The HTTP status; undefined for an error in the progress of a pull, a push or a load. */
|
|
31
|
+
status: number | undefined;
|
|
32
|
+
method: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}
|
|
35
|
+
/** The base of every answer of the engine that is an error. Its message is the message of the engine. */
|
|
36
|
+
export declare class DockerEngineError extends DockerError {
|
|
37
|
+
/** The HTTP status; undefined for an error in the progress of a pull, a push or a load. */
|
|
38
|
+
readonly status: number | undefined;
|
|
39
|
+
readonly method: string;
|
|
40
|
+
readonly path: string;
|
|
41
|
+
constructor(message: string, request: EngineRequest, options?: ErrorOptions);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD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package. */
|
|
2
|
+
export class DockerError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'DockerError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** The engine did not accept the connection: its socket does not exist, or it refuses the connection. */
|
|
9
|
+
export class ConnectionFailedError extends DockerError {
|
|
10
|
+
host;
|
|
11
|
+
constructor(host, options) {
|
|
12
|
+
super(`Cannot connect to the engine at ${host}.`, options);
|
|
13
|
+
this.name = 'ConnectionFailedError';
|
|
14
|
+
this.host = host;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The host is not unix://, npipe:// or ssh://. */
|
|
18
|
+
export class UnsupportedHostError extends DockerError {
|
|
19
|
+
host;
|
|
20
|
+
constructor(host) {
|
|
21
|
+
super(`The host ${JSON.stringify(host)} is not supported: use a unix://, npipe:// or ssh:// host.`);
|
|
22
|
+
this.name = 'UnsupportedHostError';
|
|
23
|
+
this.host = host;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** The context store does not have the context. */
|
|
27
|
+
export class ContextNotFoundError extends DockerError {
|
|
28
|
+
context;
|
|
29
|
+
constructor(context, options) {
|
|
30
|
+
super(`The context store does not have the context ${JSON.stringify(context)}.`, options);
|
|
31
|
+
this.name = 'ContextNotFoundError';
|
|
32
|
+
this.context = context;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The highest API version of the engine is lower than the lowest one that the package supports. */
|
|
36
|
+
export class UnsupportedEngineError extends DockerError {
|
|
37
|
+
host;
|
|
38
|
+
/** The highest API version of the engine. */
|
|
39
|
+
engineVersion;
|
|
40
|
+
/** The lowest API version that the package supports. */
|
|
41
|
+
minimumVersion;
|
|
42
|
+
constructor(host, engineVersion, minimumVersion) {
|
|
43
|
+
super(`The engine at ${host} has API version ${engineVersion}, but the package needs ${minimumVersion} or higher. Update Docker.`);
|
|
44
|
+
this.name = 'UnsupportedEngineError';
|
|
45
|
+
this.host = host;
|
|
46
|
+
this.engineVersion = engineVersion;
|
|
47
|
+
this.minimumVersion = minimumVersion;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** The base of every answer of the engine that is an error. Its message is the message of the engine. */
|
|
51
|
+
export class DockerEngineError extends DockerError {
|
|
52
|
+
/** The HTTP status; undefined for an error in the progress of a pull, a push or a load. */
|
|
53
|
+
status;
|
|
54
|
+
method;
|
|
55
|
+
path;
|
|
56
|
+
constructor(message, request, options) {
|
|
57
|
+
super(message, options);
|
|
58
|
+
this.name = 'DockerEngineError';
|
|
59
|
+
this.status = request.status;
|
|
60
|
+
this.method = request.method;
|
|
61
|
+
this.path = request.path;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,yGAAyG;AACzG,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IAC3C,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAsB;QAC9C,KAAK,CAAC,mCAAmC,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,mDAAmD;AACnD,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAC1C,IAAI,CAAS;IAEtB,YAAY,IAAY;QACtB,KAAK,CACH,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4DAA4D,CAC7F,CAAC;QACF,IAAI,CAAC,IA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AG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A host, parsed by its kind. */
|
|
2
|
+
export type ParsedHost = {
|
|
3
|
+
kind: 'unix' | 'npipe';
|
|
4
|
+
host: string;
|
|
5
|
+
socketPath: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'ssh';
|
|
8
|
+
host: string;
|
|
9
|
+
url: URL;
|
|
10
|
+
};
|
|
11
|
+
/** Parses a unix://, npipe:// or ssh:// host. Each other host is an UnsupportedHostError. */
|
|
12
|
+
export declare function parseHost(host: string): ParsedHost;
|
|
13
|
+
//# sourceMappingURL=host.d.ts.map
|