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,159 +1,85 @@
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
-
1
+ import { throttle } from 'lodash-es';
2
+ import { spawn } from './cp.js';
3
+ import { parseDockerDate } from './docker.js';
22
4
  // calling this function in rapid succession can lead to errors.
23
5
  // 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,
6
+ export async function unthrottledDockerNetworkLs({ filter, } = {}) {
7
+ return (await spawn('docker', ['network', 'ls', '--format', '{{json .}}'], {
8
+ captureOutput: true,
9
+ })).output
10
+ .split('\n')
11
+ .filter((line) => !!line.trim())
12
+ .map((line) => {
13
+ const { CreatedAt, Driver: driver, ID: id, IPv6, Labels, Name: name, Scope: scope, } = JSON.parse(line.trim());
14
+ return {
15
+ IPv6: IPv6 === 'true',
16
+ created: parseDockerDate(CreatedAt),
17
+ driver,
18
+ exists: async () => !!(await dockerNetworkFind(id)),
19
+ id,
20
+ labels: Labels.split(',').map((l) => l.trim()),
21
+ name,
22
+ rm: async () => dockerNetworkRm(id),
23
+ scope,
24
+ };
30
25
  })
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));
26
+ .filter((n) => n.id && (typeof filter === 'function' ? filter(n) : true));
57
27
  }
58
- export const dockerNetworkLs: (
59
- DockerNetworkLsOptions | void,
60
- ) => Promise<DockerNetwork[]> = throttle(_dockerNetworkLs, 500, {
61
- trailing: false,
28
+ export const dockerNetworkLs = throttle(unthrottledDockerNetworkLs, 500, {
29
+ trailing: false,
62
30
  });
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
- );
31
+ export async function dockerNetworkFind(networkName, options) {
32
+ return ((await dockerNetworkLs(options))?.find((n) => n.name === networkName || n.id === networkName) || null);
71
33
  }
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);
34
+ export async function dockerNetworkCreate(networkName, { driver, driverOpts = {}, ipRange, gateways = [], subnets = [], auxAddresses = [], ingress, internal, ipv6, labels = [], } = {}) {
35
+ const existing = await dockerNetworkFind(networkName);
36
+ if (existing)
37
+ return existing;
38
+ await spawn('docker', [
39
+ 'network',
40
+ 'create',
41
+ ...labels.flatMap((l) => ['--label', l]),
42
+ ...gateways.flatMap((g) => ['--gateway', g]),
43
+ ...subnets.flatMap((s) => ['--subnet', s]),
44
+ ...auxAddresses.flatMap((a) => ['--aux-address', a]),
45
+ ...(ipRange ? ['--ip-range', ipRange] : []),
46
+ ...(ingress ? ['--ingress'] : []),
47
+ ...(internal ? ['--internal'] : []),
48
+ ...(ipv6 ? ['--ipv6'] : []),
49
+ ...(driver ? ['-d', driver] : []),
50
+ ...Object.entries(driverOpts).flatMap(([k, v]) => ['-o', `${k}=${v}`]),
51
+ networkName,
52
+ ]);
53
+ return dockerNetworkFind(networkName);
122
54
  }
123
-
124
55
  /**
125
56
  * Removes a network by id
126
57
  * @param {string} id The id of the network
127
58
  */
128
- export async function dockerNetworkRm(id: string) {
129
- await spawn('docker', ['network', 'rm', id]);
59
+ export async function dockerNetworkRm(id) {
60
+ await spawn('docker', ['network', 'rm', id]);
130
61
  }
131
-
132
62
  /**
133
63
  * Removes all networks with the given name
134
64
  * @param {string} networkName The name of the network
135
65
  */
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
- }
66
+ export async function dockerNetworkDelete(networkName) {
67
+ let existing;
68
+ // eslint-disable-next-line no-cond-assign, no-await-in-loop
69
+ while ((existing = await dockerNetworkFind(networkName))) {
70
+ // eslint-disable-next-line no-await-in-loop
71
+ await existing.rm();
72
+ }
143
73
  }
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
- ]);
74
+ export async function dockerNetworkConnect(networkName, containerId, alias) {
75
+ const net = await dockerNetworkCreate(networkName);
76
+ if (!net)
77
+ throw new Error('Failed to create docker network');
78
+ await spawn('docker', [
79
+ 'network',
80
+ 'connect',
81
+ ...(alias ? ['--alias', alias] : []),
82
+ net.id,
83
+ containerId,
84
+ ]);
159
85
  }
