@zukhruf/docker 0.3.33 → 0.3.34
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 +26 -12
- package/dist/container-process.d.ts +35 -0
- package/dist/container-process.d.ts.map +1 -0
- package/dist/container-process.js +91 -0
- package/dist/container-process.js.map +1 -0
- package/dist/containers.d.ts +160 -0
- package/dist/containers.d.ts.map +1 -0
- package/dist/containers.js +700 -0
- package/dist/containers.js.map +1 -0
- package/dist/docker.d.ts +25 -2
- package/dist/docker.d.ts.map +1 -1
- package/dist/docker.js +43 -7
- package/dist/docker.js.map +1 -1
- package/dist/engine-api.d.ts +369 -0
- package/dist/engine-api.d.ts.map +1 -1
- package/dist/engine-client.d.ts +52 -4
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +167 -31
- package/dist/engine-client.js.map +1 -1
- package/dist/errors.d.ts +95 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +156 -6
- package/dist/errors.js.map +1 -1
- package/dist/images.d.ts +40 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +173 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/multiplexed-stream.d.ts +11 -0
- package/dist/multiplexed-stream.d.ts.map +1 -0
- package/dist/multiplexed-stream.js +81 -0
- package/dist/multiplexed-stream.js.map +1 -0
- package/dist/ndjson.d.ts +7 -0
- package/dist/ndjson.d.ts.map +1 -0
- package/dist/ndjson.js +21 -0
- package/dist/ndjson.js.map +1 -0
- package/dist/networks.d.ts +46 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/networks.js +170 -0
- package/dist/networks.js.map +1 -0
- package/dist/output.d.ts +18 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +21 -0
- package/dist/output.js.map +1 -0
- package/dist/progress.d.ts +9 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +20 -0
- package/dist/progress.js.map +1 -0
- package/dist/ssh-connection.d.ts +3 -0
- package/dist/ssh-connection.d.ts.map +1 -1
- package/dist/ssh-connection.js +46 -10
- package/dist/ssh-connection.js.map +1 -1
- package/dist/tar-reader.d.ts +22 -0
- package/dist/tar-reader.d.ts.map +1 -0
- package/dist/tar-reader.js +163 -0
- package/dist/tar-reader.js.map +1 -0
- package/dist/tar-writer.d.ts +16 -0
- package/dist/tar-writer.d.ts.map +1 -0
- package/dist/tar-writer.js +114 -0
- package/dist/tar-writer.js.map +1 -0
- package/dist/transport.d.ts +11 -1
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +34 -2
- package/dist/transport.js.map +1 -1
- package/dist/volumes.d.ts +41 -0
- package/dist/volumes.d.ts.map +1 -0
- package/dist/volumes.js +119 -0
- package/dist/volumes.js.map +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Container, Created } from './containers.ts';
|
|
2
|
+
import type * as EngineApi from './engine-api.ts';
|
|
3
|
+
import { type EngineClient } from './engine-client.ts';
|
|
4
|
+
import type { CancelOptions, Filters } from './options.ts';
|
|
5
|
+
/** A network, by the ID that the engine gave it. It has no disposal. */
|
|
6
|
+
export declare class Network {
|
|
7
|
+
#private;
|
|
8
|
+
readonly id: string;
|
|
9
|
+
constructor(client: EngineClient, id: string);
|
|
10
|
+
inspect(options?: CancelOptions): Promise<EngineApi.NetworkInspect>;
|
|
11
|
+
connect(container: Container, endpoint?: EngineApi.NetworkConnectRequest['EndpointConfig'], options?: CancelOptions): Promise<void>;
|
|
12
|
+
disconnect(container: Container, options?: CancelOptions & {
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves for 404. A 403 is a pre-defined network or a network with
|
|
17
|
+
* connected containers: an inspect tells which. A pre-defined network can
|
|
18
|
+
* have connected containers too, so its name decides first. Only a running
|
|
19
|
+
* container has an endpoint, so only a running one keeps the network.
|
|
20
|
+
*/
|
|
21
|
+
remove(options?: CancelOptions): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/** A network that this handle created. Disposal removes it. */
|
|
24
|
+
export declare class OwnedNetwork extends Network implements AsyncDisposable {
|
|
25
|
+
/** remove() */
|
|
26
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** The networks of one engine. */
|
|
29
|
+
export declare class Networks {
|
|
30
|
+
#private;
|
|
31
|
+
constructor(client: EngineClient);
|
|
32
|
+
/** From API 1.44, the engine refuses a taken name with 409: it rejects with NameConflictError. */
|
|
33
|
+
create(body: EngineApi.NetworkCreateRequest, options?: CancelOptions): Promise<OwnedNetwork>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates the network, or gives the one that has the name. The network that
|
|
36
|
+
* exists wins. When that network is removed between the 409 and the
|
|
37
|
+
* inspect, the create runs again.
|
|
38
|
+
*/
|
|
39
|
+
createOrGet(body: EngineApi.NetworkCreateRequest, options?: CancelOptions): Promise<Created<'network', OwnedNetwork, Network>>;
|
|
40
|
+
/** One inspect: a handle with the ID of the engine, or undefined for 404. */
|
|
41
|
+
find(nameOrId: string, options?: CancelOptions): Promise<Network | undefined>;
|
|
42
|
+
list(options?: CancelOptions & {
|
|
43
|
+
filters?: Filters;
|
|
44
|
+
}): Promise<EngineApi.NetworkSummary[]>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAO7E,OAAO,KAAK,EAAE,a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,GAAG,SAAS,CAAC;IAUzB,IAAI,CACR,OAAO,GAAE,aAAa,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO,GAClD,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;CAMvC"}
|
package/dist/networks.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { isSuccess, parseBody } from "./engine-client.js";
|
|
2
|
+
import { ContainerNotFoundError, NameConflictError, NetworkInUseError, NetworkNotFoundError, } from "./errors.js";
|
|
3
|
+
/** The networks that the engine defines and never removes: runconfig.IsPreDefinedNetwork of Moby. */
|
|
4
|
+
const PREDEFINED_NETWORKS = new Set(['bridge', 'host', 'none']);
|
|
5
|
+
/** A network, by the ID that the engine gave it. It has no disposal. */
|
|
6
|
+
export class Network {
|
|
7
|
+
id;
|
|
8
|
+
#client;
|
|
9
|
+
constructor(client, id) {
|
|
10
|
+
this.#client = client;
|
|
11
|
+
this.id = id;
|
|
12
|
+
}
|
|
13
|
+
get #path() {
|
|
14
|
+
return `/networks/${encodeURIComponent(this.id)}`;
|
|
15
|
+
}
|
|
16
|
+
async inspect(options = {}) {
|
|
17
|
+
const method = 'GET';
|
|
18
|
+
const path = this.#path;
|
|
19
|
+
const response = await this.#client.exchange(method, path, options);
|
|
20
|
+
if (isSuccess(response)) {
|
|
21
|
+
return parseBody(response);
|
|
22
|
+
}
|
|
23
|
+
const error = this.#client.error(response, method, path);
|
|
24
|
+
if (response.status !== 404)
|
|
25
|
+
throw error;
|
|
26
|
+
throw new NetworkNotFoundError(error.message, error, this.id, {
|
|
27
|
+
cause: error,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async connect(container, endpoint, options = {}) {
|
|
31
|
+
const body = { Container: container.id, EndpointConfig: endpoint };
|
|
32
|
+
await this.#endpoint('connect', container, body, options);
|
|
33
|
+
}
|
|
34
|
+
async disconnect(container, options = {}) {
|
|
35
|
+
const body = { Container: container.id, Force: options.force };
|
|
36
|
+
await this.#endpoint('disconnect', container, body, options);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Resolves for 404. A 403 is a pre-defined network or a network with
|
|
40
|
+
* connected containers: an inspect tells which. A pre-defined network can
|
|
41
|
+
* have connected containers too, so its name decides first. Only a running
|
|
42
|
+
* container has an endpoint, so only a running one keeps the network.
|
|
43
|
+
*/
|
|
44
|
+
async remove(options = {}) {
|
|
45
|
+
const method = 'DELETE';
|
|
46
|
+
const path = this.#path;
|
|
47
|
+
const response = await this.#client.exchange(method, path, options);
|
|
48
|
+
if (isSuccess(response) || response.status === 404)
|
|
49
|
+
return;
|
|
50
|
+
const error = this.#client.error(response, method, path);
|
|
51
|
+
if (response.status !== 403)
|
|
52
|
+
throw error;
|
|
53
|
+
const inspect = await this.#client.exchange('GET', path, options);
|
|
54
|
+
if (inspect.status === 404)
|
|
55
|
+
return;
|
|
56
|
+
if (!isSuccess(inspect))
|
|
57
|
+
throw error;
|
|
58
|
+
const network = parseBody(inspect);
|
|
59
|
+
if (PREDEFINED_NETWORKS.has(network.Name))
|
|
60
|
+
throw error;
|
|
61
|
+
const containers = Object.keys(network.Containers ?? {});
|
|
62
|
+
if (containers.length === 0)
|
|
63
|
+
throw error;
|
|
64
|
+
throw new NetworkInUseError(error.message, error, this.id, containers, {
|
|
65
|
+
cause: error,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A 404 of a connect or a disconnect is a missing network or a missing
|
|
70
|
+
* container: an inspect of the network tells which. An engine in swarm mode
|
|
71
|
+
* answers a missing network with 500 ("Could not attach to network", probed
|
|
72
|
+
* at API 1.51), so a 500 gets the same inspect.
|
|
73
|
+
*/
|
|
74
|
+
async #endpoint(action, container, body, options) {
|
|
75
|
+
const method = 'POST';
|
|
76
|
+
const path = `${this.#path}/${action}`;
|
|
77
|
+
const response = await this.#client.exchange(method, path, {
|
|
78
|
+
body,
|
|
79
|
+
signal: options.signal,
|
|
80
|
+
});
|
|
81
|
+
if (isSuccess(response))
|
|
82
|
+
return;
|
|
83
|
+
const error = this.#client.error(response, method, path);
|
|
84
|
+
if (response.status !== 404 && response.status !== 500)
|
|
85
|
+
throw error;
|
|
86
|
+
const inspect = await this.#client.exchange('GET', this.#path, options);
|
|
87
|
+
if (inspect.status === 404) {
|
|
88
|
+
throw new NetworkNotFoundError(error.message, error, this.id, {
|
|
89
|
+
cause: error,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (response.status === 500)
|
|
93
|
+
throw error;
|
|
94
|
+
throw new ContainerNotFoundError(error.message, error, container.id, {
|
|
95
|
+
cause: error,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** A network that this handle created. Disposal removes it. */
|
|
100
|
+
export class OwnedNetwork extends Network {
|
|
101
|
+
/** remove() */
|
|
102
|
+
async [Symbol.asyncDispose]() {
|
|
103
|
+
await this.remove();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The networks of one engine. */
|
|
107
|
+
export class Networks {
|
|
108
|
+
#client;
|
|
109
|
+
constructor(client) {
|
|
110
|
+
this.#client = client;
|
|
111
|
+
}
|
|
112
|
+
/** From API 1.44, the engine refuses a taken name with 409: it rejects with NameConflictError. */
|
|
113
|
+
async create(body, options = {}) {
|
|
114
|
+
const method = 'POST';
|
|
115
|
+
const path = '/networks/create';
|
|
116
|
+
const response = await this.#client.exchange(method, path, {
|
|
117
|
+
body,
|
|
118
|
+
signal: options.signal,
|
|
119
|
+
});
|
|
120
|
+
if (isSuccess(response)) {
|
|
121
|
+
const { Id } = parseBody(response);
|
|
122
|
+
return new OwnedNetwork(this.#client, Id);
|
|
123
|
+
}
|
|
124
|
+
const error = this.#client.error(response, method, path);
|
|
125
|
+
if (response.status === 409) {
|
|
126
|
+
throw new NameConflictError(error.message, error, 'network', body.Name, {
|
|
127
|
+
cause: error,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates the network, or gives the one that has the name. The network that
|
|
134
|
+
* exists wins. When that network is removed between the 409 and the
|
|
135
|
+
* inspect, the create runs again.
|
|
136
|
+
*/
|
|
137
|
+
async createOrGet(body, options = {}) {
|
|
138
|
+
for (;;) {
|
|
139
|
+
try {
|
|
140
|
+
return { created: true, network: await this.create(body, options) };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (!(error instanceof NameConflictError))
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
const network = await this.find(body.Name, options);
|
|
147
|
+
if (network)
|
|
148
|
+
return { created: false, network };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** One inspect: a handle with the ID of the engine, or undefined for 404. */
|
|
152
|
+
async find(nameOrId, options = {}) {
|
|
153
|
+
const method = 'GET';
|
|
154
|
+
const path = `/networks/${encodeURIComponent(nameOrId)}`;
|
|
155
|
+
const response = await this.#client.exchange(method, path, options);
|
|
156
|
+
if (response.status === 404)
|
|
157
|
+
return undefined;
|
|
158
|
+
if (!isSuccess(response))
|
|
159
|
+
throw this.#client.error(response, method, path);
|
|
160
|
+
const { Id } = parseBody(response);
|
|
161
|
+
return new Network(this.#client, Id);
|
|
162
|
+
}
|
|
163
|
+
async list(options = {}) {
|
|
164
|
+
return this.#client.json('GET', '/networks', {
|
|
165
|
+
query: { filters: options.filters },
|
|
166
|
+
signal: options.signal,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=networks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAGrB,qGAAqG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EAAE,EAAE,EAAE,GAAG,SAAS,CAA2B,QAAQ,CAAC,CAAC;QAC7D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI,CACR,UAAiD,EAAE;QAEnD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAA6B,KAAK,EAAE,WAAW,EAAE;YACvE,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;YACnC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OutputChunk } from './multiplexed-stream.ts';
|
|
2
|
+
export interface Output {
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
/** Standard output and standard error, in the order of the engine. */
|
|
6
|
+
output: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ExecResult extends Output {
|
|
9
|
+
exitCode: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Reads each chunk and decodes the text of each stream. A chunk can end inside
|
|
13
|
+
* a UTF-8 character: the character waits for the next chunk of the same
|
|
14
|
+
* stream, and `output` gets it then, so a chunk of the other stream between
|
|
15
|
+
* the two parts never breaks it. The text is not trimmed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readOutput(chunks: AsyncIterable<OutputChunk>): Promise<Output>;
|
|
18
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAW,SAAQ,MAAM;IACxC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,GACjC,OAAO,CAAC,MAAM,CAAC,CAajB"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads each chunk and decodes the text of each stream. A chunk can end inside
|
|
3
|
+
* a UTF-8 character: the character waits for the next chunk of the same
|
|
4
|
+
* stream, and `output` gets it then, so a chunk of the other stream between
|
|
5
|
+
* the two parts never breaks it. The text is not trimmed.
|
|
6
|
+
*/
|
|
7
|
+
export async function readOutput(chunks) {
|
|
8
|
+
const decoders = { stdout: new TextDecoder(), stderr: new TextDecoder() };
|
|
9
|
+
const text = { stdout: '', stderr: '', output: '' };
|
|
10
|
+
const append = (stream, piece) => {
|
|
11
|
+
text[stream] += piece;
|
|
12
|
+
text.output += piece;
|
|
13
|
+
};
|
|
14
|
+
for await (const { stream, data } of chunks) {
|
|
15
|
+
append(stream, decoders[stream].decode(data, { stream: true }));
|
|
16
|
+
}
|
|
17
|
+
append('stdout', decoders.stdout.decode());
|
|
18
|
+
append('stderr', decoders.stderr.decode());
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAkC;IAElC,MAAM,QAAQ,GAAG,EAAE,MAAM,EAAE,IAAI,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,WAAW,EAAE,EAAE,CAAC;IAC1E,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACpD,MAAM,MAAM,GAAG,CAAC,MAA6B,EAAE,KAAa,EAAE,EAAE;QAC9D,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC;QACtB,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;IACvB,CAAC,CAAC;IACF,IAAI,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;QAC5C,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the progress of the engine to its end. The engine reports an error in
|
|
3
|
+
* the progress after the status 200, so the DockerEngineError has no status.
|
|
4
|
+
*/
|
|
5
|
+
export declare function readProgress(chunks: AsyncIterable<Uint8Array>, request: {
|
|
6
|
+
method: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,EACjC,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxC,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
package/dist/progress.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DockerEngineError } from "./errors.js";
|
|
2
|
+
import { ndjson } from "./ndjson.js";
|
|
3
|
+
function isProgressMessage(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Reads the progress of the engine to its end. The engine reports an error in
|
|
8
|
+
* the progress after the status 200, so the DockerEngineError has no status.
|
|
9
|
+
*/
|
|
10
|
+
export async function readProgress(chunks, request) {
|
|
11
|
+
for await (const message of ndjson(chunks)) {
|
|
12
|
+
if (!isProgressMessage(message))
|
|
13
|
+
continue;
|
|
14
|
+
const text = message.errorDetail?.message ?? message.error;
|
|
15
|
+
if (text !== undefined) {
|
|
16
|
+
throw new DockerEngineError(text, { status: undefined, request });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAiC,EACjC,OAAyC;IAEzC,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;YAAE,SAAS;QAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC;QAC3D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/ssh-connection.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ClientRequest, type RequestOptions } from 'node:http';
|
|
2
|
+
import { Duplex } from 'node:stream';
|
|
2
3
|
import type { Transport } from './transport.ts';
|
|
3
4
|
/** `ssh` exited before the engine answered. It is the cause of a ConnectionFailedError. */
|
|
4
5
|
export declare class SshExitError extends Error {
|
|
@@ -15,6 +16,8 @@ export declare class SshTransport implements Transport {
|
|
|
15
16
|
#private;
|
|
16
17
|
constructor(url: URL);
|
|
17
18
|
request(options: RequestOptions): ClientRequest;
|
|
19
|
+
/** Ends the standard input of `ssh`: `docker system dial-stdio` then closes the write side to the engine. */
|
|
20
|
+
endInput(socket: Duplex): void;
|
|
18
21
|
close(): Promise<void>;
|
|
19
22
|
}
|
|
20
23
|
//# sourceMappingURL=ssh-connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-connection.d.ts","sourceRoot":"","sources":["../src/ssh-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EAEpB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"ssh-connection.d.ts","sourceRoot":"","sources":["../src/ssh-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EAEpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD,2FAA2F;AAC3F,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IACvC,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGtB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,EAC7B,MAAM,EAAE,MAAM;CAUjB;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,CAc/C;AA4LD,4FAA4F;AAC5F,qBAAa,YAAa,YAAW,SAAS;;gBAGhC,GAAG,EAAE,GAAG;IAIpB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa;IAI/C,6GAA6G;IAC7G,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
package/dist/ssh-connection.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { Agent, request, } from 'node:http';
|
|
3
3
|
import { Socket } from 'node:net';
|
|
4
4
|
import { Duplex } from 'node:stream';
|
|
5
|
+
import { finished } from 'node:stream/promises';
|
|
5
6
|
/** The part of the standard error of `ssh` that an SshExitError keeps: the last 4 KB. */
|
|
6
7
|
const STDERR_LIMIT = 4096;
|
|
7
8
|
/** `ssh` exited before the engine answered. It is the cause of a ConnectionFailedError. */
|
|
@@ -27,7 +28,8 @@ export function sshArguments(url) {
|
|
|
27
28
|
...(url.username ? ['-l', decodeURIComponent(url.username)] : []),
|
|
28
29
|
...(url.port ? ['-p', url.port] : []),
|
|
29
30
|
'--',
|
|
30
|
-
|
|
31
|
+
// An IPv6 address keeps its brackets in a URL; ssh takes it without them, as URL.Hostname() of Go gives it.
|
|
32
|
+
url.hostname.replace(/^\[(.*)\]$/, '$1'),
|
|
31
33
|
'docker',
|
|
32
34
|
'system',
|
|
33
35
|
'dial-stdio',
|
|
@@ -79,6 +81,10 @@ class SshConnection extends Duplex {
|
|
|
79
81
|
// The write callback reports it, after the exit of `ssh` gives the reason.
|
|
80
82
|
child.stdin.on('error', () => undefined);
|
|
81
83
|
}
|
|
84
|
+
/** True until `ssh` exits. */
|
|
85
|
+
get running() {
|
|
86
|
+
return this.#child.exitCode === null && this.#child.signalCode === null;
|
|
87
|
+
}
|
|
82
88
|
/** The exit of `ssh` as an error, or undefined while it runs or when it exited with 0. */
|
|
83
89
|
#exitError() {
|
|
84
90
|
const { exitCode, signalCode } = this.#child;
|
|
@@ -87,9 +93,20 @@ class SshConnection extends Duplex {
|
|
|
87
93
|
}
|
|
88
94
|
return new SshExitError(exitCode, signalCode, this.#stderr);
|
|
89
95
|
}
|
|
90
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Gives the exit of `ssh` in place of an error of its pipes, when `ssh`
|
|
98
|
+
* exited. When `ssh` exited with 0, its output is complete: the reader gets
|
|
99
|
+
* the end of the output before the error of the write, so a command that
|
|
100
|
+
* does not read all of its input still gives its output.
|
|
101
|
+
*/
|
|
91
102
|
#fail(error, callback) {
|
|
92
|
-
void this.exited().then(() =>
|
|
103
|
+
void this.exited().then(async () => {
|
|
104
|
+
const exit = this.#exitError();
|
|
105
|
+
if (exit === undefined) {
|
|
106
|
+
await finished(this, { writable: false }).catch(() => undefined);
|
|
107
|
+
}
|
|
108
|
+
callback(exit ?? error);
|
|
109
|
+
});
|
|
93
110
|
}
|
|
94
111
|
_read() {
|
|
95
112
|
this.#child.stdout.resume();
|
|
@@ -152,18 +169,33 @@ class SshAgent extends Agent {
|
|
|
152
169
|
createConnection() {
|
|
153
170
|
const connection = new SshConnection(this.#url);
|
|
154
171
|
this.#connections.add(connection);
|
|
155
|
-
void connection.exited().then(() =>
|
|
172
|
+
void connection.exited().then(() => {
|
|
173
|
+
this.#connections.delete(connection);
|
|
174
|
+
// An idle connection whose `ssh` exited, such as after a restart of the
|
|
175
|
+
// engine, cannot take the next request. Its close removes it from the
|
|
176
|
+
// free connections of the agent.
|
|
177
|
+
if (this.#isIdle(connection))
|
|
178
|
+
connection.destroy();
|
|
179
|
+
});
|
|
156
180
|
return connection;
|
|
157
181
|
}
|
|
182
|
+
#isIdle(connection) {
|
|
183
|
+
return Object.values(this.freeSockets).some((sockets) => sockets?.some((socket) => Object.is(socket, connection)));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The keepSocketAlive of Node sets a timeout and TCP keep-alive, which a
|
|
187
|
+
* connection through `ssh` does not have. The reuseSocket of Node stays: it
|
|
188
|
+
* removes the error listener of the idle connection and calls ref(). A
|
|
189
|
+
* connection whose `ssh` exited is not kept.
|
|
190
|
+
*/
|
|
158
191
|
keepSocketAlive(socket) {
|
|
159
|
-
if (socket instanceof SshConnection)
|
|
160
|
-
|
|
192
|
+
if (!(socket instanceof SshConnection))
|
|
193
|
+
return true;
|
|
194
|
+
if (!socket.running)
|
|
195
|
+
return false;
|
|
196
|
+
socket.unref();
|
|
161
197
|
return true;
|
|
162
198
|
}
|
|
163
|
-
reuseSocket(socket) {
|
|
164
|
-
if (socket instanceof SshConnection)
|
|
165
|
-
socket.ref();
|
|
166
|
-
}
|
|
167
199
|
/** Ends each `ssh` process and resolves when each one exited. */
|
|
168
200
|
async close() {
|
|
169
201
|
const connections = [...this.#connections];
|
|
@@ -182,6 +214,10 @@ export class SshTransport {
|
|
|
182
214
|
request(options) {
|
|
183
215
|
return request({ ...options, agent: this.#agent });
|
|
184
216
|
}
|
|
217
|
+
/** Ends the standard input of `ssh`: `docker system dial-stdio` then closes the write side to the engine. */
|
|
218
|
+
endInput(socket) {
|
|
219
|
+
socket.end();
|
|
220
|
+
}
|
|
185
221
|
async close() {
|
|
186
222
|
await this.#agent.close();
|
|
187
223
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-connection.js","sourceRoot":"","sources":["../src/ssh-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;A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C3C,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,KAAK,MAAM,UAAU,IAAI,WAAW;YAAE,UAAU,CAAC,OAAO,EAAE,CAAC;QAC3D,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF;AAED,4FAA4F;AAC5F,MAAM,OAAO,YAAY;IACd,MAAM,CAAW;IAE1B,YAAY,GAAQ;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,CAAC,OAAuB;QAC7B,OAAO,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,6GAA6G;IAC7G,QAAQ,CAAC,MAAc;QACrB,MAAM,CAAC,GAAG,EAAE,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** One entry of a tar archive, with its bytes. */
|
|
2
|
+
export interface TarEntry {
|
|
3
|
+
/** The name in the archive, without a trailing '/'. */
|
|
4
|
+
path: string;
|
|
5
|
+
/** 'link' is a hard link; 'other' is a device, a FIFO or another kind. */
|
|
6
|
+
type: 'file' | 'directory' | 'symlink' | 'link' | 'other';
|
|
7
|
+
mode: number;
|
|
8
|
+
uid: number;
|
|
9
|
+
gid: number;
|
|
10
|
+
/** Seconds since the Unix epoch. */
|
|
11
|
+
mtime: number;
|
|
12
|
+
/** The target of a symlink or of a hard link; '' for each other entry. */
|
|
13
|
+
linkTarget: string;
|
|
14
|
+
data: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The entries of a tar archive, as the chunks come. It takes ustar, PAX
|
|
18
|
+
* headers for one entry ('x'), and the GNU long name ('L') and long link
|
|
19
|
+
* ('K'). It skips a global PAX header ('g'). Each entry comes with its bytes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function tarEntries(chunks: AsyncIterable<Uint8Array>): AsyncGenerator<TarEntry>;
|
|
22
|
+
//# sourceMappingURL=tar-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tar-reader.d.ts","sourceRoot":"","sources":["../src/tar-reader.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,WAAW,QAAQ;IACvB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB;AAwGD;;;;GAIG;AACH,wBAAuB,UAAU,CAC/B,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,GAChC,cAAc,CAAC,QAAQ,CAAC,CA4D1B"}
|