build-strap 3.0.0-dev.45 → 4.0.0-dev.3

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 (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -34
  3. package/ant.d.ts +19 -0
  4. package/ant.js +12 -37
  5. package/cert.d.ts +12 -0
  6. package/cert.js +89 -151
  7. package/clean.d.ts +4 -0
  8. package/clean.js +7 -16
  9. package/copy.d.ts +7 -0
  10. package/copy.js +49 -76
  11. package/cp.d.ts +17 -0
  12. package/cp.js +85 -170
  13. package/docker.container.d.ts +73 -0
  14. package/docker.container.js +219 -362
  15. package/docker.d.ts +68 -0
  16. package/docker.js +167 -347
  17. package/docker.network.d.ts +42 -0
  18. package/docker.network.js +69 -144
  19. package/docker.volume.d.ts +26 -0
  20. package/docker.volume.js +52 -126
  21. package/dockerCleanup.d.ts +38 -0
  22. package/dockerCleanup.js +66 -141
  23. package/dockerCompose.d.ts +154 -0
  24. package/dockerCompose.js +400 -727
  25. package/fs.d.ts +5 -0
  26. package/fs.js +38 -95
  27. package/git.d.ts +9 -0
  28. package/git.js +19 -30
  29. package/index.d.ts +20 -0
  30. package/index.js +20 -27
  31. package/maps.d.ts +33 -0
  32. package/maps.js +16 -87
  33. package/npm.d.ts +42 -0
  34. package/npm.js +104 -135
  35. package/package.json +23 -19
  36. package/pkg.d.ts +39 -0
  37. package/pkg.js +26 -74
  38. package/publish.d.ts +27 -0
  39. package/publish.js +52 -140
  40. package/run.d.ts +13 -0
  41. package/run.js +39 -85
  42. package/tgz.d.ts +13 -0
  43. package/tgz.js +61 -96
  44. package/version.d.ts +34 -0
  45. package/version.js +86 -127
  46. package/yarn.d.ts +44 -0
  47. package/yarn.js +156 -119
  48. package/ant.js.flow +0 -42
  49. package/artifactory.js +0 -617
  50. package/artifactory.js.flow +0 -616
  51. package/cert.conf +0 -20
  52. package/cert.js.flow +0 -152
  53. package/clean.js.flow +0 -19
  54. package/copy.js.flow +0 -79
  55. package/cp.js.flow +0 -172
  56. package/docker.container.js.flow +0 -389
  57. package/docker.js.flow +0 -367
  58. package/docker.network.js.flow +0 -159
  59. package/docker.volume.js.flow +0 -136
  60. package/dockerCleanup.js.flow +0 -151
  61. package/dockerCompose.js.flow +0 -765
  62. package/flow.js +0 -21
  63. package/flow.js.flow +0 -20
  64. package/fs.js.flow +0 -96
  65. package/git.js.flow +0 -34
  66. package/hg.js +0 -35
  67. package/hg.js.flow +0 -34
  68. package/index.js.flow +0 -26
  69. package/inline-resources.js +0 -158
  70. package/inline-resources.js.flow +0 -157
  71. package/maps.js.flow +0 -111
  72. package/npm.js.flow +0 -144
  73. package/pkg.js.flow +0 -80
  74. package/publish.js.flow +0 -144
  75. package/run.js.flow +0 -89
  76. package/src/ant.js +0 -42
  77. package/src/artifactory.js +0 -616
  78. package/src/cert.conf +0 -20
  79. package/src/cert.js +0 -152
  80. package/src/clean.js +0 -19
  81. package/src/copy.js +0 -79
  82. package/src/cp.js +0 -172
  83. package/src/docker.container.js +0 -389
  84. package/src/docker.js +0 -367
  85. package/src/docker.network.js +0 -159
  86. package/src/docker.volume.js +0 -136
  87. package/src/dockerCleanup.js +0 -151
  88. package/src/dockerCompose.js +0 -765
  89. package/src/flow.js +0 -20
  90. package/src/fs.js +0 -96
  91. package/src/git.js +0 -34
  92. package/src/hg.js +0 -34
  93. package/src/index.js +0 -26
  94. package/src/inline-resources.js +0 -157
  95. package/src/maps.js +0 -111
  96. package/src/npm.js +0 -144
  97. package/src/pkg.js +0 -80
  98. package/src/publish.js +0 -144
  99. package/src/run.js +0 -89
  100. package/src/test.js +0 -55
  101. package/src/tgz.js +0 -101
  102. package/src/version.js +0 -141
  103. package/src/yarn.js +0 -123
  104. package/test.js +0 -56
  105. package/test.js.flow +0 -55
  106. package/tgz.js.flow +0 -101
  107. package/version.js.flow +0 -141
  108. package/yarn.js.flow +0 -123
package/docker.js.flow DELETED
@@ -1,367 +0,0 @@
1
- // @flow
2
- import path from 'path';
3
- import bytes from 'bytes';
4
- import isReachable from 'is-reachable';
5
- import moment from 'moment';
6
- import { buildLog } from './run';
7
- import { getCfg, getPkgName, getPkgScope } from './pkg';
8
- import { spawn } from './cp';
9
- import { getVersion, getDevBranch } from './version';
10
- import {
11
- dockerContainerRunDaemon,
12
- dockerContainerKill,
13
- } from './docker.container';
14
- import { dockerNetworkConnect } from './docker.network';
15
-
16
- export type DockerConfig = {
17
- registry?: string,
18
- repository?: string,
19
- name?: string,
20
- };
21
-
22
- export function getDockerConfig(): DockerConfig {
23
- return getCfg().docker || {};
24
- }
25
-
26
- export const parseDockerDate = (date: string): Date =>
27
- moment(date, 'YYYY-MM-DD HH:mm:ss ZZ').toDate();
28
-
29
- export async function dockerBuild(
30
- tags: string[] = ['latest'],
31
- buildArgs: string[] = [],
32
- target: ?string = null,
33
- extraArgs?: ?(string[]) = [],
34
- repo: string = getDockerRepo(),
35
- dockerFile: string = './Dockerfile',
36
- workDir: string = '.',
37
- ): Promise<string> {
38
- const args = [
39
- 'build',
40
- ...['-f', path.resolve(dockerFile)],
41
- ...(target ? ['--target', target] : []),
42
- ...tags.reduce((ar, t) => [...ar, '-t', `${repo}:${t}`], []),
43
- ...buildArgs.reduce((ar, a) => [...ar, '--build-arg', a], []),
44
- ...(extraArgs || []),
45
- path.resolve(workDir),
46
- ];
47
-
48
- return spawn('docker', args, { stdio: 'inherit' });
49
- }
50
-
51
- export async function dockerTag(
52
- imageId: string,
53
- tags: string[] = ['latest'],
54
- repo?: string = getDockerRepo(),
55
- ): Promise<void> {
56
- await Promise.all(
57
- tags.map(async (t) => {
58
- await spawn('docker', ['tag', imageId, `${repo}:${t}`]);
59
- buildLog(`Tagged image ${imageId} as ${repo}:${t}`);
60
- }),
61
- );
62
- }
63
-
64
- /**
65
- * Apply the standard convention for tagging the docker image for the project,
66
- * based on the source control branch being built.
67
- * For releases, applies `latest`, `M.m.p`, `M.m`, `M`
68
- * For release candidates, applies `latest-rc`
69
- * For feature branches, applies `latest-feature`
70
- * For development branch, applies `latest-dev`
71
- * All other branches, no tag is applies
72
- * @param {string} imageId id of the docker image to which to apply the tags
73
- * @param {string} repo optional override of the docker repo url to use (derived from package.json by default)
74
- */
75
- export async function dockerTagVersion(
76
- imageId: string,
77
- repo?: string = getDockerRepo(),
78
- ) {
79
- const { isRelease, major, minor, patch, branch } = await getVersion();
80
- // determine what tags to apply
81
- if (isRelease) {
82
- await dockerTag(
83
- imageId,
84
- ['latest', `${major}`, `${major}.${minor}`, `${major}.${minor}.${patch}`],
85
- repo,
86
- );
87
- } else if (branch === getDevBranch()) {
88
- await dockerTag(imageId, ['latest-dev'], repo);
89
- } else if (branch.match(/^(release|patch)-/)) {
90
- await dockerTag(imageId, ['latest-rc'], repo);
91
- } else if (branch.match(/^feature-/)) {
92
- await dockerTag(imageId, ['latest-feature'], repo);
93
- }
94
- }
95
-
96
- export type DockerImage = {
97
- repository: string,
98
- tag: string,
99
- id: string,
100
- digest: string,
101
- created: Date,
102
- size: number,
103
- };
104
-
105
- export type DockerImageFilter = (i: DockerImage) => boolean;
106
-
107
- export async function dockerImages(
108
- repo?: ?string = getDockerRepo(),
109
- filter?: ?DockerImageFilter = null,
110
- ): Promise<DockerImage[]> {
111
- return (
112
- await spawn(
113
- 'docker',
114
- ['images', '--format', `{{json .}}`, ...(repo ? [repo] : [])],
115
- { captureOutput: true },
116
- )
117
- )
118
- .split('\n')
119
- .filter((line) => !!line.trim())
120
- .map((l) => {
121
- const {
122
- Repository: repository,
123
- Tag: tag,
124
- ID: id,
125
- Digest: digest,
126
- CreatedAt,
127
- Size,
128
- } = JSON.parse(l.trim());
129
- return {
130
- repository,
131
- tag,
132
- id,
133
- digest,
134
- created: parseDockerDate(CreatedAt),
135
- size: bytes.parse(Size),
136
- };
137
- })
138
- .filter(
139
- (m) =>
140
- (m && m.id) != null &&
141
- (typeof filter === 'function' ? filter(m) : true),
142
- );
143
- }
144
-
145
- export async function getDockerId(
146
- tag: string = 'latest',
147
- repo?: ?string,
148
- ): Promise<string> {
149
- return (await dockerImages(repo, (m) => m.tag === tag)).map((m) => m.id)[0];
150
- }
151
-
152
- export async function getUntaggedDockerIds(
153
- repo?: ?string,
154
- filter?: ?DockerImageFilter = null,
155
- ): Promise<string[]> {
156
- return (
157
- await dockerImages(
158
- repo,
159
- (m) =>
160
- m.tag === '<none>' && (typeof filter === 'function' ? filter(m) : true),
161
- )
162
- ).map((m) => m.id);
163
- }
164
-
165
- export async function getDockerTags(
166
- id?: ?string,
167
- repo?: ?string,
168
- fullName: boolean = false,
169
- filter?: ?DockerImageFilter = null,
170
- ): Promise<string[]> {
171
- return (
172
- await dockerImages(
173
- repo,
174
- (m) =>
175
- (!id || m.id === id) &&
176
- (typeof filter === 'function' ? filter(m) : true),
177
- )
178
- ).map((m) => (fullName ? `${m.repository}:${m.tag}` : m.tag));
179
- }
180
-
181
- export async function getDockerDigest(
182
- imageId: string,
183
- repo?: string,
184
- ): Promise<string> {
185
- return (await dockerImages(repo, (m) => m.id === imageId)).map(
186
- (m) => m.digest,
187
- )[0];
188
- }
189
-
190
- export async function dockerLogin(
191
- user: string,
192
- password: string,
193
- registry: string,
194
- ): Promise<void> {
195
- const reg = registry || getDockerConfig().registry;
196
- await spawn(
197
- 'docker',
198
- [
199
- 'login',
200
- '-u',
201
- user || process.env.ARTIFACTORY_USER || '',
202
- '-p',
203
- password || process.env.ARTIFACTORY_PASSWORD || '',
204
- ...(reg ? [reg] : []),
205
- ],
206
- { stdio: 'inherit' },
207
- );
208
- }
209
-
210
- export async function dockerPush(
211
- tags?: string[] = ['latest'],
212
- repo?: string = getDockerRepo(),
213
- ) {
214
- // do this sequentially, so you don't push the same image simultaneously
215
- await tags.reduce(async (prev, tag) => {
216
- await prev;
217
- await spawn('docker', ['push', `${repo}:${tag}`], { stdio: 'inherit' });
218
- }, Promise.resolve());
219
- }
220
-
221
- export type DockerPullOptions = {
222
- image: string,
223
- offline?: boolean,
224
- testUrl?: ?string,
225
- };
226
-
227
- export async function dockerPull({
228
- image,
229
- offline = process.argv.includes('--offline'),
230
- testUrl,
231
- }: DockerPullOptions) {
232
- if (
233
- offline ||
234
- !(await isReachable(testUrl || 'https://hub.docker.com'))
235
- ) {
236
- if (offline === false) {
237
- throw new Error('Offline, cannot docker pull');
238
- }
239
- buildLog('It looks like you are offline, skipping docker pull');
240
- } else {
241
- // throws on failure
242
- await spawn('docker', ['pull', image], { stdio: 'inherit' });
243
- }
244
- }
245
-
246
- export async function dockerRmi(
247
- images: string[] = [],
248
- ignoreErrors: boolean = true,
249
- ): Promise<void> {
250
- // must do these sequentially, or they will interfere with each other
251
- await images.reduce(async (prev, image) => {
252
- await prev;
253
- await spawn('docker', ['rmi', image], { stdio: 'inherit' }).catch((err) => {
254
- if (ignoreErrors) {
255
- buildLog(
256
- `Warning (ignored Error): Failed to rm image(s): ${err.message}`,
257
- );
258
- } else {
259
- throw err;
260
- }
261
- });
262
- }, Promise.resolve());
263
- }
264
-
265
- export function getDockerRepo(): string {
266
- const { registry, repository: dkrRepo, name: dkrName } = getDockerConfig();
267
- const repository = dkrRepo || getPkgScope();
268
- const name = dkrName || getPkgName(false);
269
- if (!repository || !name) {
270
- throw new Error(
271
- 'Docker configuration is missing or incomplete in package.json',
272
- );
273
- }
274
- return `${registry ? `${registry}/` : ''}${repository}/${name}`;
275
- }
276
-
277
- export type PullAndRunContainerOptions = {
278
- ...DockerPullOptions,
279
- runArgs?: string[],
280
- cmd?: string[],
281
- network?: ?string,
282
- alias?: ?string,
283
- };
284
-
285
- export async function dockerPullAndRunContainer(
286
- image: string,
287
- options: PullAndRunContainerOptions = {},
288
- ): Promise<string> {
289
- const {
290
- runArgs = [],
291
- cmd = [],
292
- network,
293
- alias,
294
- offline = process.argv.includes('--offline'),
295
- testUrl,
296
- } = options;
297
-
298
- try {
299
- await dockerPull({ image, offline, testUrl });
300
- } catch (err) {
301
- buildLog(`docker pull failed (${err.message}), attempting to continue...`);
302
- }
303
- const { id } = await dockerContainerRunDaemon({ image, runArgs, cmd });
304
- if (network) {
305
- await dockerNetworkConnect(network, id, alias);
306
- }
307
- return id;
308
- }
309
-
310
- export type CopyFilePathConfig = {
311
- from: string,
312
- to: string,
313
- };
314
-
315
- export type CopyFilesFromDockerImageConfig = {
316
- imageId: string,
317
- filePaths: CopyFilePathConfig[],
318
- ignoreErrors?: ?boolean,
319
- };
320
-
321
- export async function copyFilesFromDockerImage({
322
- imageId,
323
- filePaths,
324
- ignoreErrors,
325
- }: CopyFilesFromDockerImageConfig): Promise<any> {
326
- const container = await dockerContainerRunDaemon({
327
- image: imageId,
328
- runArgs: ['-it', '--rm', '--entrypoint=/bin/bash'],
329
- cmd: ['read', '-p', 'pause'],
330
- });
331
-
332
- buildLog(`Copying Files from Docker Image - imageId (${imageId})`);
333
-
334
- const spawnOptions = {
335
- stdio: 'inherit',
336
- pipeOutput: true,
337
- captureOutput: false,
338
- };
339
- const copyErrors = [];
340
-
341
- try {
342
- filePaths.forEach(async (fp) => {
343
- // Try to copy from the Debug Folder
344
- try {
345
- await spawn(
346
- 'docker',
347
- ['cp', `${container.id}:${fp.from}`, fp.to],
348
- spawnOptions,
349
- );
350
- buildLog(`Copied ${fp.from} => ${fp.to}`);
351
- } catch (error) {
352
- copyErrors.push(error);
353
- buildLog(`Error copying file ${fp.from}`);
354
- }
355
- });
356
- } finally {
357
- try {
358
- await dockerContainerKill(container.id);
359
- } catch (error) {
360
- copyErrors.push(error);
361
- }
362
- }
363
-
364
- if (copyErrors.length > 0 && ignoreErrors !== true) {
365
- throw new Error('Some files failed to copy');
366
- }
367
- }
@@ -1,159 +0,0 @@
1
- // @flow
2
- import throttle from 'lodash/throttle';
3
- import { spawn } from './cp';
4
- import { parseDockerDate } from './docker';
5
-
6
- export type DockerNetwork = {|
7
- id: string,
8
- name: string,
9
- driver: string,
10
- scope: string,
11
- created: Date,
12
- IPv6: boolean,
13
- labels: string[],
14
- exists: () => Promise<boolean>,
15
- rm: () => Promise<void>,
16
- |};
17
-
18
- type DockerNetworkLsOptions = {
19
- filter?: (network: DockerNetwork) => boolean,
20
- };
21
-
22
- // calling this function in rapid succession can lead to errors.
23
- // prefer throttled version
24
- export async function _dockerNetworkLs({
25
- filter,
26
- }: DockerNetworkLsOptions = {}): Promise<DockerNetwork[]> {
27
- return (
28
- await spawn('docker', ['network', 'ls', '--format', '{{json .}}'], {
29
- captureOutput: true,
30
- })
31
- )
32
- .split('\n')
33
- .filter((line) => !!line.trim())
34
- .map((line) => {
35
- const {
36
- ID: id,
37
- Name: name,
38
- Driver: driver,
39
- Scope: scope,
40
- CreatedAt,
41
- IPv6,
42
- Labels,
43
- } = JSON.parse(line.trim());
44
- return {
45
- id,
46
- name,
47
- driver,
48
- scope,
49
- created: parseDockerDate(CreatedAt),
50
- IPv6: IPv6 === 'true',
51
- labels: Labels.split(',').map((l) => l.trim()),
52
- exists: async () => !!(await dockerNetworkFind(id)),
53
- rm: async () => dockerNetworkRm(id),
54
- };
55
- })
56
- .filter((n) => n.id && (typeof filter === 'function' ? filter(n) : true));
57
- }
58
- export const dockerNetworkLs: (
59
- DockerNetworkLsOptions | void,
60
- ) => Promise<DockerNetwork[]> = throttle(_dockerNetworkLs, 500, {
61
- trailing: false,
62
- });
63
-
64
- export async function dockerNetworkFind(
65
- networkName: string,
66
- options?: DockerNetworkLsOptions,
67
- ): Promise<?DockerNetwork> {
68
- return (await dockerNetworkLs(options)).find(
69
- (n) => n.name === networkName || n.id === networkName,
70
- );
71
- }
72
-
73
- export type DockerNetworkCreateOptions = {|
74
- driver?: string,
75
- driverOpts?: { [string]: string },
76
- ipRange?: string,
77
- gateways?: string[],
78
- subnets?: string[],
79
- auxAddresses?: string[],
80
- ingress?: boolean,
81
- internal?: boolean,
82
- ipv6?: boolean,
83
- labels?: string[],
84
- |};
85
-
86
- export async function dockerNetworkCreate(
87
- networkName: string,
88
- {
89
- driver,
90
- driverOpts = {},
91
- ipRange,
92
- gateways = [],
93
- subnets = [],
94
- auxAddresses = [],
95
- ingress,
96
- internal,
97
- ipv6,
98
- labels = [],
99
- }: DockerNetworkCreateOptions = {},
100
- ): Promise<?DockerNetwork> {
101
- const existing = await dockerNetworkFind(networkName);
102
- if (existing) return existing;
103
- await spawn('docker', [
104
- 'network',
105
- 'create',
106
- ...labels.flatMap((l) => ['--label', l]),
107
- ...gateways.flatMap((g) => ['--gateway', g]),
108
- ...subnets.flatMap((s) => ['--subnet', s]),
109
- ...auxAddresses.flatMap((a) => ['--aux-address', a]),
110
- ...(ipRange ? ['--ip-range', ipRange] : []),
111
- ...(ingress ? ['--ingress'] : []),
112
- ...(internal ? ['--internal'] : []),
113
- ...(ipv6 ? ['--ipv6'] : []),
114
- ...(driver ? ['-d', driver] : []),
115
- ...Object.entries(driverOpts).flatMap(([k, v]) => [
116
- '-o',
117
- `${k}=${(v: any)}`,
118
- ]),
119
- networkName,
120
- ]);
121
- return dockerNetworkFind(networkName);
122
- }
123
-
124
- /**
125
- * Removes a network by id
126
- * @param {string} id The id of the network
127
- */
128
- export async function dockerNetworkRm(id: string) {
129
- await spawn('docker', ['network', 'rm', id]);
130
- }
131
-
132
- /**
133
- * Removes all networks with the given name
134
- * @param {string} networkName The name of the network
135
- */
136
- export async function dockerNetworkDelete(networkName: string) {
137
- let existing;
138
- // eslint-disable-next-line no-cond-assign, no-await-in-loop
139
- while ((existing = await dockerNetworkFind(networkName))) {
140
- // eslint-disable-next-line no-await-in-loop
141
- await existing.rm();
142
- }
143
- }
144
-
145
- export async function dockerNetworkConnect(
146
- networkName: string,
147
- containerId: string,
148
- alias?: ?string,
149
- ) {
150
- const net = await dockerNetworkCreate(networkName);
151
- if (!net) throw new Error('Failed to create docker network');
152
- await spawn('docker', [
153
- 'network',
154
- 'connect',
155
- ...(alias ? ['--alias', alias] : []),
156
- net.id,
157
- containerId,
158
- ]);
159
- }
@@ -1,136 +0,0 @@
1
- // @flow
2
- import throttle from 'lodash/throttle';
3
- import { spawn } from './cp';
4
-
5
- type DockerVolumeInspectOutput = {
6
- [string]: any,
7
- };
8
-
9
- export type DockerVolume = {|
10
- name: string,
11
- driver: string,
12
- scope: string,
13
- labels: string[],
14
- mountPoint: string,
15
- inspect: () => Promise<DockerVolumeInspectOutput>,
16
- rm: () => Promise<void>,
17
- |};
18
-
19
- type DockerVolumeLsOptions = {
20
- filter?: (vol: DockerVolume) => boolean,
21
- };
22
-
23
- // calling this function in rapid succession can lead to errors.
24
- // prefer throttled version
25
- export async function _dockerVolumeLs({
26
- filter,
27
- }: DockerVolumeLsOptions = {}): Promise<DockerVolume[]> {
28
- return (
29
- await spawn('docker', ['volume', 'ls', '--format', '{{json .}}'], {
30
- captureOutput: true,
31
- })
32
- )
33
- .split('\n')
34
- .filter((line) => !!line.trim())
35
- .map((line) => {
36
- const {
37
- Name: name,
38
- Driver: driver,
39
- Scope: scope,
40
- Labels,
41
- Mountpoint: mountPoint,
42
- } = JSON.parse(line.trim());
43
-
44
- return {
45
- name,
46
- driver,
47
- scope,
48
- labels: Labels.split(',').map((l) => l.trim()),
49
- mountPoint,
50
- inspect: async () => (await dockerVolumeInspect(name))[0],
51
- rm: async () => dockerVolumeRm(name),
52
- };
53
- })
54
- .filter((v) => v.name && (typeof filter === 'function' ? filter(v) : true));
55
- }
56
-
57
- export const dockerVolumeLs: (
58
- DockerVolumeLsOptions | void,
59
- ) => Promise<DockerVolume[]> = throttle(_dockerVolumeLs, 500, {
60
- trailing: false,
61
- });
62
-
63
- export async function dockerVolumeFind(
64
- search: string,
65
- options?: DockerVolumeLsOptions,
66
- ): Promise<?DockerVolume> {
67
- return (await dockerVolumeLs(options)).find(
68
- (v) => v.name === search || v.name.startsWith(search),
69
- );
70
- }
71
-
72
- export type DockerVolumeCreateOptions = {|
73
- labels?: string[],
74
- driver?: string,
75
- driverOpts?: { [string]: string },
76
- |};
77
- export async function dockerVolumeCreate(
78
- name: string,
79
- { labels = [], driver, driverOpts = {} }: DockerVolumeCreateOptions = {},
80
- ): Promise<?DockerVolume> {
81
- const existing = await dockerVolumeFind(name);
82
- if (existing) return existing;
83
- await spawn('docker', [
84
- 'volume',
85
- 'create',
86
- ...labels.flatMap((l) => ['--label', l]),
87
- ...(driver ? ['-d', driver] : []),
88
- ...Object.entries(driverOpts).flatMap(([k, v]) => [
89
- '-o',
90
- `${k}=${(v: any)}`,
91
- ]),
92
- name,
93
- ]);
94
- return dockerVolumeFind(name);
95
- }
96
-
97
- export async function dockerVolumeRm(
98
- id: string | string[],
99
- ignoreErrors: boolean = true,
100
- ) {
101
- const ids = Array.isArray(id) ? id : [id];
102
- try {
103
- await spawn('docker', ['volume', 'rm', ...ids]);
104
- } catch (e) {
105
- if (!ignoreErrors) {
106
- throw new Error(`Failed to remove volume(s): ${e.message}`);
107
- }
108
- }
109
- }
110
-
111
- // calling this function in rapid succession can lead to errors.
112
- // prefer throttled version
113
- export async function _dockerVolumeInspect(
114
- id: string | string[],
115
- ): Promise<DockerVolumeInspectOutput[]> {
116
- const ids = Array.isArray(id) ? id : [id];
117
- return (
118
- JSON.parse(
119
- (
120
- await spawn(
121
- 'docker',
122
- ['volume', 'inspect', '--format', '{{json .}}', ...ids],
123
- { captureOutput: true },
124
- )
125
- ).trim(),
126
- ) || []
127
- );
128
- }
129
-
130
- export const dockerVolumeInspect: (
131
- string | string[],
132
- ) => Promise<DockerVolumeInspectOutput[]> = throttle(
133
- _dockerVolumeInspect,
134
- 500,
135
- { trailing: true },
136
- );