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.
Files changed (107) hide show
  1. package/README.md +3 -34
  2. package/package.json +23 -19
  3. package/src/ant.d.ts +19 -0
  4. package/src/ant.js +12 -36
  5. package/src/cert.d.ts +12 -0
  6. package/src/cert.js +87 -148
  7. package/src/clean.d.ts +4 -0
  8. package/src/clean.js +5 -13
  9. package/src/copy.d.ts +7 -0
  10. package/src/copy.js +48 -74
  11. package/src/cp.d.ts +17 -0
  12. package/src/cp.js +81 -165
  13. package/src/docker.container.d.ts +73 -0
  14. package/src/docker.container.js +208 -350
  15. package/src/docker.d.ts +68 -0
  16. package/src/docker.js +163 -339
  17. package/src/docker.network.d.ts +42 -0
  18. package/src/docker.network.js +67 -141
  19. package/src/docker.volume.d.ts +26 -0
  20. package/src/docker.volume.js +50 -124
  21. package/src/dockerCleanup.d.ts +38 -0
  22. package/src/dockerCleanup.js +62 -136
  23. package/src/dockerCompose.d.ts +154 -0
  24. package/src/dockerCompose.js +390 -716
  25. package/src/fs.d.ts +5 -0
  26. package/src/fs.js +33 -91
  27. package/src/git.d.ts +9 -0
  28. package/src/git.js +19 -29
  29. package/src/index.d.ts +20 -0
  30. package/src/index.js +20 -26
  31. package/src/maps.d.ts +33 -0
  32. package/src/maps.js +12 -82
  33. package/src/npm.d.ts +48 -0
  34. package/src/npm.js +128 -131
  35. package/src/pkg.d.ts +38 -0
  36. package/src/pkg.js +27 -74
  37. package/src/publish.d.ts +27 -0
  38. package/src/publish.js +51 -138
  39. package/src/run.d.ts +13 -0
  40. package/src/run.js +39 -84
  41. package/src/tgz.d.ts +13 -0
  42. package/src/tgz.js +54 -88
  43. package/src/version.d.ts +34 -0
  44. package/src/version.js +85 -126
  45. package/src/yarn.d.ts +44 -0
  46. package/src/yarn.js +147 -115
  47. package/ant.js +0 -43
  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 +0 -153
  53. package/cert.js.flow +0 -152
  54. package/clean.js +0 -20
  55. package/clean.js.flow +0 -19
  56. package/copy.js +0 -80
  57. package/copy.js.flow +0 -79
  58. package/cp.js +0 -173
  59. package/cp.js.flow +0 -172
  60. package/docker.container.js +0 -390
  61. package/docker.container.js.flow +0 -389
  62. package/docker.js +0 -365
  63. package/docker.js.flow +0 -364
  64. package/docker.network.js +0 -160
  65. package/docker.network.js.flow +0 -159
  66. package/docker.volume.js +0 -136
  67. package/docker.volume.js.flow +0 -136
  68. package/dockerCleanup.js +0 -152
  69. package/dockerCleanup.js.flow +0 -151
  70. package/dockerCompose.js +0 -766
  71. package/dockerCompose.js.flow +0 -765
  72. package/flow.js +0 -21
  73. package/flow.js.flow +0 -20
  74. package/fs.js +0 -95
  75. package/fs.js.flow +0 -96
  76. package/git.js +0 -35
  77. package/git.js.flow +0 -34
  78. package/hg.js +0 -35
  79. package/hg.js.flow +0 -34
  80. package/index.js +0 -27
  81. package/index.js.flow +0 -26
  82. package/inline-resources.js +0 -158
  83. package/inline-resources.js.flow +0 -157
  84. package/maps.js +0 -112
  85. package/maps.js.flow +0 -111
  86. package/npm.js +0 -145
  87. package/npm.js.flow +0 -144
  88. package/pkg.js +0 -81
  89. package/pkg.js.flow +0 -80
  90. package/publish.js +0 -145
  91. package/publish.js.flow +0 -144
  92. package/run.js +0 -90
  93. package/run.js.flow +0 -89
  94. package/src/artifactory.js +0 -616
  95. package/src/cert.conf +0 -20
  96. package/src/flow.js +0 -20
  97. package/src/hg.js +0 -34
  98. package/src/inline-resources.js +0 -157
  99. package/src/test.js +0 -55
  100. package/test.js +0 -56
  101. package/test.js.flow +0 -55
  102. package/tgz.js +0 -102
  103. package/tgz.js.flow +0 -101
  104. package/version.js +0 -143
  105. package/version.js.flow +0 -142
  106. package/yarn.js +0 -124
  107. package/yarn.js.flow +0 -123
@@ -1,151 +1,77 @@
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
-
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
- 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
-
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
- 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
- }
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
- 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
- }
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
- dryRun,
142
- ...rest
143
- }: DockerCleanupOptions = {}) => {
144
- await dockerContainerCleanup({ dryRun });
145
- await dockerImageCleanup({
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 {};