@leverege/build-tools 2.38.1 → 2.39.0-beta.1

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 (38) 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/firebaseDeploy.mjs +1 -0
  5. package/src/firebaseServe.mjs +1 -0
  6. package/src/getjson.mjs +3 -3
  7. package/src/helm-charts/firebase-rules/.nohelm +0 -0
  8. package/src/helm-charts/firebase-rules/firebase.json +5 -0
  9. package/src/helm-charts/firebase-rules/firebaserc.ovh +24 -0
  10. package/src/helm-charts/firebase-rules/gitignore +2 -0
  11. package/src/helm-charts/firebase-rules/helmup.plugin +14 -0
  12. package/src/helm-charts/firebase-rules/leverege.rules.json +65 -0
  13. package/src/helm-charts/velero/helmup.plugin +16 -0
  14. package/src/helmup.sh +47 -1
  15. package/src/{overwhelm.js → overwhelm.mjs} +69 -76
  16. package/src/push-my-chart.mjs +7 -6
  17. package/src/refresh-npm-token.mjs +142 -40
  18. package/src/unleash.mjs +4 -2
  19. package/lib/server/build-tools.js +0 -138
  20. package/lib/server/firebaseDeploy.js +0 -195
  21. package/lib/server/firebaseServe.js +0 -116
  22. package/lib/server/getfbcfg.js +0 -25
  23. package/lib/server/getjson.js +0 -70
  24. package/lib/server/overwhelm.js +0 -445
  25. package/lib/server/push-my-chart.js +0 -18
  26. package/lib/server/refresh-npm-token.js +0 -135
  27. package/lib/server/tag-release.js +0 -681
  28. package/lib/server/unleash.js +0 -50
  29. package/lib/web/build-tools.js +0 -138
  30. package/lib/web/firebaseDeploy.js +0 -195
  31. package/lib/web/firebaseServe.js +0 -116
  32. package/lib/web/getfbcfg.js +0 -25
  33. package/lib/web/getjson.js +0 -70
  34. package/lib/web/overwhelm.js +0 -445
  35. package/lib/web/push-my-chart.js +0 -18
  36. package/lib/web/refresh-npm-token.js +0 -135
  37. package/lib/web/tag-release.js +0 -681
  38. package/lib/web/unleash.js +0 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.38.1",
3
+ "version": "2.39.0-beta.1",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -14,12 +14,12 @@
14
14
  "compile_server": "NODE_ENV=server babel -d lib/server src/",
15
15
  "compile_web": "NODE_ENV=web babel -d lib/web src/",
16
16
  "lint": "find ./src -name \\*.\\*js | xargs npx eslint --report-unused-disable-directives",
17
- "prepublintOnly": "npm run lint && npm run build",
18
- "prepublishOnly": "npm run compile",
17
+ "xprepublintOnly": "npm run lint && npm run build",
18
+ "xprepublishOnly": "npm run compile",
19
19
  "test": "echo \"Error: no test specified\" && exit 1"
20
20
  },
