build-strap 3.0.0 → 4.0.0-dev.4
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 +1 -1
- package/README.md +3 -34
- package/ant.d.ts +19 -0
- package/ant.js +12 -37
- package/cert.d.ts +12 -0
- package/cert.js +89 -151
- package/clean.d.ts +4 -0
- package/clean.js +7 -16
- package/copy.d.ts +7 -0
- package/copy.js +49 -76
- package/cp.d.ts +17 -0
- package/cp.js +85 -170
- package/docker.container.d.ts +73 -0
- package/docker.container.js +219 -362
- package/docker.d.ts +68 -0
- package/docker.js +167 -347
- package/docker.network.d.ts +42 -0
- package/docker.network.js +69 -144
- package/docker.volume.d.ts +26 -0
- package/docker.volume.js +52 -126
- package/dockerCleanup.d.ts +38 -0
- package/dockerCleanup.js +66 -141
- package/dockerCompose.d.ts +154 -0
- package/dockerCompose.js +400 -727
- package/fs.d.ts +5 -0
- package/fs.js +38 -95
- package/git.d.ts +9 -0
- package/git.js +19 -30
- package/index.d.ts +20 -0
- package/index.js +20 -27
- package/maps.d.ts +33 -0
- package/maps.js +16 -87
- package/npm.d.ts +48 -0
- package/npm.js +133 -135
- package/package.json +23 -19
- package/pkg.d.ts +39 -0
- package/pkg.js +26 -74
- package/publish.d.ts +27 -0
- package/publish.js +52 -140
- package/run.d.ts +13 -0
- package/run.js +39 -85
- package/tgz.d.ts +13 -0
- package/tgz.js +61 -96
- package/version.d.ts +34 -0
- package/version.js +86 -127
- package/yarn.d.ts +44 -0
- package/yarn.js +150 -119
- 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.flow +0 -152
- package/clean.js.flow +0 -19
- package/copy.js.flow +0 -79
- package/cp.js.flow +0 -172
- package/docker.container.js.flow +0 -389
- package/docker.js.flow +0 -367
- package/docker.network.js.flow +0 -159
- package/docker.volume.js.flow +0 -136
- package/dockerCleanup.js.flow +0 -151
- package/dockerCompose.js.flow +0 -765
- package/flow.js +0 -21
- package/flow.js.flow +0 -20
- package/fs.js.flow +0 -96
- package/git.js.flow +0 -34
- package/hg.js +0 -35
- package/hg.js.flow +0 -34
- package/index.js.flow +0 -26
- package/inline-resources.js +0 -158
- package/inline-resources.js.flow +0 -157
- package/maps.js.flow +0 -111
- package/npm.js.flow +0 -144
- package/pkg.js.flow +0 -80
- package/publish.js.flow +0 -144
- package/run.js.flow +0 -89
- package/src/ant.js +0 -42
- package/src/artifactory.js +0 -616
- package/src/cert.conf +0 -20
- package/src/cert.js +0 -152
- package/src/clean.js +0 -19
- package/src/copy.js +0 -79
- package/src/cp.js +0 -172
- package/src/docker.container.js +0 -389
- package/src/docker.js +0 -367
- package/src/docker.network.js +0 -159
- package/src/docker.volume.js +0 -136
- package/src/dockerCleanup.js +0 -151
- package/src/dockerCompose.js +0 -765
- package/src/flow.js +0 -20
- package/src/fs.js +0 -96
- package/src/git.js +0 -34
- package/src/hg.js +0 -34
- package/src/index.js +0 -26
- package/src/inline-resources.js +0 -157
- package/src/maps.js +0 -111
- package/src/npm.js +0 -144
- package/src/pkg.js +0 -80
- package/src/publish.js +0 -144
- package/src/run.js +0 -89
- package/src/test.js +0 -55
- package/src/tgz.js +0 -101
- package/src/version.js +0 -141
- package/src/yarn.js +0 -123
- package/test.js +0 -56
- package/test.js.flow +0 -55
- package/tgz.js.flow +0 -101
- package/version.js.flow +0 -141
- package/yarn.js.flow +0 -123
package/src/dockerCleanup.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import uniq from 'lodash/uniq';
|
|
3
|
-
import {
|
|
4
|
-
dockerImages,
|
|
5
|
-
dockerRmi,
|
|
6
|
-
getUntaggedDockerIds,
|
|
7
|
-
getDockerTags,
|
|
8
|
-
getDockerRepo,
|
|
9
|
-
} from './docker';
|
|
10
|
-
import type { DockerImage, DockerImageFilter } from './docker';
|
|
11
|
-
import { dockerContainerLs } from './docker.container';
|
|
12
|
-
import { buildLog } from './run';
|
|
13
|
-
|
|
14
|
-
// flattens arrays of promises and/or promises for arrays
|
|
15
|
-
// into a single array of (awaited) values
|
|
16
|
-
const flatten = async (input) => {
|
|
17
|
-
const result = await input;
|
|
18
|
-
return Array.isArray(result)
|
|
19
|
-
? [].concat(...(await Promise.all(result.map(flatten))))
|
|
20
|
-
: result;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type CommonDockerCleanupOptions = {|
|
|
24
|
-
/** print matched items to console instead of deleting */
|
|
25
|
-
dryRun?: boolean,
|
|
26
|
-
|};
|
|
27
|
-
|
|
28
|
-
type DockerContainerCleanupOptions = {|
|
|
29
|
-
...CommonDockerCleanupOptions,
|
|
30
|
-
|};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Purge stopped containers
|
|
34
|
-
*/
|
|
35
|
-
export const dockerContainerCleanup = async ({
|
|
36
|
-
dryRun = process.argv.includes('--dry-run'),
|
|
37
|
-
}: DockerContainerCleanupOptions = {}) => {
|
|
38
|
-
const toClean = await dockerContainerLs({
|
|
39
|
-
all: true,
|
|
40
|
-
filter: (c) => c.exited,
|
|
41
|
-
});
|
|
42
|
-
if (dryRun) {
|
|
43
|
-
buildLog(
|
|
44
|
-
`Containers to delete (dry run):\n ${toClean
|
|
45
|
-
.map((c) => c.id)
|
|
46
|
-
.join('\n ')}`,
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
await Promise.all(toClean.map(async (c) => c.rm(true)));
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type DockerImageCleanupOptions = {|
|
|
54
|
-
...CommonDockerCleanupOptions,
|
|
55
|
-
/** Image repositories to clean (defaults to the one configured in package.json) */
|
|
56
|
-
repos?: string[],
|
|
57
|
-
/** Image ids known to be produced by this build */
|
|
58
|
-
buildImageIds?: string[],
|
|
59
|
-
/** Explicit image names/ids to delete unconditionally */
|
|
60
|
-
images?: string[],
|
|
61
|
-
/**
|
|
62
|
-
* ignore default exclusions of :latest* and images < 1hr old
|
|
63
|
-
* this will delete all images in the given repos
|
|
64
|
-
*/
|
|
65
|
-
purgeAll?: boolean,
|
|
66
|
-
/**
|
|
67
|
-
* looks for other builds of the same repos
|
|
68
|
-
* this will still exclude :latest* and images < 1hr old
|
|
69
|
-
* useful to clean up after past builds that failed to clean themselves properly
|
|
70
|
-
*/
|
|
71
|
-
purgeOld?: boolean,
|
|
72
|
-
|};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Purge docker images created during build process
|
|
76
|
-
*/
|
|
77
|
-
export const dockerImageCleanup = async ({
|
|
78
|
-
repos = [getDockerRepo()],
|
|
79
|
-
buildImageIds = [],
|
|
80
|
-
images = [],
|
|
81
|
-
purgeAll = process.argv.includes('--purge-all'),
|
|
82
|
-
purgeOld = !process.argv.includes('--keep-old'),
|
|
83
|
-
dryRun = process.argv.includes('--dry-run'),
|
|
84
|
-
}: DockerImageCleanupOptions = {}) => {
|
|
85
|
-
// only match images without a :latest tag
|
|
86
|
-
const filterLatest: DockerImageFilter = (m: DockerImage) =>
|
|
87
|
-
purgeAll || !m.tag.match(/^latest(-\w+)?$/);
|
|
88
|
-
// only match images more than an hour old, AND without a :latest* tag
|
|
89
|
-
const filterOld: DockerImageFilter = (m: DockerImage) =>
|
|
90
|
-
purgeAll || (filterLatest(m) && m.created < Date.now() - 1000 * 60 * 60);
|
|
91
|
-
|
|
92
|
-
const uniqueList = uniq([
|
|
93
|
-
// the things that we know were just built by us
|
|
94
|
-
// remove all tags from the given repos with a matching `buildImageIds`, except for :latest*
|
|
95
|
-
...(await flatten(
|
|
96
|
-
repos.map((r) =>
|
|
97
|
-
buildImageIds.map(async (b) => getDockerTags(b, r, true, filterLatest)),
|
|
98
|
-
),
|
|
99
|
-
)),
|
|
100
|
-
|
|
101
|
-
// unconditionally delete explicitly passed images/ids
|
|
102
|
-
...images,
|
|
103
|
-
|
|
104
|
-
// images in the given `repos` without a tag, older than 1hr
|
|
105
|
-
...(await flatten(
|
|
106
|
-
repos.map(async (r) => getUntaggedDockerIds(r, filterOld)),
|
|
107
|
-
)),
|
|
108
|
-
|
|
109
|
-
// images with no repo and no tag
|
|
110
|
-
...(
|
|
111
|
-
await dockerImages(
|
|
112
|
-
null,
|
|
113
|
-
(m) => m.repository === '<none>' && m.tag === '<none>' && filterOld(m),
|
|
114
|
-
)
|
|
115
|
-
).map((m) => m.id),
|
|
116
|
-
|
|
117
|
-
// any leftover tags from prior builds (only if purgeAll or purgeOld)
|
|
118
|
-
...(purgeAll || purgeOld
|
|
119
|
-
? await flatten(
|
|
120
|
-
repos.map(async (r) => getDockerTags(null, r, true, filterOld)),
|
|
121
|
-
)
|
|
122
|
-
: []),
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
if (dryRun) {
|
|
126
|
-
buildLog(`Images to delete (dry run):\n ${uniqueList.join('\n ')}`);
|
|
127
|
-
} else {
|
|
128
|
-
await dockerRmi(uniqueList, true);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
type DockerCleanupOptions = {|
|
|
133
|
-
...DockerImageCleanupOptions,
|
|
134
|
-
...DockerContainerCleanupOptions,
|
|
135
|
-
|};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Purge docker images created during build process
|
|
139
|
-
*/
|
|
140
|
-
export const dockerCleanup = async ({
|
|
141
|
-
dryRun,
|
|
142
|
-
...rest
|
|
143
|
-
}: DockerCleanupOptions = {}) => {
|
|
144
|
-
await dockerContainerCleanup({ dryRun });
|
|
145
|
-
await dockerImageCleanup({
|
|
146
|
-
dryRun,
|
|
147
|
-
...rest,
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export default dockerCleanup;
|