@leverege/build-tools 2.51.5 → 2.52.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.51.5",
3
+ "version": "2.52.0-beta.1",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/Docker.mjs CHANGED
@@ -40,8 +40,12 @@ COPY ./.npmrc /usr/src/app/.npmrc
40
40
  RUN apk --no-cache add openssh-client && \
41
41
  apk --update add --no-cache --virtual build-dep g++ gcc libgcc \\
42
42
  libstdc++ linux-headers make {{apkadds}} && \
43
- npm install -g npm@10 && \
44
- npm ci --only=production --ignore-scripts --no-optional {{npmlogging}} && \
43
+ npm install -g npm@10
44
+
45
+ {{preInstallPluginfile}}
46
+
47
+ # Removed --ignore-scripts from npm ci because it was causing issues with python native build
48
+ RUN npm ci --only=production --no-optional {{npmlogging}} && \
45
49
  rm -f /usr/src/app/.npmrc /root/.ssh/*
46
50
 
47
51
  # --------------------------------------------------------------
@@ -67,7 +71,7 @@ COPY --chown=node:node --from=intermediate /usr/src/app /usr/src/app
67
71
 
68
72
  USER {{runuser}}
69
73
  COPY ./bashrc /home/node/.bashrc
70
- CMD [ "/bin/bash", "-c", "node index.js" ]`
74
+ CMD [ "/bin/bash", "-c", "source /home/node/.bashrc && node index.js" ]`
71
75
 
72
76
  const pluginTemplate = `
73
77
  # Dockerfile.plugin - optionally extend the service Docker image
@@ -132,6 +136,19 @@ dunm() {
132
136
  du -sh /usr/src/app/node_modules/* | sort -sh
133
137
  }
134
138
  `
139
+ const cloudBuildSteps = `
140
+ steps:
141
+ - name: 'gcr.io/cloud-builders/docker'
142
+ args:
143
+ - 'build'
144
+ - '--network=cloudbuild'
145
+ - '-t'
146
+ - '{{imageName}}:{{imageVersion}}'
147
+ - '.'
148
+
149
+ images:
150
+ - '{{imageName}}:{{imageVersion}}'
151
+ `
135
152
 
136
153
  const defaultSettings = {
137
154
  apkadds : '',
@@ -139,6 +156,7 @@ const defaultSettings = {
139
156
  nodeimage : 'iron-alpine',
140
157
  npmlogging : '--silent',
141
158
  pluginfile : '# NO PLUGIN',
159
+ preInstallPluginfile : '# NO PRE-INSTALL PLUGIN',
142
160
  regvers : 'package.version',
143
161
  runuser : 'node',
144
162
  }
@@ -168,8 +186,14 @@ const generateDockerfile = ( settings = defaultSettings ) => {
168
186
 
169
187
  const bashrcFile = './docker/bashrc'
170
188
  if ( !fs.existsSync( bashrcFile ) ) {
189
+ let bf = bashrcTemplate
190
+ const bashrcFilePlugin = './docker/Bashrc.plugin'
191
+ if ( fs.existsSync( bashrcFilePlugin ) ) {
192
+ const bashrcAdditions = fs.readFileSync( bashrcFilePlugin )
193
+ bf = `${bf}\n${bashrcAdditions}`
194
+ }
171
195
  warning( `creating the missing ${bashrcFile} file in the docker directory` )
172
- fs.writeFileSync( bashrcFile, bashrcTemplate )
196
+ fs.writeFileSync( bashrcFile, bf )
173
197
  }
174
198
 
175
199
  const dockerfilePlugin = './docker/Dockerfile.plugin'
@@ -194,7 +218,12 @@ const generateDockerfile = ( settings = defaultSettings ) => {
194
218
  errorExit( `***ERROR: something went wrong with ${dockerfilePlugin} plugin creation` )
195
219
  }
196
220
 
197
- const compiled = handlebars.compile( dockerfileTemplate )
221
+ const dockerfilePrePlugin = './docker/DockerfilePreInstall.plugin'
222
+ if ( fs.existsSync( dockerfilePrePlugin ) ) {
223
+ defaultSettings.preInstallPluginfile = fs.readFileSync( dockerfilePrePlugin )
224
+ }
225
+
226
+ const compiled = handlebars.compile( dockerfileTemplate, { noEscape : true } )
198
227
  const replaced = compiled( settings )
199
228
  // temporarily write the Dockerfile to the docker subdir - the container
200
229
  // image builder will then move it over to the build subdir
@@ -226,8 +255,10 @@ const validateCloudBuildBucket = async ( artifactProject ) => {
226
255
  }
227
256
 
228
257
  const buildContainerImage = async ( {
229
- artifactProject, artifactRegistry, containerName, imageVersion, isNpmWorkspace,
258
+ artifactProject, artifactRegistry, containerName,
259
+ imageVersion, isNpmWorkspace, options
230
260
  } ) => {
261
+ const { useCloudBuildFile } = options || {}
231
262
  const buildWorkspace = './build/workspace' // passed to Cloud Build
232
263
  const imageName = `${artifactRegistry}/images/${containerName}`
233
264
 
@@ -256,14 +287,24 @@ const buildContainerImage = async ( {
256
287
  const { fullName : builderName } = await getGcpAccount()
257
288
  const gcloudBuild = `time gcloud builds submit --project ${artifactProject}`
258
289
  const gcloudLogs = `--gcs-log-dir ${formCloudBuildBucketName( artifactProject )}/log`
259
- const gcloudTags = `--tag ${imageName}:${imageVersion}`
290
+ let gcloudTags = `--tag ${imageName}:${imageVersion} `
291
+
292
+ if ( useCloudBuildFile ) {
293
+ const cloudBuildFile = './docker/cloudbuild.yaml'
294
+ gcloudTags = `--config=${cloudBuildFile}`
295
+ const cbst = handlebars.compile( cloudBuildSteps, { noEscape : true } )
296
+ const cbs = cbst( { artifactProject, artifactRegistry, imageName, imageVersion } )
297
+
298
+ fs.writeFileSync( cloudBuildFile, cbs )
299
+ }
260
300
 
261
301
  log( chalk.green.bold( `
262
- *** Submitting Build as ${builderName} ***
263
- ${gcloudBuild} \\
264
- ${gcloudLogs} \\
265
- ${gcloudTags}
266
- ` ) )
302
+ *** Submitting Build as ${builderName} ***
303
+ ${gcloudBuild} \\
304
+ ${gcloudLogs} \\
305
+ ${gcloudTags}
306
+ ` ) )
307
+
267
308
 
268
309
  if ( process.env.DRY_RUN === '1' ) {
269
310
  log( '\n***Exiting from DRY_RUN\n' )
@@ -26,8 +26,22 @@ if ( refreshErr && !process.env.BUILD_TOOLS_DEBUG ) {
26
26
  log( refreshErr ) // most likely the token refreshed message
27
27
  }
28
28
 
29
+ const options = {}
30
+ let imageVersion = null
29
31
  // Expected to be invoked like docker-to-registry v1.2.3
30
- const imageVersion = process.argv[2]
32
+ for ( let n = 2; n < process.argv.length; n++ ) {
33
+ if ( process.argv[n].startsWith( '-' ) ) {
34
+ const str = process.argv[n].slice( 1 )
35
+ if ( str.indexOf( '=' ) > 0 ) {
36
+ const [key, value] = str.split( '=' )
37
+ options[key] = value
38
+ } else {
39
+ options[str] = true
40
+ }
41
+ } else {
42
+ imageVersion = process.argv[n]
43
+ }
44
+ }
31
45
  if ( !imageVersion ) {
32
46
  errorExit( '***Error: docker-to-registry requires an image version' )
33
47
  }
@@ -151,39 +165,41 @@ if ( giveGuidance ) {
151
165
  }
152
166
 
153
167
  // do chart checks too
154
- const chart = helmChart?.yaml['Chart.yaml']
155
- const values = helmChart?.yaml['values.yaml']
156
- const expectedChartRegistry = `${artifactRegistry}/images`
168
+ if ( options?.helmChecks !== 'false' ) {
169
+ const chart = helmChart?.yaml['Chart.yaml']
170
+ const values = helmChart?.yaml['values.yaml']
171
+ const expectedChartRegistry = `${artifactRegistry}/images`
157
172
 
158
- if ( expectedChartRegistry !== values.image?.registry ) {
159
- log( `
160
- ${chalk.red.bold( '***Error: mismatched package.json registry and helm/values.yaml' )}
173
+ if ( expectedChartRegistry !== values.image?.registry ) {
174
+ log( `
175
+ ${chalk.red.bold( '***Error: mismatched package.json registry and helm/values.yaml' )}
161
176
 
162
- The registry specified in the package.json leverege stanza does not line up
163
- with the image registry in helm/values.yaml. The naming convention expects
164
- the '/images' suffix to be added to the package.json registry string and then
165
- stored as the image.registry in the helm/values.yaml file.
177
+ The registry specified in the package.json leverege stanza does not line up
178
+ with the image registry in helm/values.yaml. The naming convention expects
179
+ the '/images' suffix to be added to the package.json registry string and then
180
+ stored as the image.registry in the helm/values.yaml file.
166
181
 
167
- Current settings:
168
- package.json registry => ${chalk.yellow.bold( artifactRegistry )}
169
- values.yaml registry => ${chalk.red.bold( values.image?.registry )}
182
+ Current settings:
183
+ package.json registry => ${chalk.yellow.bold( artifactRegistry )}
184
+ values.yaml registry => ${chalk.red.bold( values.image?.registry )}
170
185
 
171
- Expected settings:
172
- values.yaml registry => ${chalk.green.bold( expectedChartRegistry )}
173
- ` )
186
+ Expected settings:
187
+ values.yaml registry => ${chalk.green.bold( expectedChartRegistry )}
188
+ ` )
174
189
 
175
- if ( !values.image ) {
176
- log( `
177
- ${chalk.yellow.bold( '***DEPRECATED: legacy helm charts detected' )}
190
+ if ( !values.image ) {
191
+ log( `
192
+ ${chalk.yellow.bold( '***DEPRECATED: legacy helm charts detected' )}
178
193
 
179
- The helm chart structure appears to be based on the pre-ignition helm chart
180
- layouts. The charts must be upgraded before docker-to-registry can complete
181
- its job.
194
+ The helm chart structure appears to be based on the pre-ignition helm chart
195
+ layouts. The charts must be upgraded before docker-to-registry can complete
196
+ its job.
182
197
 
183
- ` )
184
- }
198
+ ` )
199
+ }
185
200
 
186
- process.exit( 1 )
201
+ process.exit( 1 )
202
+ }
187
203
  }
188
204
 
189
205
  // Give the summary and the user a chance to proceed or not
@@ -256,7 +272,7 @@ if ( isNpmWorkspace ) {
256
272
  await shellCmd( 'npm install --package-lock-only --workspaces false', { stdio : 'inherit' } )
257
273
  }
258
274
 
259
- await docker.buildContainerImage( { artifactProject, artifactRegistry, containerName, imageVersion, isNpmWorkspace } )
275
+ await docker.buildContainerImage( { ...repoDescr, options, imageVersion } )
260
276
 
261
277
  if ( willGitTag ) {
262
278
  const tagDescription = `docker_${imageVersion}`
@@ -17,6 +17,17 @@ config:
17
17
  # # timescale
18
18
  # PG_HOST: "cnpg-db-tsdb-basic-r.cnpg-operands"
19
19
 
20
+ # The settings on the left are for the "standard" legacy chart settings which
21
+ # specifiy the old k8s secrets setups and are the defaults values from the
22
+ # api-server helm chart.
23
+ psqlSecurity: # v----- these are for CNPG -----v
24
+ PSQL_SECRET_NAME: "authz-postgres" # "cnpg-db-psql-stack-postgres-pw"
25
+ PSQL_SECRET_KEY: "postgresql-password" # "password"
26
+ TSDB_SECRET_NAME: "postgresql-password" # "cnpg-db-tsdb-basic-postgres-pw"
27
+ TSDB_SECRET_KEY: "postgresql-password" # "password"
28
+ TSDB_DENSE_SECRET_NAME: "postgresql-password" # "cnpg-db-tsdb-dense-postgres-pw"
29
+ TSDB_DENSE_SECRET_KEY: "postgresql-password" # "password"
30
+
20
31
  autoscaling:
21
32
  minReplicas: 3
22
33
  maxReplicas: 12
@@ -1,20 +0,0 @@
1
- registry:
2
- - root: us-docker.pkg.dev
3
- - repositories:
4
- - name: stack
5
- charts:
6
- - api-server
7
- - authz-server
8
- - emailer
9
- - message-processor
10
- - name: leverege
11
- charts:
12
- - pubsub-pulse
13
- - pusher
14
- - overdose
15
- - name: cox-health
16
- charts:
17
- - actions-server
18
- - analytics-server
19
- - centrak-healthz
20
- - centrak-ingestor
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env node
2
- /*
3
- * chart-to-registry will...
4
- */
5
- import fs from 'node:fs'
6
-
7
- import chalk from 'chalk'
8
- import commandLineArgs from 'command-line-args'
9
- import commandLineUsage from 'command-line-usage'
10
- import { lt as semverLt } from 'semver'
11
- import YAML from 'js-yaml'
12
-
13
- import {
14
- condir,
15
- debug,
16
- errorExit,
17
- log,
18
- warning,
19
- getGitRootDirectory,
20
- parsePackageJson,
21
- parseHelmChart,
22
- shellCmd } from './Utils.mjs'
23
-
24
- const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
25
- /* eslint-disable max-len */
26
- {
27
- name : 'location',
28
- type : String,
29
- description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
30
- },
31
- {
32
- name : 'project',
33
- type : String,
34
- description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
35
- },
36
- {
37
- name : 'repository',
38
- type : String,
39
- description : '{green the target repository to receive the pushed chart}',
40
- },
41
- {
42
- name : 'dry-run',
43
- type : Boolean,
44
- description : '{yellow perform everything except the actual chart push}',
45
- },
46
- {
47
- name : 'help',
48
- type : Boolean,
49
- description : '{green display this help screen}',
50
- },
51
- /* eslint-enable max-len */
52
- ]
53
-
54
- const sections = [
55
- {
56
- header : 'Leverege Helm Chart Compass (for helmup)',
57
- content : `{green This tool helps helmup navigate the helm charts stored in the
58
- artifact-registries.}`
59
- },
60
- { header : 'Options',
61
- optionList : commandLineOptions,
62
- },
63
- ]
64
-
65
- const args = commandLineArgs( commandLineOptions, { camelCase : true, partial : true } )
66
- const usage = commandLineUsage( sections )
67
-
68
- if ( args.help ) {
69
- log( usage )
70
- process.exit( 0 )
71
- }
72
-
73
- /* eslint-disable no-underscore-dangle */
74
- if ( args._unknown ) {
75
- log( usage )
76
- log( `\nUnrecognized argument [${chalk.bold.red( args._unknown )}]\n` )
77
- process.exit( 1 )
78
- }
79
- /* eslint-enable no-underscore-dangle */
80
-
81
- const minNodejsVersion = '18.0.0'
82
- if ( semverLt( process.version, minNodejsVersion ) ) {
83
- errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
84
- }
85
-
86
- // First of all, fail if we are not in a git repository
87
- let gitRoot
88
- try {
89
- gitRoot = await getGitRootDirectory()
90
- } catch ( error ) {
91
- errorExit( chalk.red.bold( error ), { errorCode : 5 } )
92
- }
93
-
94
- const chartCompass = YAML.load( fs.readFileSync( './registry-compass.yaml', 'utf8' ) )
95
-
96
- condir( { chartCompass }, '<==Navigation' )