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