@@ -0,0 +1,26 @@
1
+ declare type DockerVolumeInspectOutput = Record<string, any>;
2
+ export interface DockerVolume {
3
+ driver: string;
4
+ inspect: () => Promise<null | DockerVolumeInspectOutput>;
5
+ labels: string[];
6
+ mountPoint: string;
7
+ name: string;
8
+ rm: () => Promise<void>;
9
+ scope: string;
10
+ }
11
+ interface DockerVolumeLsOptions {
12
+ filter?: (vol: DockerVolume) => boolean;
13
+ }
14
+ export declare function unthrottledDockerVolumeLs({ filter, }?: DockerVolumeLsOptions): Promise<DockerVolume[]>;
15
+ export declare const dockerVolumeLs: (options?: DockerVolumeLsOptions) => undefined | Promise<DockerVolume[]>;
16
+ export declare function dockerVolumeFind(search: string, options?: DockerVolumeLsOptions): Promise<null | DockerVolume>;
17
+ export interface DockerVolumeCreateOptions {
18
+ driver?: string;
19
+ driverOpts?: Record<string, string>;
20
+ labels?: string[];
21
+ }
22
+ export declare function dockerVolumeCreate(name: string, { labels, driver, driverOpts }?: DockerVolumeCreateOptions): Promise<null | DockerVolume>;
23
+ export declare function dockerVolumeRm(id: string | string[], ignoreErrors?: boolean): Promise<void>;
24
+ export declare function unthrottledDockerVolumeInspect(id: string | string[]): Promise<DockerVolumeInspectOutput[]>;
25
+ export declare const dockerVolumeInspect: (id: string | string[]) => undefined | Promise<DockerVolumeInspectOutput[]>;
26
+ export {};
@@ -1,136 +1,62 @@
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
-
1
+ import { throttle } from 'lodash-es';
2
+ import { spawn } from './cp.js';
23
3
  // calling this function in rapid succession can lead to errors.
24
4
  // 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,
5
+ export async function unthrottledDockerVolumeLs({ filter, } = {}) {
6
+ return (await spawn('docker', ['volume', 'ls', '--format', '{{json .}}'], {
7
+ captureOutput: true,
8
+ })).output
9
+ .split('\n')
10
+ .filter((line) => !!line.trim())
11
+ .map((line) => {
12
+ const { Driver: driver, Labels, Mountpoint: mountPoint, Name: name, Scope: scope, } = JSON.parse(line.trim());
13
+ return {
14
+ driver,
15
+ inspect: async () => (await dockerVolumeInspect(name))?.[0] || null,
16
+ labels: Labels.split(',').map((l) => l.trim()),
17
+ mountPoint,
18
+ name,
19
+ rm: async () => dockerVolumeRm(name),
20
+ scope,
21
+ };
31
22
  })
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));
23
+ .filter((v) => v.name && (typeof filter === 'function' ? filter(v) : true));
55
24
  }
