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/dockerCleanup.js
CHANGED
|
@@ -1,151 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
1
|
+
import { uniq } from 'lodash-es';
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
import { dockerContainerLs } from './docker.container.js';
|
|
4
|
+
import { dockerImages, dockerRmi, getDockerRepo, getDockerTags, getUntaggedDockerIds, } from './docker.js';
|
|
5
|
+
import { buildLog } from './run.js';
|
|
14
6
|
// flattens arrays of promises and/or promises for arrays
|
|
15
7
|
// into a single array of (awaited) values
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
8
|
+
async function flatten(input) {
|
|
9
|
+
const result = await input;
|
|
10
|
+
return Array.isArray(result)
|
|
11
|
+
? [].concat(...(await Promise.all(result.map(flatten))))
|
|
12
|
+
: result;
|
|
13
|
+
}
|
|
32
14
|
/**
|
|
33
15
|
* Purge stopped containers
|
|
34
16
|
*/
|
|
35
|
-
export const dockerContainerCleanup = async ({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
17
|
+
export const dockerContainerCleanup = async ({ dryRun = process.argv.includes('--dry-run'), } = {}) => {
|
|
18
|
+
const toClean = await dockerContainerLs({
|
|
19
|
+
all: true,
|
|
20
|
+
filter: (c) => c.exited,
|
|
21
|
+
});
|
|
22
|
+
if (dryRun) {
|
|
23
|
+
if (toClean) {
|
|
24
|
+
buildLog(`Containers to delete (dry run):\n ${toClean
|
|
25
|
+
.map((c) => c.id)
|
|
26
|
+
.join('\n ')}`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
buildLog('No containers to delete (dry run)');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (toClean) {
|
|
33
|
+
await Promise.all(toClean.map(async (c) => c.rm(true)));
|
|
34
|
+
}
|
|
51
35
|
};
|
|
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
36
|
/**
|
|
75
37
|
* Purge docker images created during build process
|
|
76
38
|
*/
|
|
77
|
-
export const dockerImageCleanup = async ({
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
}
|
|
39
|
+
export const dockerImageCleanup = async ({ repos = [getDockerRepo()], buildImageIds = [], images = [], purgeAll = process.argv.includes('--purge-all'), purgeOld = !process.argv.includes('--keep-old'), dryRun = process.argv.includes('--dry-run'), } = {}) => {
|
|
40
|
+
// only match images without a :latest tag
|
|
41
|
+
const filterLatest = (m) => purgeAll || !m.tag.match(/^latest(-\w+)?$/);
|
|
42
|
+
// only match images more than an hour old, AND without a :latest* tag
|
|
43
|
+
const filterOld = (m) => purgeAll ||
|
|
44
|
+
(filterLatest(m) && moment().subtract(1, 'h').isAfter(m.created));
|
|
45
|
+
const uniqueList = uniq([
|
|
46
|
+
// the things that we know were just built by us
|
|
47
|
+
// remove all tags from the given repos with a matching `buildImageIds`, except for :latest*
|
|
48
|
+
...(await flatten(repos.map((r) => buildImageIds.map(async (b) => getDockerTags(b, r, true, filterLatest))))),
|
|
49
|
+
// unconditionally delete explicitly passed images/ids
|
|
50
|
+
...images,
|
|
51
|
+
// images in the given `repos` without a tag, older than 1hr
|
|
52
|
+
...(await flatten(repos.map(async (r) => getUntaggedDockerIds(r, filterOld)))),
|
|
53
|
+
// images with no repo and no tag
|
|
54
|
+
...(await dockerImages(null, (m) => m.repository === '<none>' && m.tag === '<none>' && filterOld(m))).map((m) => m.id),
|
|
55
|
+
// any leftover tags from prior builds (only if purgeAll or purgeOld)
|
|
56
|
+
...(purgeAll || purgeOld
|
|
57
|
+
? await flatten(repos.map(async (r) => getDockerTags(null, r, true, filterOld)))
|
|
58
|
+
: []),
|
|
59
|
+
]);
|
|
60
|
+
if (dryRun) {
|
|
61
|
+
buildLog(`Images to delete (dry run):\n ${uniqueList.join('\n ')}`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
await dockerRmi(uniqueList, true);
|
|
65
|
+
}
|
|
130
66
|
};
|
|
131
|
-
|
|
132
|
-
type DockerCleanupOptions = {|
|
|
133
|
-
...DockerImageCleanupOptions,
|
|
134
|
-
...DockerContainerCleanupOptions,
|
|
135
|
-
|};
|
|
136
|
-
|
|
137
67
|
/**
|
|
138
68
|
* Purge docker images created during build process
|
|
139
69
|
*/
|
|
140
|
-
export const dockerCleanup = async ({
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
dryRun,
|
|
147
|
-
...rest,
|
|
148
|
-
});
|
|
70
|
+
export const dockerCleanup = async ({ dryRun, ...rest } = {}) => {
|
|
71
|
+
await dockerContainerCleanup({ dryRun });
|
|
72
|
+
await dockerImageCleanup({
|
|
73
|
+
dryRun,
|
|
74
|
+
...rest,
|
|
75
|
+
});
|
|
149
76
|
};
|
|
150
|
-
|
|
151
77
|
export default dockerCleanup;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { DockerContainer } from './docker.container.js';
|
|
2
|
+
import { DockerNetwork, DockerNetworkCreateOptions } from './docker.network.js';
|
|
3
|
+
import { DockerVolume, DockerVolumeCreateOptions } from './docker.volume.js';
|
|
4
|
+
export declare type DockerComposeResourceTracker = {
|
|
5
|
+
cleaning: null | Promise<void>;
|
|
6
|
+
containers: Map<string, DockerContainer>;
|
|
7
|
+
networks: Map<string, DockerNetwork>;
|
|
8
|
+
services: Map<string, DockerComposeService>;
|
|
9
|
+
volumes: Map<string, DockerVolume>;
|
|
10
|
+
};
|
|
11
|
+
export declare const dockerComposeCreateResourceTracker: () => DockerComposeResourceTracker;
|
|
12
|
+
declare type DockerComposeEnvDef = string[] | Record<string, string>;
|
|
13
|
+
declare type DockerComposeULimitDef = number | {
|
|
14
|
+
hard: number;
|
|
15
|
+
soft: number;
|
|
16
|
+
};
|
|
17
|
+
declare type DockerComposeULimitsDef = Record<string, DockerComposeULimitDef>;
|
|
18
|
+
interface DockerComposeServiceDef {
|
|
19
|
+
command?: string[];
|
|
20
|
+
container_name?: string;
|
|
21
|
+
environment?: DockerComposeEnvDef;
|
|
22
|
+
image?: string;
|
|
23
|
+
links?: string[];
|
|
24
|
+
networks?: string[];
|
|
25
|
+
ports?: string[];
|
|
26
|
+
ulimits?: DockerComposeULimitsDef;
|
|
27
|
+
volumes?: string[];
|
|
28
|
+
}
|
|
29
|
+
interface DockerComposeVolumeDef extends DockerVolumeCreateOptions {
|
|
30
|
+
name?: string;
|
|
31
|
+
}
|
|
32
|
+
interface DockerComposeNetworkDef extends DockerNetworkCreateOptions {
|
|
33
|
+
name?: string;
|
|
34
|
+
}
|
|
35
|
+
interface DockerCompose {
|
|
36
|
+
networks?: Record<string, DockerComposeNetworkDef>;
|
|
37
|
+
services?: Record<string, DockerComposeServiceDef>;
|
|
38
|
+
version: string;
|
|
39
|
+
volumes?: Record<string, DockerComposeVolumeDef>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a docker-compose.yml file into a pojo representation
|
|
43
|
+
* @param {string} filePath Path to the docker-compose.yml file
|
|
44
|
+
*/
|
|
45
|
+
export declare const dockerComposeParse: (filePath?: string) => Promise<DockerCompose>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the main docker-compose.yml from the root of the repo
|
|
48
|
+
* @param {boolean} force Force reload from file
|
|
49
|
+
*/
|
|
50
|
+
export declare const dockerComposeGetMain: (force?: boolean) => Promise<DockerCompose>;
|
|
51
|
+
interface PortMap {
|
|
52
|
+
docker: number;
|
|
53
|
+
local: null | number;
|
|
54
|
+
localDefault: number;
|
|
55
|
+
}
|
|
56
|
+
interface UrlMap {
|
|
57
|
+
docker: null | string;
|
|
58
|
+
local: null | string;
|
|
59
|
+
}
|
|
60
|
+
interface ParsedPortInfo {
|
|
61
|
+
ports: PortMap[];
|
|
62
|
+
runArgs: string[];
|
|
63
|
+
}
|
|
64
|
+
interface ParsedVolumeInfo {
|
|
65
|
+
runArgs: string[];
|
|
66
|
+
volumes: string[];
|
|
67
|
+
}
|
|
68
|
+
interface ParsedNetworkInfo {
|
|
69
|
+
networks: string[];
|
|
70
|
+
runArgs: string[];
|
|
71
|
+
}
|
|
72
|
+
export declare const dockerComposeCreateNetworks: (names?: string[] | null | undefined, dockerCompose?: string | DockerCompose | null | undefined, tracker?: DockerComposeResourceTracker) => Promise<void>;
|
|
73
|
+
export declare const dockerComposeCreateVolumes: (names?: string[] | undefined, dockerCompose?: string | DockerCompose | null | undefined, tracker?: DockerComposeResourceTracker) => Promise<void>;
|
|
74
|
+
declare type HealthCheckFn = (result: UpResult) => Promise<void>;
|
|
75
|
+
interface UpOptions {
|
|
76
|
+
avoidConflicts?: boolean;
|
|
77
|
+
cmd?: string[];
|
|
78
|
+
healthCheck?: HealthCheckFn;
|
|
79
|
+
mapPorts?: boolean;
|
|
80
|
+
mapVolumes?: boolean;
|
|
81
|
+
tracker?: DockerComposeResourceTracker;
|
|
82
|
+
}
|
|
83
|
+
interface ServiceNameInfo {
|
|
84
|
+
aliases: string[];
|
|
85
|
+
name: string;
|
|
86
|
+
suffix: string;
|
|
87
|
+
}
|
|
88
|
+
interface UpResult {
|
|
89
|
+
aliases: string[];
|
|
90
|
+
container: DockerContainer;
|
|
91
|
+
containerName: string;
|
|
92
|
+
ports: PortMap[];
|
|
93
|
+
service: DockerComposeService;
|
|
94
|
+
urls: UrlMap[];
|
|
95
|
+
volumes: string[];
|
|
96
|
+
}
|
|
97
|
+
export declare class DockerComposeService {
|
|
98
|
+
#private;
|
|
99
|
+
constructor(name: string, serviceDef: DockerComposeServiceDef, dockerCompose?: null | (DockerCompose | string));
|
|
100
|
+
get name(): string;
|
|
101
|
+
get serviceDef(): DockerComposeServiceDef;
|
|
102
|
+
get image(): null | string;
|
|
103
|
+
get defaultContainerName(): string;
|
|
104
|
+
get cmd(): string[];
|
|
105
|
+
get envArgs(): string[];
|
|
106
|
+
/**
|
|
107
|
+
* Find (available) container name and alias(es)
|
|
108
|
+
* @param {boolean} avoidConflicts if `true`, find a container name that is unused
|
|
109
|
+
* @param {number} max maximum number of names to try
|
|
110
|
+
*/
|
|
111
|
+
getNames(avoidConflicts?: boolean, max?: number): Promise<ServiceNameInfo>;
|
|
112
|
+
getPorts(avoidConflicts?: boolean, mapLocal?: boolean): Promise<ParsedPortInfo>;
|
|
113
|
+
getDefaultPortInfo(): Promise<ParsedPortInfo>;
|
|
114
|
+
getDefaultPorts(): Promise<PortMap[]>;
|
|
115
|
+
getDefaultPortArgs(): Promise<string[]>;
|
|
116
|
+
getDefaultUrls(): Promise<UrlMap[]>;
|
|
117
|
+
getDefaultNetworkInfo(): Promise<ParsedNetworkInfo>;
|
|
118
|
+
getDefaultNetworks(): Promise<string[]>;
|
|
119
|
+
getDefaultNetworkArgs(): Promise<string[]>;
|
|
120
|
+
getDefaultVolumeInfo(): Promise<ParsedVolumeInfo>;
|
|
121
|
+
getDefaultVolumes(): Promise<string[]>;
|
|
122
|
+
getDefaultVolumeArgs(): Promise<string[]>;
|
|
123
|
+
pull(): Promise<void>;
|
|
124
|
+
getBaseRunArgs(): Promise<string[]>;
|
|
125
|
+
assembleRunArgs(containerName?: string, aliases?: string[], additionalArgs?: null | string[]): Promise<string[]>;
|
|
126
|
+
getRunArgs(avoidConflicts?: boolean, mapLocalPorts?: boolean): Promise<string[]>;
|
|
127
|
+
up({ healthCheck, avoidConflicts, mapVolumes, mapPorts, cmd, tracker, }?: UpOptions): Promise<UpResult>;
|
|
128
|
+
down({ includeDefaults, includeNetworks, includeVolumes, }?: {
|
|
129
|
+
includeDefaults?: boolean;
|
|
130
|
+
includeNetworks?: boolean;
|
|
131
|
+
includeVolumes?: boolean;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
static parse(name: string, force?: boolean, dockerCompose?: null | (DockerCompose | string)): Promise<null | DockerComposeService>;
|
|
134
|
+
static getUrls(ports: PortMap[], alias: string): UrlMap[];
|
|
135
|
+
}
|
|
136
|
+
export declare function dockerComposeGetAllServices(dockerCompose?: null | (string | DockerCompose)): Promise<Record<string, null | DockerComposeService>>;
|
|
137
|
+
export declare function dockerComposeTeardown({ includeDefaults, includeVolumes, includeNetworks, dockerCompose, tracker, }?: {
|
|
138
|
+
dockerCompose?: null | (string | DockerCompose);
|
|
139
|
+
includeDefaults?: boolean;
|
|
140
|
+
includeNetworks?: boolean;
|
|
141
|
+
includeVolumes?: boolean;
|
|
142
|
+
tracker?: DockerComposeResourceTracker;
|
|
143
|
+
}): Promise<void>;
|
|
144
|
+
export interface DockerContainerInfo extends UpResult {
|
|
145
|
+
dockerPort?: null | number;
|
|
146
|
+
dockerUrl?: null | string;
|
|
147
|
+
id: string;
|
|
148
|
+
image: string;
|
|
149
|
+
name?: null | string;
|
|
150
|
+
port?: null | number;
|
|
151
|
+
url?: null | string;
|
|
152
|
+
}
|
|
153
|
+
export declare function dockerComposeRunService(key: string, upOptions?: UpOptions, dockerCompose?: null | string | DockerCompose): Promise<DockerContainerInfo>;
|
|
154
|
+
export {};
|