21
21
  "bin": {
22
- "build-tools": "src/build-tools.js",
22
+ "build-tools": "src/build-tools.mjs",
23
23
  "circleate": "src/circleate.sh",
24
24
  "decrypt-secrets": "src/decrypt-secrets.sh",
25
25
  "dirty-git": "src/dirty-git.sh",
@@ -55,17 +55,16 @@
55
55
  "license": "SEE LICENSE IN LICENSE.md",
56
56
  "dependencies": {
57
57
  "ansi-colors": "^4.1.3",
58
- "chalk": "^4.1.2",
58
+ "chalk": "^5.3.0",
59
59
  "command-line-args": "^5.2.1",
60
- "command-line-usage": "^6.1.3",
60
+ "command-line-usage": "^7.0.1",
61
61
  "deepmerge": "^4.3.1",
62
- "dotenv": "^16.3.1",
63
62
  "enquirer": "^2.4.1",
64
- "execa": "^5.1.1",
65
- "get-bin-path": "^10.0.0",
66
- "glob": "^8.1.0",
63
+ "execa": "^8.0.1",
64
+ "glob": "^10.3.4",
67
65
  "js-yaml": "^4.1.0",
68
- "npm-registry-fetch": "^13.3.1",
66
+ "ms": "^2.1.3",
67
+ "npm-registry-fetch": "^16.0.0",
69
68
  "parse-gitignore": "^2.0.0",
70
69
  "read-pkg": "^8.1.0",
71
70
  "readline-sync": "^1.4.10",
@@ -74,10 +73,7 @@
74
73
  "zx": "^7.2.3"
75
74
  },
76
75
  "devDependencies": {
77
- "@babel/cli": "^7.22.10",
78
- "@babel/core": "^7.22.11",
79
- "@leverege/babel-preset-leverege-node": "^2.0.0",
80
- "@leverege/eslint-config-leverege": "^3.0.1",
81
- "npm": "^9.8.1"
76
+ "@leverege/eslint-config-leverege": "^4.2.0",
77
+ "npm": "^10.0.0"
82
78
  }
83
79
  }
package/src/Utils.mjs ADDED
@@ -0,0 +1,30 @@
1
+ import chalk from 'chalk'
2
+ import { $ } from 'execa'
3
+
4
+ const debugEnabled = process.env.BUILD_TOOLS_DEBUG === '1'
5
+
6
+ // eslint-disable-next-line no-console
7
+ export const log = console.log
8
+ export const debug = ( obj, text ) => {
9
+ if ( debugEnabled ) {
10
+ log( obj, `${chalk.yellow( '***DEBUG:' )} ${chalk.green( text )}` )
11
+ }
12
+ }
13
+
14
+ export const shellCmd = async ( cmdstr, opts = {} ) => {
15
+ try {
16
+ // due to the escaping rules we pull apart the cmdstr and invoke $ using
17
+ // the (command, argsArray) or the escaped command sent to spawn will have
18
+ // addition double quotes which causes fail
19
+ const [ command, ...args ] = cmdstr.split( ' ' )
20
+
21
+ debug( { command, args }, '<==execa $ invoke' )
22
+ const results = await $( opts )`${command} ${args}`
23
+ debug( { results }, '<==execa $ results' )
24
+
25
+ return results.stdout
26
+ } catch ( error ) {
27
+ debug( { error } )
28
+ throw error
29
+ }
30
+ }
@@ -1,13 +1,31 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable security/detect-non-literal-fs-filename */
3
+
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import url from 'node:url'
7
+
8
+ import chalk from 'chalk'
9
+ import cliArgs from 'command-line-args'
10
+ import cliHelp from 'command-line-usage'
11
+ import npmRegistryFetch from 'npm-registry-fetch'
12
+ import { lt as semverLt } from 'semver'
13
+
14
+ // because __dirname goes away with ESM
15
+ const getFilename = () => {
16
+ const filename = url.fileURLToPath( import.meta.url )
17
+ return filename
18
+ }
2
19
 
3
- const fs = require( 'node:fs' )
4
- const path = require( 'node:path' )
20
+ const getDirname = () => {
21
+ const dirname = path.dirname( getFilename() )
22
+ return dirname
23
+ }
5
24
 
6
- const chalk = require( 'chalk' )
7
- const cliArgs = require( 'command-line-args' )
8
- const cliHelp = require( 'command-line-usage' )
9
- const npmRegistryFetch = require( 'npm-registry-fetch' )
10
- const semverLt = require( 'semver/functions/lt' )
25
+ const repoRoot = path.dirname( getDirname() )
26
+ const thisVersion = JSON.parse(
27
+ fs.readFileSync( `${repoRoot}/package.json` )
28
+ ).version
11
29
 
12
30
  /* eslint-disable no-console */