56
-
57
- export const dockerVolumeLs: (
58
- DockerVolumeLsOptions | void,
59
- ) => Promise<DockerVolume[]> = throttle(_dockerVolumeLs, 500, {
60
- trailing: false,
25
+ export const dockerVolumeLs = throttle(unthrottledDockerVolumeLs, 500, {
26
+ trailing: false,
61
27
  });
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
- );
28
+ export async function dockerVolumeFind(search, options) {
29
+ return ((await dockerVolumeLs(options))?.find((v) => v.name === search || v.name.startsWith(search)) ?? null);
70
30
  }
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);
31
+ export async function dockerVolumeCreate(name, { labels = [], driver, driverOpts = {} } = {}) {
32
+ const existing = await dockerVolumeFind(name);
33
+ if (existing)
34
+ return existing;
35
+ await spawn('docker', [
36
+ 'volume',
37
+ 'create',
38
+ ...labels.flatMap((l) => ['--label', l]),
39
+ ...(driver ? ['-d', driver] : []),
40
+ ...Object.entries(driverOpts).flatMap(([k, v]) => ['-o', `${k}=${v}`]),
41
+ name,
42
+ ]);
43
+ return dockerVolumeFind(name);
95
44
  }
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}`);
45
+ export async function dockerVolumeRm(id, ignoreErrors = true) {
46
+ const ids = Array.isArray(id) ? id : [id];
47
+ try {
48
+ await spawn('docker', ['volume', 'rm', ...ids]);
49
+ }
50
+ catch (e) {
51
+ if (!ignoreErrors) {
52
+ throw new Error(`Failed to remove volume(s): ${e.message}`);
53
+ }
107
54
  }
108
- }
109
55
  }
110
-
111
56
  // calling this function in rapid succession can lead to errors.
112
57
  // 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
- );
58
+ export async function unthrottledDockerVolumeInspect(id) {
59
+ const ids = Array.isArray(id) ? id : [id];
60
+ return (JSON.parse((await spawn('docker', ['volume', 'inspect', '--format', '{{json .}}', ...ids], { captureOutput: true })).output.trim()) || []);
128
61
  }
129
-
130
- export const dockerVolumeInspect: (
131
- string | string[],
132
- ) => Promise<DockerVolumeInspectOutput[]> = throttle(
133
- _dockerVolumeInspect,
134
- 500,
135
- { trailing: true },
136
- );
62
+ export const dockerVolumeInspect = throttle(unthrottledDockerVolumeInspect, 500, { trailing: true });
@@ -0,0 +1,38 @@
1
+ interface CommonDockerCleanupOptions {
2
+ /** print matched items to console instead of deleting */
3
+ dryRun?: boolean;
4
+ }
5
+ /**
6
+ * Purge stopped containers
7
+ */
8
+ export declare const dockerContainerCleanup: ({ dryRun, }?: CommonDockerCleanupOptions) => Promise<void>;
9
+ interface DockerImageCleanupOptions extends CommonDockerCleanupOptions {
10
+ /** Image ids known to be produced by this build */
11
+ buildImageIds?: string[];
12
+ /** Explicit image names/ids to delete unconditionally */
13
+ images?: string[];
14
+ /**
15
+ * ignore default exclusions of :latest* and images < 1hr old
16
+ * this will delete all images in the given repos
17
+ */
18
+ purgeAll?: boolean;
19
+ /**
20
+ * looks for other builds of the same repos
21
+ * this will still exclude :latest* and images < 1hr old
22
+ * useful to clean up after past builds that failed to clean themselves properly
23
+ */
24
+ purgeOld?: boolean;
25
+ /** Image repositories to clean (defaults to the one configured in package.json) */
26
+ repos?: string[];
27
+ }
28
+ /**
29
+ * Purge docker images created during build process
30
+ */
31
+ export declare const dockerImageCleanup: ({ repos, buildImageIds, images, purgeAll, purgeOld, dryRun, }?: DockerImageCleanupOptions) => Promise<void>;
32
+ interface DockerCleanupOptions extends DockerImageCleanupOptions, CommonDockerCleanupOptions {
33
+ }
34
+ /**
35
+ * Purge docker images created during build process
36
+ */
37
+ export declare const dockerCleanup: ({ dryRun, ...rest }?: DockerCleanupOptions) => Promise<void>;
38
+ export default dockerCleanup;