@leverege/build-tools 2.38.2 → 2.39.0-beta.2

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 (45) hide show
  1. package/package.json +12 -16
  2. package/src/Utils.mjs +30 -0
  3. package/src/{build-tools.js → build-tools.mjs} +28 -12
  4. package/src/circle-lib.yml +150 -0
  5. package/src/circle-srv.yml +213 -0
  6. package/src/firebaseDeploy.mjs +2 -1
  7. package/src/firebaseServe.mjs +2 -1
  8. package/src/getjson.mjs +3 -3
  9. package/src/helm-charts/firebase-rules/.nohelm +0 -0
  10. package/src/helm-charts/firebase-rules/firebase.json +5 -0
  11. package/src/helm-charts/firebase-rules/firebaserc.ovh +24 -0
  12. package/src/helm-charts/firebase-rules/gitignore +2 -0
  13. package/src/helm-charts/firebase-rules/helmup.plugin +14 -0
  14. package/src/helm-charts/firebase-rules/leverege.rules.json +65 -0
  15. package/src/helm-charts/geotile-server/.nohelm +0 -0
  16. package/src/helm-charts/geotile-server/gitignore +1 -0
  17. package/src/helm-charts/geotile-server/helmup.plugin +6 -0
  18. package/src/helm-charts/velero/helmup.plugin +16 -0
  19. package/src/helmup.sh +47 -1
  20. package/src/overwhelm.mjs +55 -63
  21. package/src/push-my-chart.mjs +7 -6
  22. package/src/refresh-npm-token.mjs +142 -40
  23. package/src/unleash.mjs +4 -2
  24. package/leverege-build-tools-2.21.13.tgz +0 -0
  25. package/lib/server/build-tools.js +0 -138
  26. package/lib/server/firebaseDeploy.js +0 -195
  27. package/lib/server/firebaseServe.js +0 -116
  28. package/lib/server/getfbcfg.js +0 -25
  29. package/lib/server/getjson.js +0 -70
  30. package/lib/server/overwhelm.js +0 -447
  31. package/lib/server/push-my-chart.js +0 -18
  32. package/lib/server/refresh-npm-token.js +0 -135
  33. package/lib/server/tag-release.js +0 -681
  34. package/lib/server/unleash.js +0 -50
  35. package/lib/web/build-tools.js +0 -138
  36. package/lib/web/firebaseDeploy.js +0 -195
  37. package/lib/web/firebaseServe.js +0 -116
  38. package/lib/web/getfbcfg.js +0 -25
  39. package/lib/web/getjson.js +0 -70
  40. package/lib/web/overwhelm.js +0 -447
  41. package/lib/web/push-my-chart.js +0 -18
  42. package/lib/web/refresh-npm-token.js +0 -135
  43. package/lib/web/tag-release.js +0 -681
  44. package/lib/web/unleash.js +0 -50
  45. package/src/overwhelm.js +0 -396