13
31
 
@@ -65,10 +83,6 @@ const sections = [
65
83
  const args = cliArgs( optionList, { partial : true } )
66
84
  const help = cliHelp( sections )
67
85
 
68
- const repoRoot = path.dirname( __dirname )
69
- const thisPackage = require( `${repoRoot}/package.json` )
70
- const thisVersion = thisPackage.version
71
-
72
86
  if ( args.root ) {
73
87
  console.log( repoRoot )
74
88
  process.exit( 0 )
@@ -93,7 +107,7 @@ const checkForLatest = async ( pkg = '@leverege/build-tools' ) => {
93
107
  }
94
108
  try {
95
109
  const tokenLine = fs.readFileSync( tokenFile ).toString()
96
- const tokenRegX = new RegExp( '.*registry.npmjs.org\\/:\\w+=+(.*)' )
110
+ const tokenRegX = '.*registry.npmjs.org\\/:\\w+=+(.*)' // old => new RegExp( '.*registry.npmjs.org\\/:\\w+=+(.*)' )
97
111
  const tokenStr = tokenLine.match( tokenRegX )
98
112
  if ( !tokenStr ) {
99
113
  console.error( `\n***ERROR: malformed npm token in ${tokenFile}\n` )
@@ -103,6 +117,7 @@ const checkForLatest = async ( pkg = '@leverege/build-tools' ) => {
103
117
  } catch ( err ) {
104
118
  console.error( err )
105
119
  }
120
+ return undefined
106
121
  }
107
122
 
108
123
  try {
@@ -113,6 +128,7 @@ const checkForLatest = async ( pkg = '@leverege/build-tools' ) => {
113
128
  } catch ( err ) {
114
129
  console.log( err )
115
130
  }
131
+ return undefined
116
132
  }
117
133
 
118
134
  const checkAndAnnounce = () => {
@@ -78,6 +78,7 @@ const targets = Object
78
78
  // Store the longest length of site id for formatting later on
79
79
  maxSiteIdLength = Math.max( siteId.length, maxSiteIdLength )
80
80
 
81
+ // eslint-disable-next-line no-param-reassign
81
82
  prev[alias] = {
82
83
  projectId,
83
84
  siteId,
@@ -61,6 +61,7 @@ const targets = Object
61
61
  .entries( config.hosting )
62
62
  .forEach( ( [ siteId, aliases ] ) => {
63
63
  aliases.forEach( ( alias ) => {
64
+ // eslint-disable-next-line no-param-reassign
64
65
  prev[alias] = {
65
66
  projectId,
66
67
  siteId,
package/src/getjson.mjs CHANGED
@@ -18,7 +18,7 @@
18
18
  /**
19
19
  * Get a command line switch parser.
20
20
  */
21
- import fs from 'fs'
21
+ import fs from 'node:fs'
22
22
  import cliArgs from 'command-line-args'
23
23
  import cliHelp from 'command-line-usage'
24
24
 
@@ -64,9 +64,9 @@ if ( !args.file ) {
64
64
  }
65
65
 
66
66
  try {
67
- const json = JSON.parse( fs.readFileSync( args.file, 'utf8' ) )
67
+ const json = JSON.parse( fs.readFileSync( args.file, 'utf8' ) ) // eslint-disable-line security/detect-non-literal-fs-filename
68
68
  const value = json[args.key]
69
- const match = new RegExp( args.regex || '.*' ).exec( value )
69
+ const match = new RegExp( args.regex || '.*' ).exec( value ) // eslint-disable-line security/detect-non-literal-regexp
70
70
 
71
71
  console.log( match ? match[match.length - 1] : '' )
72
72
  } catch ( e ) {
File without changes
@@ -0,0 +1,5 @@
1
+ {
2
+ "database": [
3
+ {"target": "leverege", "rules": "leverege.rules.json"}
4
+ ]
5
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "projects": {
3
+ "default": "OVH:<PROJECT_ID>"
4
+ },
5
+ "targets": {
6
+ "OVH:<PROJECT_ID>": {
7
+ "database": {
8
+ "leverege": [
9
+ "OVH:<PROJECT_ID>",
10
+ "OVH:<PROJECT_ID>-rt-0",
11
+ "OVH:<PROJECT_ID>-rt-1",
12
+ "OVH:<PROJECT_ID>-rt-2",
13
+ "OVH:<PROJECT_ID>-rt-3",
14
+ "OVH:<PROJECT_ID>-rt-4",
15
+ "OVH:<PROJECT_ID>-rt-5",
16
+ "OVH:<PROJECT_ID>-rt-6",
17
+ "OVH:<PROJECT_ID>-rt-7",
18
+ "OVH:<PROJECT_ID>-rt-8",
19
+ "OVH:<PROJECT_ID>-rt-9"
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ firebaserc
2
+ .firebaserc
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ # make sure we're running from the proper dir
4
+ cd $GITTOP/firebase-rules
5
+
6
+ # grab a copy of existing rules - date time stamp DTS comes from bash-funcs
7
+ firebase --project $GCP_PROJECT_ID \
8
+ database:get /.settings/rules > leverege.rules.previous.json
9
+
10
+ # copy the current ovh generated rc file to where firebase will find it
11
+ cp firebaserc .firebaserc
12
+
13
+ # Note: GCP_PROJECT_ID is passed down from helmup's environment.
14
+ firebase --project $GCP_PROJECT_ID deploy --only database
@@ -0,0 +1,65 @@
1
+ {
2
+ "rules": {
3
+ "projectRefs": {
4
+ "$project_id": {
5
+ "member": {
6
+ ".indexOn": ["created"]
7
+ }
8
+ }
9
+ },
10
+ "blueprint": {
11
+ ".indexOn": "lastModified"
12
+ },
13
+ "blueprintChildren": {
14
+ "$bp_id": {
15
+ "attributes": {
16
+ ".indexOn": ".value"
17
+ }
18
+ }
19
+ },
20
+ "attribute":{
21
+ ".indexOn" : [ "path", "blueprintId" ]
22
+ },
23
+ "systemChildren": {
24
+ "$sys_id": {
25
+ "device": {
26
+ ".indexOn": ".value"
27
+ }
28
+ }
29
+ },
30
+ "device": {
31
+ ".indexOn": ["id", "networkId", "simNetworkId"]
32
+ },
33
+ "deviceRefs": {
34
+ "$dev_id": {
35
+ "member": {
36
+ ".indexOn": ["created"]
37
+ }
38
+ }
39
+ },
40
+ "user": {
41
+ ".indexOn": ["username", "email"]
42
+ },
43
+ "project": {
44
+ ".indexOn": ["id"]
45
+ },
46
+ "rt": {
47
+ "$sys_id": {
48
+ ".read": "auth.systemId === $sys_id",
49
+ "dev": {
50
+ "$dev_id": {
51
+ ".read": "auth.deviceId === $dev_id",
52
+ "outbound": {
53
+ ".indexOn": ["initiated", "sent", "ack"]
54
+ },
55
+ "events": {
56
+ "$evt_type": {
57
+ ".indexOn": ["time", "id"]
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
@@ -31,6 +31,22 @@ helm upgrade \
31
31
  --set configuration.backupStorageLocation[0].config.serviceAccount="$GCE_SA_EMAIL" \
32
32
  --set configuration.volumeSnapshotLocation[0].config.snapshotLocation="$GCE_REGION"
33
33
 
34
+ if [ $? -ne 0 ];
35
+ then
36
+ cat<<VELERROR
37
+
38
+ `color r ***ERROR:` helm upgrade has failed! If upgrading from an older chart there
39
+ may be residual velero components that need to be cleaned up. Try running the
40
+ following kubectl commands and then rerun helmup:
41
+
42
+ kubectl delete backupstoragelocations.velero.io -n velero default
43
+ kubectl delete volumesnapshotlocations.velero.io -n velero default
44
+ helmup velero
45
+
46
+ VELERROR
47
+ exit 1
48
+ fi
49
+
34
50
  velero schedule get
35
51
  cat<<DONE_VELERO
36
52
 
package/src/helmup.sh CHANGED
@@ -152,10 +152,29 @@ MISSING_HELMUP_PLUGIN
152
152
  # because npm tends to not allow .gitinore files the easy way...
153
153
  [ -f "$SERVICE/gitignore" ] && mv $SERVICE/gitignore $SERVICE/.gitignore
154
154
  git add $SERVICE
155
- overwhelm.js --genvals
155
+ overwhelm --genvals
156
156
  ifPluggedIn $SERVICE
157
157
  }
158
158
 
159
+ function installDefaultConfigs() {
160
+ showInstalling "Default Configs"
161
+
162
+ clearlyWarn 'without clearing'
163
+ cat<<INSTALLDEFAULTCONFIGS
164
+ Continuing with applying the default-configs.yaml will cause all non-system
165
+ services to `color r restart`. Make certain people are made aware that this is about
166
+ to happen.
167
+
168
+ INSTALLDEFAULTCONFIGS
169
+ yesToContinue "to apply the default-configs to the cluster"
170
+
171
+ kubecmd="kubectl apply -f default-configs.yaml"
172
+
173
+ printf "\nRunning => `color y \"$kubecmd\"`\n\n"
174
+ eval $kubecmd
175
+ postToSlack "$kubecmd"
176
+ }
177
+
159
178
  function errorIfMissingSecret() {
160
179
  SECRET="$1"
161
180
  kubectl get secret $SECRET &> $DEVNULL
@@ -165,6 +184,24 @@ function errorIfMissingSecret() {
165
184
  fi
166
185
  }
167
186
 
187
+ function installFirebaseDatabases() {
188
+ showInstalling "Firebase Realtime Databases"
189
+
190
+ open https://console.firebase.google.com/u/0/project/${GCP_PROJECT_ID}/authentication/users
191
+ yesToContinue "when you have pressed Get Started on the Firebase Authentication page"
192
+
193
+ # create the firebase primary db
194
+ firebase --project $GCP_PROJECT_ID database:instances:create ${PROJECT}
195
+
196
+ # TODO: should maybe be more flexible with number of shards in the future
197
+ for SHARD in {0..9}
198
+ do
199
+ SHARD="${GCP_PROJECT_ID}-rt-${SHARD}"
200
+ printf "Creating shard $SHARD\n"
201
+ firebase --project $GCP_PROJECT_ID database:instances:create ${SHARD}
202
+ done
203
+ }
204
+
168
205
  function installStackdriverExporterEnvironment() {
169
206
  showInstalling "Stackdriver Exporter Service Account Binding"
170
207
 
@@ -627,6 +664,10 @@ CATBACKUP
627
664
  kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter.yaml
628
665
  ;;
629
666
 
667
+ default-configs*)
668
+ installDefaultConfigs
669
+ ;;
670
+
630
671
  db-curator*)
631
672
  # db-curator / db-curator-dh diffs are defined in values-local.yaml
632
673
  HELMUP="helm upgrade --install $SERVICE leverege/db-curator --values $SERVICE/values.yaml $CHARTVER $HELM_WHAT"
@@ -649,6 +690,11 @@ CATBACKUP
649
690
  installPreemptibleKiller # the gke preemptible node spreader outer
650
691
  ;;
651
692
 
693
+ "firebase")
694
+ installFirebaseDatabases
695
+ bootstrapLocalSetup firebase-rules
696
+ ;;
697
+
652
698
  "grafana")
653
699
  bootstrapLocalSetup $SERVICE
654
700
  ;;