@leverege/build-tools 2.48.1 → 2.48.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.48.1",
3
+ "version": "2.48.2",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/Utils.mjs CHANGED
@@ -125,7 +125,7 @@ export const getGitUpstream = async () => {
125
125
 
126
126
  export const gitRepoIsDirty = async () => {
127
127
  const cleanliness = await shellCmd( 'git status --porcelain' )
128
- return cleanliness?.length
128
+ return cleanliness?.length > 0
129
129
  }
130
130
 
131
131
  export const parseJsonFile = async ( jsonFile ) => {
@@ -343,9 +343,15 @@ export const parseHelmChart = async ( helmroot = './helm' ) => {
343
343
  const chartYaml = YAML.load( readFileSync( `${helmroot}/Chart.yaml`, 'utf8' ) )
344
344
  const chartPackage = `${chartYaml.name}-${chartYaml.version}.tgz`
345
345
  const valuesYaml = YAML.load( readFileSync( `${helmroot}/values.yaml`, 'utf8' ) )
346
+ const imageRegistry = valuesYaml.image?.registry
347
+ const registryComponents = imageRegistry.split( '/' )
346
348
  /* eslint-enable security/detect-non-literal-fs-filename */
347
349
  return ( {
348
350
  chartPackage,
351
+ imageRegistry,
352
+ registryRegion : registryComponents[0],
353
+ registryProject : registryComponents[1],
354
+ registryRepository : registryComponents[2],
349
355
  files : chartFiles,
350
356
  yaml : {
351
357
  'Chart.yaml' : chartYaml,
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * chart-to-registry will...
4
+ */
5
+ import { existsSync, rmSync } 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
+
12
+ import {
13
+ debug,
14
+ errorExit,
15
+ log,
16
+ getGitRootDirectory,
17
+ parsePackageJson,
18
+ parseHelmChart,
19
+ shellCmd } from './Utils.mjs'
20
+
21
+ const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
22
+ /* eslint-disable max-len */
23
+ {
24
+ name : 'location',
25
+ type : String,
26
+ defaultValue : 'us-docker.pkg.dev',
27
+ description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
28
+ },
29
+ {
30
+ name : 'project',
31
+ type : String,
32
+ defaultValue : process.env.HELM_CHART_REGISTRY || 'leverege-registry',
33
+ description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
34
+ },
35
+ {
36
+ name : 'repository',
37
+ type : String,
38
+ description : '{green the target repository to receive the pushed chart}',
39
+ },
40
+ {
41
+ name : 'help',
42
+ type : Boolean,
43
+ description : '{green display this help screen}',
44
+ },
45
+ /* eslint-enable max-len */
46
+ ]
47
+
48
+ const sections = [
49
+ {
50
+ header : 'Leverege Helm Chart Location Tool',
51
+ content : `{green A tool for locating helm charts in registries. It was created to allow
52
+ the helmup.sh bash script to easily locate charts, which may be in the
53
+ chart museum, La everge artifact-registry project or a 3rd party
54
+ developer\'s artifact-registry.}`
55
+ },
56
+ { header : 'Options',
57
+ optionList : commandLineOptions,
58
+ },
59
+ ]
60
+
61
+ const args = commandLineArgs( commandLineOptions, { camelCase : true, partial : true } )
62
+ const usage = commandLineUsage( sections )
63
+
64
+ if ( args.help ) {
65
+ log( usage )
66
+ process.exit( 0 )
67
+ }
68
+
69
+ /* eslint-disable no-underscore-dangle */
70
+ if ( args._unknown ) {
71
+ log( usage )
72
+ log( `\nUnrecognized argument [${chalk.bold.red( args._unknown )}]\n` )
73
+ process.exit( 1 )
74
+ }
75
+ /* eslint-enable no-underscore-dangle */
76
+
77
+ const minNodejsVersion = '18.0.0'
78
+ if ( semverLt( process.version, minNodejsVersion ) ) {
79
+ errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
80
+ }
81
+
@@ -21,16 +21,16 @@ import {
21
21
  const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
22
22
  /* eslint-disable max-len */
23
23
  {
24
- name : 'project',
24
+ name : 'location',
25
25
  type : String,
26
- defaultValue : process.env.HELM_CHART_REGISTRY || 'leverege-registry',
27
- description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
26
+ defaultValue : 'us-docker.pkg.dev',
27
+ description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
28
28
  },
29
29
  {
30
- name : 'region',
30
+ name : 'project',
31
31
  type : String,
32
- defaultValue : 'us-docker.pkg.dev',
33
- description : '{green the region of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
32
+ defaultValue : process.env.HELM_CHART_REGISTRY || 'leverege-registry',
33
+ description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
34
34
  },
35
35
  {
36
36
  name : 'repository',
@@ -49,7 +49,7 @@ const sections = [
49
49
  {
50
50
  header : 'Leverege Helm Chart to Artifact Registry',
51
51
  content : `{green This tool helps ...
52
- ... multi-line helm.}`
52
+ ... multi-line help.}`
53
53
  },
54
54
  { header : 'Options',
55
55
  optionList : commandLineOptions,
@@ -85,7 +85,7 @@ try {
85
85
  const accessToken = await shellCmd( 'gcloud auth print-access-token' )
86
86
  const registryLoginCommand = `helm registry login -u oauth2accesstoken -p ${accessToken}`
87
87
 
88
- const loginResult = await shellCmd( `${registryLoginCommand} https://${args.region}` ) // TODO: cmd line param
88
+ const loginResult = await shellCmd( `${registryLoginCommand} https://${args.location}` ) // TODO: cmd line param
89
89
  debug( { loginResult }, '<==registryLogin' )
90
90
  } catch ( error ) {
91
91
  errorExit( error )
@@ -117,9 +117,12 @@ try {
117
117
 
118
118
  debug( { packageJson, helmChart }, '<==Parsed package and chart' )
119
119
 
120
- // helm push helm-package.tgz oci://REGISTRY_NAME/REPOSITORY_NAME/charts/SERVICE
120
+ // helm push helm-package.tgz oci://REGISTRY_LOCATION/REGISTRY_PROJECT/REGISTRY_REPOSITORY/charts
121
121
  //
122
- const ociPushEndpoint = `oci://${args.region}/${args.project}/${args.repository}/charts`
122
+ const registryLocation = args.location || helmChart.registryLocation
123
+ const registryProject = args.project || helmChart.registryProject
124
+ const registryRepository = args.repository || helmChart.registryRepository
125
+ const ociPushEndpoint = `oci://${registryLocation}/${registryProject}/${registryRepository}/charts`
123
126
 
124
127
  try {
125
128
  await shellCmd( 'helm package helm' )