@@ -1,50 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _execa = _interopRequireDefault(require("execa"));
5
- var _simpleGit = _interopRequireDefault(require("simple-git"));
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- const git = new _simpleGit.default();
8
- const getCurrentBranchName = async () => {
9
- const branchInfo = await git.branch();
10
-
11
- // first check to see if there are no branches - new repo?
12
- if (Object.keys(branchInfo.branches).length === 0) {
13
- return '';
14
- }
15
- return Object.entries(branchInfo.branches).find(([name, info]) => info.current)[0];
16
- };
17
- const isProtected = async () => {
18
- const theBranch = await getCurrentBranchName();
19
- const protectedBranches = ['main', 'master', 'development'];
20
- const additionalProtectedBranches = [...process.argv.slice(2)];
21
-
22
- // Check if the current branch starts with any of the additional
23
- // protected branch name
24
- let matchesAdditionalBranch = false;
25
- for (let i = 0; i < additionalProtectedBranches.length; i++) {
26
- matchesAdditionalBranch = matchesAdditionalBranch || theBranch.startsWith(additionalProtectedBranches[i]);
27
- }
28
- return protectedBranches.includes(theBranch) || matchesAdditionalBranch;
29
- };
30
- const npmRunner = async script => {
31
- try {
32
- const results = await (0, _execa.default)('npm', ['run', script], {
33
- stdio: 'inherit'
34
- });
35
- return results;
36
- } catch (err) {
37
- process.exit(1);
38
- }
39
- return undefined;
40
- };
41
- (async () => {
42
- if (await isProtected()) {
43
- const script = ['test', 'lint'];
44
- for (let i = 0; i < script.length; i++) {
45
- await npmRunner(script[i]); // eslint-disable-line no-await-in-loop
46
- }
47
- } else {
48
- process.exit(0);
49
- }
50
- })();
package/src/overwhelm.js DELETED
@@ -1,396 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // XXX console.log( `TOP=>[${process.cwd()}] PWD=[${process.env.PWD}]` )
4
- /* eslint-disable no-console */
5
-
6
- const path = require( 'node:path' )
7
- const exec = require( 'node:child_process' ).execSync
8
- const fs = require( 'node:fs' )
9
-
10
- const chalk = require( 'chalk' )
11
- const cliArgs = require( 'command-line-args' )
12
- // const cliHelp = require( 'command-line-usage' )
13
- const deepmerge = require( 'deepmerge' )
14
- const glob = require( 'glob' )
15
- const parse = require( 'parse-gitignore' )
16
- const ask = require( 'readline-sync' )
17
- const YAML = require( 'js-yaml' )
18
-
19
- const optionsDefinitions = [
20
- /* eslint-disable no-multi-spaces */
21
- { name : 'context', alias : 'x', type : String, default : '' },
22
- { name : 'section', alias : 's', type : String, default : 'default' },
23
- { name : 'key', alias : 'k', type : String },
24
- { name : 'export', alias : 'e', type : Boolean, default : false },
25
- { name : 'continue', alias : 'c', type : Boolean, default : false },
26
- { name : 'checkctx', alias : 't', type : Boolean, default : false }, // checks overwhelm context
27
- { name : 'fetchctx', alias : 'f', type : Boolean, default : false }, // fetch and set k8s context
28
- { name : 'genvals', alias : 'g', type : Boolean, default : false }, // only generates values.yaml
29
- { name : 'matchk8s', alias : 'm', type : Boolean, default : false }, // checks k8s context
30
- { name : 'verbose', alias : 'v', type : Boolean, default : false },
31
- /* eslint-enable no-multi-spaces */
32
- ]
33
- const args = cliArgs( optionsDefinitions )
34
-
35
- // See if we are in a monorepo, which changes some of the rules.
36
- const gitTop = exec(
37
- 'git rev-parse --show-toplevel', { stdio : [ undefined ] }
38
- ).toString().trim()
39
- let monoTop
40
- if ( fs.existsSync( `${gitTop}/packages` ) ) {
41
- monoTop = path.basename( path.resolve() ) // process.env.PWD
42
- console.log( `MONO=[${monoTop}]` )
43
- }
44
-
45
- // The kubernetes context is equal to the git branch name.
46
- const gitBranch = exec(
47
- 'git rev-parse --abbrev-ref HEAD', { stdio : [ undefined ] }
48
- ).toString().trim()
49
-
50
- const context = args.context || monoTop || gitBranch
51
-
52
- if ( context === 'master' ) {
53
- console.log( '***ERROR: master context is forbidden; change to a different branch\n\n' )
54
- process.exit( 1 )
55
- }
56
-
57
- if ( !fs.existsSync( 'overwhelm.yaml' ) ) {
58
- console.log( chalk.red.bold( `
59
-
60
- ***ERROR overwhelm => missing the overwhelm.yaml file - this command expects
61
- to execute from within a platform-k8s branch
62
- ` ) )
63
- process.exit( 1 )
64
- }
65
-
66
- // Load the default values and then overlay with the project specific yaml
67
- // values. This supports the notion of this type of approach in the
68
- // overwhelm yaml settings:
69
- // default:
70
- // GCE_MACHINE : "n1-standard-2"
71
- //
72
- // my-project:
73
- // GCE_MACHINE : "n1-highcpu-8"
74
- //
75
- // fashion, but it is advised not to set a default region with this
76
- // approach in order to keep us cognizant of exactly where a cluster is
77
- // being formed.
78
- //
79
- const yaml = YAML.load( fs.readFileSync( 'overwhelm.yaml', 'utf-8' ) )
80
- const over = yaml.default
81
- if ( process.env.OVERWHELM_DEBUG ) {
82
- console.log( { over, yaml }, '<==Contents of the over and yaml structs' )
83
- }
84
-
85
- let cfgs = yaml[context]
86
-
87
- // If we just need to check context return 0 if cfgs exists, else error.
88
- if ( args.checkctx ) { process.exit( !cfgs ) }
89
-
90
- if ( !cfgs ) {
91
- console.log( `***ERROR: Unknown context => [${context}]\n` )
92
- console.log( ' Known k8s contexts are:' )
93
- Object.keys( yaml ).forEach( ( key ) => {
94
- if ( key !== 'default' ) { console.log( ` ${key}` ) }
95
- } )
96
- console.log( `Add a section into overwhelm.yaml for ${context}\n\n` )
97
- process.exit( 1 )
98
- }
99
-
100
- // Check to see if we are deriving from another configuration.
101
- if ( cfgs.PROJECT_BASE ) {
102
- const baseName = cfgs.PROJECT_BASE
103
- const tempCfgs = cfgs
104
- cfgs = yaml[baseName]
105
- Object.keys( tempCfgs ).forEach( ( key ) => { cfgs[key] = tempCfgs[key] } )
106
- console.log( 'PROJECT_BASE still under evaluation' )
107
- console.log( '\n cfgs=', cfgs )
108
- process.exit( 1 ) // XXX HERE
109
- }
110
-
111
- Object.keys( cfgs ).forEach( ( key ) => { over[key] = cfgs[key] || over[key] } )
112
-
113
- // Expand any variables that reference other variable settings. A perfect
114
- // example of where this is useful is in the setting of a PROJECT_NAME and
115
- // a PROJECT_ID. Most of the time these values are identical, which is why
116
- // this setting exists in the default section:
117
- // default:
118
- // PROJECT_ID : ${PROJECT_NAME}
119
- //
120
- // However, in the case of projects like Siren Marine, this is the more
121
- // likely setup due to legacy naming schemes:
122
- // sire-marine:
123
- // PROJECT_NAME : siren-marine
124
- // PROJECT_ID : prod-rt-data
125
- //
126
- const varErrors = []
127
-
128
- Object.keys( over ).forEach( ( key ) => {
129
- if ( !over[key] ) return // no value to work with - skip it
130
-
131
- // Look for something in the form of "thing-${VAR1}-${VAR2}-${VARn}-stuff"
132
- const matches = over[key].match( /\$\{\w+\}/g )
133
- if ( !matches ) return
134
-
135
- matches.forEach( ( replaceThis ) => {
136
- // The matched variable names will be in the form of ${VARNAME} so drop
137
- // the ${} characters before using the VARNAME to map into the
138
- // overwhelm map containing the desired replacement value.
139
- const withThat = over[replaceThis.replace( /\W+/g, '' )]
140
- if ( !withThat ) {
141
- varErrors.push( `${key} : ${over[key]}` )
142
- return
143
- }
144
- // Store the replaced string back in the overwhelm value map.
145
- over[key] = over[key].replace( replaceThis, withThat )
146
- } )
147
- } )
148
-
149
- if ( varErrors.length > 0 ) {
150
- console.log( '***ERROR: unkown variable reference(s) in overwhelm.yaml:\n' )
151
- varErrors.forEach( ( error ) => {
152
- console.log( ` ${error}` )
153
- } )
154
- console.log( '' )
155
- process.exit( 1 )
156
- }
157
-
158
- // Grab a list of the existing yaml templates.
159
- const yams = glob.sync( 'values-*.yaml' )
160
-
161
- // A function to apply the replacements to all of the matching yaml which
162
- // will error out if it runs into an unknown OVH<tag>.
163
- const doReplacements = ( yamls, replacements ) => {
164
- let replYaml = yamls
165
-
166
- // wrap special chars with quotes if needed, like "#---incident-alerts---"
167
- const quoteSpecials = ( raw ) => {
168
- return /[#$?*]/g.test( raw ) ? `"${raw}"` : raw
169
- }
170
-
171
- Object.keys( replacements ).forEach( ( repl ) => {
172
- const replaceThis = new RegExp( `OVH:<${repl}>`, 'g' )
173
- const withThat = quoteSpecials( `${replacements[repl]}` )
174
- replYaml = replYaml.replace( replaceThis, withThat )
175
- } )
176
-
177
- // Verify all replaceables have been handled, or error out.
178
- const missed = replYaml.match( /OVH:<(.*)>/g )
179
-
180
- if ( missed ) {
181
- console.log( '\n***ERROR: missing replacements in overwhelm.yaml for these tags:\n' )
182
- missed.forEach( ( miss ) => {
183
- console.log( ` TAG: ${miss.match( /OVH:<(.*)>/ )[1]}` )
184
- } )
185
- console.log( '' )
186
- process.exit( 1 )
187
- }
188
-
189
- return replYaml
190
- }
191
-
192
- // Collect all of the yaml from the yams...
193
- const buildYaml = ( yamls, replacements ) => {
194
- const always = [ 'values-default.yaml' ]
195
- const values = [ ...always, ...yamls ]
196
- const loaded = []
197
- let allYamls = ''
198
-
199
- values.forEach( ( yaml ) => {
200
- if ( !fs.existsSync( yaml ) ) {
201
- console.log( `\n***ERROR: yaml file missing => ${yaml}\n` )
202
- process.exit( 1 )
203
- }
204
-
205
- if ( !loaded.includes( yaml ) ) {
206
- allYamls += `\n# AHOY => ${yaml}\n\n`
207
- allYamls += fs.readFileSync( yaml, { encoding : 'utf-8' } )
208
- loaded.push( yaml )
209
- }
210
- } )
211
-
212
- // Now apply all of the replacements from the overwhelm file.
213
- return doReplacements( allYamls, replacements )
214
- }
215
-
216
- // Call buildYaml to replace the OVH strings in the yaml files.
217
- const values = buildYaml( yams, over )
218
-
219
- // Check to see if someone is requesting a value from the yaml.
220
- if ( args.key ) {
221
- const section = args.section || 'default'
222
- const keys = yaml[section]
223
- if ( args.verbose ) {
224
- console.log( 'replacements' )
225
- console.log( keys )
226
- }
227
- if ( args.export ) {
228
- console.log( `export ${args.key}=${keys[args.key]}` )
229
- } else {
230
- console.log( keys[args.key] )
231
- }
232
- if ( !args.continue ) process.exit()
233
- }
234
-
235
- // Find all of the potential target dirs. Utilize .gitignore to ignore files
236
- const gitignore = parse( fs.readFileSync( '.gitignore' ) )
237
- const opt = {
238
- ignore : gitignore.patterns,
239
- }
240
-
241
- const ahoy = glob.sync( '*/', opt )
242
-
243
- // .noahoy = skips generation of values.yaml but allows helmup to run
244
- // .nohelm = overwhelm and helmup will skip the deployment entirely
245
- ahoy.forEach( ( dir ) => {
246
- if ( fs.existsSync( `${dir}/.noahoy` ) ) {
247
- !args.fetchctx && console.log( chalk.yellow( `***WARNING: .noahoy detected, not regenerating ${dir}values.yaml` ) )
248
- } else if ( !fs.existsSync( `${dir}/.nohelm` ) ) {
249
- args.verbose && console.log( `Generating values in ${dir}` ) // eslint-disable-line no-unused-expressions
250
-
251
- let valuesOut = [] // An accumulator for all of the output values.
252
-
253
- // Add support for localized values for things like keel (or whatever)
254
- const valuesLocal = `${dir}values-local.yaml`
255
-
256
- if ( fs.existsSync( valuesLocal ) ) {
257
- args.verbose && console.log( ` Local values in ${valuesLocal}` ) // eslint-disable-line no-unused-expressions
258
- valuesOut += '\n# AHOY => values-local.yaml\n\n'
259
- valuesOut += fs.readFileSync( valuesLocal, { encoding : 'utf-8' } )
260
- }
261
- valuesOut += `\n${values}`
262
-
263
- // Augment the default service section of the YAML with settings that
264
- // usually come from the top level overwhelm.yaml file.
265
- //
266
- const valuesAll = YAML.load( valuesOut ) || {}
267
- const valuesSvc = {
268
- service : {
269
- project_id : 'OVH:<PROJECT_ID>',
270
- project_name : 'OVH:<PROJECT_NAME>',
271
- host : 'OVH:<HOST>',
272
- ingress : 'OVH:<INGRESS>',
273
- }
274
- }
275
- const valuesMerged = YAML.dump( deepmerge( valuesSvc, valuesAll ), { quotingType : '"' } )
276
-
277
- valuesOut = doReplacements( valuesMerged, over )
278
-
279
- // DEPRECATED once siren and manheim are platform 4.0
280
- // If we are going to override then we need to convert it to YAML and
281
- // do a deepmerge to combine the values.
282
- const valuesOverride = `${dir}/values-override.yaml`
283
-
284
- if( fs.existsSync( valuesOverride ) ) {
285
- console.log( `===>Applying Overrides=> ${valuesOverride}` )
286
- const overrides = YAML.load( fs.readFileSync( valuesOverride, { encofind : 'utf-8' } ))
287
- const allValues = YAML.load( valuesOut )
288
- valuesOut = YAML.dump( deepmerge( allValues, overrides ), { quotingType : '"' } )
289
- }
290
- // DEPRECATED
291
-
292
- fs.writeFileSync( `${dir}/values.yaml`, valuesOut )
293
- }
294
- } )
295
-
296
- // we can also apply replaceables to any top level .ovh files to support top level config maps
297
- glob.sync( '**/*.ovh' ).forEach( ( cfgmap ) => {
298
- const target = cfgmap.replace( /.ovh$/, '' )
299
- let valuesOut = fs.readFileSync( cfgmap, { encoding : 'utf-8' } )
300
- valuesOut = doReplacements( valuesOut, over )
301
- fs.writeFileSync( target, valuesOut )
302
- } )
303
-
304
- if ( args.genvals ) { process.exit( 0 ) }
305
-
306
- // Set the GCP context for safety!
307
- const clusterName = over.CLUSTER_NAME
308
- if ( over.PROJECT_NAME === 'minikube' ) {
309
- process.exit( 0 )
310
- }
311
- const projectId = over.PROJECT_ID
312
- let zone = over.GCE_REGION + ( over.GCE_ZONE ? `-${over.GCE_ZONE}` : '' )
313
-
314
- if ( !clusterName ) {
315
- console.log( chalk.yellow(
316
- `
317
-
318
- The overwhelm.yaml file in this branch is missing a CLUSTER_NAME setting,
319
- which was added to support cluster names that do not match the project
320
- name. Since the mismatch is rare, you can probably get by with simply
321
- adding this line following PROJECT_NAME in the default section of
322
- overwhelm.yaml:
323
-
324
- ${chalk.bold.green( `CLUSTER_NAME : "\${PROJECT_NAME}"` )}
325
-
326
- However, if the CLUSTER_NAME is not the same as the PROJECT_NAME then go
327
- ahead and add the CLUSTER_NAME setting to the ${chalk.bold.green( projectId )} section of the
328
- overwhelm.yaml file.
329
-
330
- ` ) )
331
- process.exit( 1 )
332
- }
333
-
334
- let kubeout = '_no_current_context_'
335
- try {
336
- kubeout = exec( 'kubectl config current-context', { stdio : [ undefined ] } )
337
- } catch ( err ) {
338
- // err && console.log( `Caught Error =>[${err}]` )
339
- }
340
-
341
- const currentCtx = kubeout.toString().trim()
342
- let desiredCtx = `gke_${projectId}_${zone}_${clusterName}`
343
- let cmd = `gcloud container clusters get-credentials ${clusterName} --zone ${zone} --project ${projectId}`
344
-
345
- const matchedCtx = ( currentCtx === desiredCtx )
346
-
347
- if ( args.matchk8s ) {
348
- process.exit( matchedCtx ? 0 : 1 )
349
- }
350
-
351
- // just fetch the context and exit if -f is specified
352
- if ( args.fetchctx ) {
353
- if ( !matchedCtx ) {
354
- try {
355
- exec( `${cmd}`, { stdio : [ undefined ] } )
356
- } catch ( err ) {
357
- process.exit( 61 ) // ECONNREFUSED
358
- }
359
- }
360
- process.exit( 0 )
361
- }
362
-
363
- if ( matchedCtx ) {
364
- console.log( `
365
-
366
- Current context matches => ${chalk.bold.green( currentCtx )}
367
-
368
- ` )
369
- } else {
370
- console.log( `
371
- You are about to change your Kubernetes context to:
372
- CLUSTER_NAME => ${chalk.bold.green( clusterName )}
373
- PROJECT_ID => ${chalk.bold.green( projectId )}
374
- REGION => ${chalk.bold.green( zone )}
375
-
376
- ` )
377
- }
378
- const operation = matchedCtx ? 'refetch the credentials' : 'switch your context'
379
- const ans = ask.question( `Enter "${chalk.bold.green( 'yes' )}" if you wish to ${operation} => ` )
380
- if ( ans !== 'yes' ) {
381
- if ( matchedCtx ) {
382
- console.log( chalk.bold.yellow( '\n\nSkipping a refetch of your Kubernetes context and credentials\n\n' ) )
383
- process.exit( 0 )
384
- }
385
-
386
- console.log( chalk.bold.red( '\n\nYour Kubernetes context and credentials do NOT match - this could be bad!\n\n' ) )
387
- process.exit( 1 )
388
- }
389
-
390
- console.log( `\n\nExecuting: ${chalk.bold.yellow( cmd )}\n\n` )
391
- exec( `${cmd}`, ( error, out ) => {
392
- if ( error ) {
393
- console.log( `\n\n***ERROR ${error}\n\n` )
394
- process.exit( 1 )
395
- }
396
- } )