@leverege/build-tools 2.48.1 → 2.48.3
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 +1 -1
- package/src/Utils.mjs +7 -1
- package/src/chart-compass.mjs +81 -0
- package/src/chart-to-registry.mjs +42 -25
package/package.json
CHANGED
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
|
+
registryLocation : 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,19 @@ import {
|
|
|
21
21
|
const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
|
|
22
22
|
/* eslint-disable max-len */
|
|
23
23
|
{
|
|
24
|
-
name : '
|
|
24
|
+
name : 'dry-run',
|
|
25
|
+
type : Boolean,
|
|
26
|
+
description : '{green perform everything except the actuall chart push}',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name : 'location',
|
|
25
30
|
type : String,
|
|
26
|
-
|
|
27
|
-
description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
|
|
31
|
+
description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
|
|
28
32
|
},
|
|
29
33
|
{
|
|
30
|
-
name : '
|
|
34
|
+
name : 'project',
|
|
31
35
|
type : String,
|
|
32
|
-
|
|
33
|
-
description : '{green the region of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
|
|
36
|
+
description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
|
|
34
37
|
},
|
|
35
38
|
{
|
|
36
39
|
name : 'repository',
|
|
@@ -49,7 +52,7 @@ const sections = [
|
|
|
49
52
|
{
|
|
50
53
|
header : 'Leverege Helm Chart to Artifact Registry',
|
|
51
54
|
content : `{green This tool helps ...
|
|
52
|
-
... multi-line
|
|
55
|
+
... multi-line help.}`
|
|
53
56
|
},
|
|
54
57
|
{ header : 'Options',
|
|
55
58
|
optionList : commandLineOptions,
|
|
@@ -77,20 +80,6 @@ if ( semverLt( process.version, minNodejsVersion ) ) {
|
|
|
77
80
|
errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
// gcloud auth print-access-token | helm registry login -u oauth2accesstoken \
|
|
81
|
-
// -p ${password} https://us-docker.pkg.dev
|
|
82
|
-
//
|
|
83
|
-
// Get the current access token and use it to login to the registry with helm.
|
|
84
|
-
try {
|
|
85
|
-
const accessToken = await shellCmd( 'gcloud auth print-access-token' )
|
|
86
|
-
const registryLoginCommand = `helm registry login -u oauth2accesstoken -p ${accessToken}`
|
|
87
|
-
|
|
88
|
-
const loginResult = await shellCmd( `${registryLoginCommand} https://${args.region}` ) // TODO: cmd line param
|
|
89
|
-
debug( { loginResult }, '<==registryLogin' )
|
|
90
|
-
} catch ( error ) {
|
|
91
|
-
errorExit( error )
|
|
92
|
-
}
|
|
93
|
-
|
|
94
83
|
// First of all, fail if we are not in a git repository
|
|
95
84
|
let gitRoot
|
|
96
85
|
try {
|
|
@@ -115,11 +104,34 @@ try {
|
|
|
115
104
|
errorExit( error )
|
|
116
105
|
}
|
|
117
106
|
|
|
118
|
-
|
|
107
|
+
// helm push helm-package.tgz oci://REGISTRY_LOCATION/REGISTRY_PROJECT/REGISTRY_REPOSITORY/charts
|
|
108
|
+
//
|
|
109
|
+
const registryLocation = args.location || helmChart.registryLocation
|
|
110
|
+
const registryProject = args.project || helmChart.registryProject
|
|
111
|
+
const registryRepository = args.repository || helmChart.registryRepository
|
|
112
|
+
const ociPushEndpoint = `oci://${registryLocation}/${registryProject}/${registryRepository}/charts`
|
|
113
|
+
|
|
114
|
+
debug( {
|
|
115
|
+
packageJson,
|
|
116
|
+
helmChart,
|
|
117
|
+
registryLocation,
|
|
118
|
+
registryProject,
|
|
119
|
+
registryRepository,
|
|
120
|
+
ociPushEndpoint }, '<==Parsed package and chart' )
|
|
119
121
|
|
|
120
|
-
// helm
|
|
122
|
+
// gcloud auth print-access-token | helm registry login -u oauth2accesstoken \
|
|
123
|
+
// -p ${password} https://us-docker.pkg.dev
|
|
121
124
|
//
|
|
122
|
-
|
|
125
|
+
// Get the current access token and use it to login to the registry with helm.
|
|
126
|
+
try {
|
|
127
|
+
const accessToken = await shellCmd( 'gcloud auth print-access-token' )
|
|
128
|
+
const registryLoginCommand = `echo ${accessToken} | helm registry login --username oauth2accesstoken --password-stdin`
|
|
129
|
+
|
|
130
|
+
const loginResult = await shellCmd( `${registryLoginCommand} https://${registryLocation}` ) // TODO: cmd line param
|
|
131
|
+
debug( { loginResult }, '<==registryLogin' )
|
|
132
|
+
} catch ( error ) {
|
|
133
|
+
errorExit( error )
|
|
134
|
+
}
|
|
123
135
|
|
|
124
136
|
try {
|
|
125
137
|
await shellCmd( 'helm package helm' )
|
|
@@ -129,7 +141,12 @@ try {
|
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
log( `\nPushing ${chalk.green.bold( chartPackage )} => ${chalk.green.bold( ociPushEndpoint )}` )
|
|
132
|
-
|
|
144
|
+
const pushItRealGood = `helm push ${chartPackage} ${ociPushEndpoint}`
|
|
145
|
+
if ( !args.dryRun ) {
|
|
146
|
+
await shellCmd( pushItRealGood )
|
|
147
|
+
} else {
|
|
148
|
+
log( `\nDry run => ${chalk.green.bold( pushItRealGood )}` )
|
|
149
|
+
}
|
|
133
150
|
rmSync( chartPackage )
|
|
134
151
|
} catch ( err ) {
|
|
135
152
|
errorExit( err )
|