@leverege/build-tools 2.43.6 → 2.43.7
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 +3 -3
- package/src/Utils.mjs +111 -8
- package/src/bash-funcs +1 -0
- package/src/chart-to-registry.mjs +55 -18
- package/src/dirty-git.sh +9 -4
- package/src/helm-charts/grafana/helmup.plugin +1 -1
- package/src/helm-charts/overdose/values-local.yaml +18 -0
- package/src/helm-charts/redis/helmup.plugin +4 -5
- package/src/helm-charts/traefik/helmup.plugin +1 -1
- package/src/helmup.sh +2 -0
- package/src/pkgck.sh +1 -1
- package/src/send-to-slack.mjs +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.43.
|
|
3
|
+
"version": "2.43.7",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"ms": "^2.1.3",
|
|
65
65
|
"npm-registry-fetch": "^16.1.0",
|
|
66
66
|
"parse-gitignore": "^2.0.0",
|
|
67
|
-
"read-pkg": "^
|
|
67
|
+
"read-pkg": "^9.0.0",
|
|
68
68
|
"readline-sync": "^1.4.10",
|
|
69
69
|
"semver": "^7.5.4",
|
|
70
70
|
"simple-git": "^3.20.0",
|
|
@@ -72,6 +72,6 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@leverege/eslint-config-leverege": "^4.2.0",
|
|
75
|
-
"npm": "^10.2.
|
|
75
|
+
"npm": "^10.2.3"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/Utils.mjs
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
|
|
1
3
|
import chalk from 'chalk'
|
|
2
4
|
import { $ } from 'execa'
|
|
5
|
+
import YAML from 'js-yaml'
|
|
3
6
|
|
|
4
7
|
const debugEnabled = process.env.BUILD_TOOLS_DEBUG === '1'
|
|
5
8
|
|
|
6
9
|
/* eslint-disable no-console */
|
|
7
10
|
export const err = console.error
|
|
8
11
|
export const log = console.log
|
|
12
|
+
export const condir = ( obj, text = '' ) => {
|
|
13
|
+
console.log( `${chalk.yellow( '\n***DEBUG:' )} ${chalk.green( text )}` )
|
|
14
|
+
console.dir(
|
|
15
|
+
{ obj, },
|
|
16
|
+
{ depth : 8, colors : true },
|
|
17
|
+
)
|
|
18
|
+
}
|
|
9
19
|
export const debug = ( obj, text ) => {
|
|
10
|
-
if ( debugEnabled ) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{ depth : 8, colors : true }, )
|
|
16
|
-
}
|
|
20
|
+
if ( debugEnabled ) { condir( obj, text ) }
|
|
21
|
+
}
|
|
22
|
+
export const errorExit = ( error, opts = { errorCode : 1 } ) => {
|
|
23
|
+
console.error( `\n${chalk.red.bold( error )}\n` )
|
|
24
|
+
if ( opts?.errorCode ) { process.exit( opts.errorCode ) }
|
|
17
25
|
}
|
|
18
26
|
/* eslint-enable no-console */
|
|
19
27
|
|
|
@@ -30,7 +38,102 @@ export const shellCmd = async ( cmdstr, opts = {} ) => {
|
|
|
30
38
|
|
|
31
39
|
return results.stdout
|
|
32
40
|
} catch ( error ) {
|
|
33
|
-
debug( { error } )
|
|
41
|
+
debug( { error }, '<==shellCmd' )
|
|
42
|
+
throw error
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const getGcpSecret = async ( gcpProject, secretName, opts ) => {
|
|
47
|
+
const secretFetchCmd = `gcloud secrets versions access latest --project=${gcpProject} --secret=${secretName}`
|
|
48
|
+
let secretString
|
|
49
|
+
try {
|
|
50
|
+
secretString = await shellCmd( secretFetchCmd )
|
|
51
|
+
} catch ( error ) {
|
|
52
|
+
debug( { error }, '<==getGcpSecret' )
|
|
53
|
+
throw error
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if ( !opts?.isJSON ) { return secretString }
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const secretJSON = JSON.parse( secretString )
|
|
60
|
+
return secretJSON
|
|
61
|
+
} catch ( error ) {
|
|
62
|
+
debug( { error }, '<==getGcpSecret JSON.parse' )
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const getGitRootDirectory = async () => {
|
|
68
|
+
try {
|
|
69
|
+
const gitRoot = await shellCmd( 'git rev-parse --show-toplevel' )
|
|
70
|
+
debug( { gitRoot }, '<==getGitRootDirectory' )
|
|
71
|
+
return gitRoot
|
|
72
|
+
} catch ( error ) {
|
|
73
|
+
debug( { error }, '<==getGitRootDirectory' )
|
|
34
74
|
throw error
|
|
35
75
|
}
|
|
36
76
|
}
|
|
77
|
+
|
|
78
|
+
export const parseJsonFile = async ( jsonFile ) => {
|
|
79
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
80
|
+
if ( existsSync( jsonFile ) ) {
|
|
81
|
+
try {
|
|
82
|
+
const json = JSON.parse( readFileSync( jsonFile, 'utf8' ) )
|
|
83
|
+
return json
|
|
84
|
+
} catch ( error ) {
|
|
85
|
+
throw new Error( `${error} in ${jsonFile}` )
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
throw new Error( `File ${jsonFile} does not exist` )
|
|
89
|
+
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Parses the ./package.json file and verifies there is a properly formatted
|
|
93
|
+
// leverege.registry section present.
|
|
94
|
+
export const parsePackageJson = async ( packageFileName ) => {
|
|
95
|
+
const packageJson = await parseJsonFile( packageFileName )
|
|
96
|
+
|
|
97
|
+
const leveregeClauseError = `leverege.registry statement, it should
|
|
98
|
+
resemble something like:
|
|
99
|
+
|
|
100
|
+
"leverege": {
|
|
101
|
+
"registry": "us-docker.pkg.dev/leverege-registry/<REPO NAME>"
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
`
|
|
105
|
+
|
|
106
|
+
if ( !packageJson?.leverege?.registry ) {
|
|
107
|
+
errorExit( `Error: package.json is missing a proper ${leveregeClauseError}` )
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const artifacts = packageJson.leverege.registry.split( '/' )
|
|
111
|
+
if ( artifacts.length !== 3 ) {
|
|
112
|
+
errorExit( `Error: package.json has a malformed ${leveregeClauseError}` )
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
artifactRegistry : {
|
|
117
|
+
registry : packageJson.leverege.registry,
|
|
118
|
+
region : artifacts[0],
|
|
119
|
+
project : artifacts[1],
|
|
120
|
+
repository : artifacts[2],
|
|
121
|
+
},
|
|
122
|
+
...packageJson,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const parseHelmChart = async ( helmroot ) => {
|
|
127
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
128
|
+
const chartFiles = readdirSync( helmroot, { encoding : 'utf8', recursive : true } )
|
|
129
|
+
const chartYaml = YAML.load( readFileSync( `${helmroot}/Chart.yaml`, 'utf-8' ) )
|
|
130
|
+
const valuesYaml = YAML.load( readFileSync( `${helmroot}/values.yaml`, 'utf-8' ) )
|
|
131
|
+
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
132
|
+
return ( {
|
|
133
|
+
files : chartFiles,
|
|
134
|
+
yaml : {
|
|
135
|
+
'Chart.yaml' : chartYaml,
|
|
136
|
+
'values.yaml' : valuesYaml
|
|
137
|
+
}
|
|
138
|
+
} )
|
|
139
|
+
}
|
package/src/bash-funcs
CHANGED
|
@@ -8,20 +8,37 @@ import commandLineArgs from 'command-line-args'
|
|
|
8
8
|
import commandLineUsage from 'command-line-usage'
|
|
9
9
|
import { lt as semverLt } from 'semver'
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
condir, debug,
|
|
13
|
+
errorExit,
|
|
14
|
+
log,
|
|
15
|
+
getGitRootDirectory,
|
|
16
|
+
parsePackageJson,
|
|
17
|
+
parseHelmChart,
|
|
18
|
+
shellCmd } from './Utils.mjs'
|
|
12
19
|
|
|
13
20
|
const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
|
|
14
21
|
/* eslint-disable max-len */
|
|
15
22
|
{
|
|
16
23
|
name : 'project',
|
|
17
24
|
type : String,
|
|
18
|
-
|
|
25
|
+
defaultValue : process.env.HELM_CHART_REGISTRY || 'leverege-registry',
|
|
19
26
|
description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
|
|
20
27
|
},
|
|
28
|
+
{
|
|
29
|
+
name : 'region',
|
|
30
|
+
type : String,
|
|
31
|
+
defaultValue : 'us-docker.pkg.dev',
|
|
32
|
+
description : '{green the region of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name : 'repository',
|
|
36
|
+
type : String,
|
|
37
|
+
description : '{green the target repository to receive the pushed chart}',
|
|
38
|
+
},
|
|
21
39
|
{
|
|
22
40
|
name : 'help',
|
|
23
41
|
type : Boolean,
|
|
24
|
-
default : false,
|
|
25
42
|
description : '{green display this help screen}',
|
|
26
43
|
},
|
|
27
44
|
/* eslint-enable max-len */
|
|
@@ -54,19 +71,12 @@ if ( args._unknown ) {
|
|
|
54
71
|
}
|
|
55
72
|
/* eslint-enable no-underscore-dangle */
|
|
56
73
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const minNodejsVersion = '18.13.0'
|
|
74
|
+
const minNodejsVersion = '18.0.0'
|
|
60
75
|
if ( semverLt( process.version, minNodejsVersion ) ) {
|
|
61
|
-
|
|
62
|
-
process.exit( 1 )
|
|
76
|
+
errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
|
|
63
77
|
}
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
return `gcloud secrets versions access latest --project=${gcpProject} --secret=${secretName}`
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
log( chalk.yellow( '\n\n***WARNING: Under Construction' ) )
|
|
79
|
+
log( { args }, chalk.yellow( '\n\n***WARNING: Under Construction' ) )
|
|
70
80
|
|
|
71
81
|
// gcloud auth print-access-token | helm registry login -u oauth2accesstoken \
|
|
72
82
|
// -p ${password} https://us-docker.pkg.dev
|
|
@@ -76,10 +86,37 @@ try {
|
|
|
76
86
|
const accessToken = await shellCmd( 'gcloud auth print-access-token' )
|
|
77
87
|
const registryLoginCommand = `helm registry login -u oauth2accesstoken -p ${accessToken}`
|
|
78
88
|
|
|
79
|
-
const loginResult = await shellCmd( `${registryLoginCommand} https
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const loginResult = await shellCmd( `${registryLoginCommand} https://${args.region}` ) // TODO: cmd line param
|
|
90
|
+
debug( { loginResult }, '<==registryLogin' )
|
|
91
|
+
} catch ( error ) {
|
|
92
|
+
errorExit( error )
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
//
|
|
95
|
+
// First of all, fail if we are not in a git repository
|
|
96
|
+
let gitRoot
|
|
97
|
+
try {
|
|
98
|
+
gitRoot = await getGitRootDirectory()
|
|
99
|
+
} catch ( error ) {
|
|
100
|
+
errorExit( chalk.red.bold( error ), { errorCode : 5 } )
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Next, parse the package.json file looking for sections of interest
|
|
104
|
+
let packageJson
|
|
105
|
+
try {
|
|
106
|
+
packageJson = await parsePackageJson( './package.json' )
|
|
107
|
+
} catch ( error ) {
|
|
108
|
+
errorExit( error )
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// And then load up the helm chart too
|
|
112
|
+
let helmChart
|
|
113
|
+
try {
|
|
114
|
+
helmChart = await parseHelmChart( `${gitRoot}/helm` )
|
|
115
|
+
} catch ( error ) {
|
|
116
|
+
errorExit( error )
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
condir( { packageJson, helmChart }, '<==Parsed package and chart' )
|
|
120
|
+
|
|
121
|
+
// helm push chart-tarball oci://REGISTRY_NAME/REPOSITORY_NAME/charts/SERVICE
|
|
122
|
+
// helm install my-release oci://REGISTRY_NAME/REPOSITORY_NAME/redis
|
package/src/dirty-git.sh
CHANGED
|
@@ -8,7 +8,6 @@ CLEAN="\e[32m✔\e[0m"
|
|
|
8
8
|
DIRTY="\e[31m✘\e[0m"
|
|
9
9
|
STASH="\e[33;44m$\e[0m"
|
|
10
10
|
AHEAD="\e[34;42m!\e[0m"
|
|
11
|
-
#NOHED="\e[31m✖\e[0m"
|
|
12
11
|
NOHED="\e[31;43m⚑\e[0m"
|
|
13
12
|
LOCKD="\e[35m\e[0m"
|
|
14
13
|
ELAS7="\e[33m7\e[0m"
|
|
@@ -23,12 +22,18 @@ do
|
|
|
23
22
|
[[ `git status --porcelain` ]] && status="$DIRTY" || status="$CLEAN"
|
|
24
23
|
scount=`git stash list | wc -l`
|
|
25
24
|
[ $scount -gt 0 ] && stash="\e[33;44m$\e[0m" || stash=" "
|
|
26
|
-
ahead=`git rev-
|
|
27
|
-
if [ -
|
|
25
|
+
ahead=`git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null` # check on remote first
|
|
26
|
+
if [ $? -gt 0 ];
|
|
28
27
|
then
|
|
29
28
|
ahead="$NOHED" # "✖" # "❓"
|
|
30
29
|
else
|
|
31
|
-
|
|
30
|
+
ahead=`git rev-list FETCH_HEAD..HEAD --count 2>/dev/null`
|
|
31
|
+
if [ -z "$ahead" ];
|
|
32
|
+
then
|
|
33
|
+
ahead="$NOHED" # "✖" # "❓"
|
|
34
|
+
else
|
|
35
|
+
[ $ahead -gt 0 ] && ahead="$AHEAD" || ahead=" "
|
|
36
|
+
fi
|
|
32
37
|
fi
|
|
33
38
|
[ -f "Versions.json" ] && locked="$LOCKD" || locked=" "
|
|
34
39
|
[ ! -d "elasticsearch8" ] && elastic="$ELAS7" || elastic=" "
|
|
@@ -4,7 +4,7 @@ showInstalling "Grafana"
|
|
|
4
4
|
|
|
5
5
|
addHelmRepo grafana https://grafana.github.io/helm-charts
|
|
6
6
|
|
|
7
|
-
[ -z "$GRAFANA_CHART_VERSION" ] && GRAFANA_CHART_VERSION="
|
|
7
|
+
[ -z "$GRAFANA_CHART_VERSION" ] && GRAFANA_CHART_VERSION="7"
|
|
8
8
|
helm upgrade --install grafana grafana/grafana \
|
|
9
9
|
--namespace monitoring --create-namespace \
|
|
10
10
|
--values grafana/grafana-local.yaml \
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
image:
|
|
2
|
+
tag: # 1.2.1
|
|
3
|
+
|
|
4
|
+
config:
|
|
5
|
+
LOG_CONFIG: '{"type":"pino","level":"info"}'
|
|
6
|
+
|
|
7
|
+
resources:
|
|
8
|
+
limits:
|
|
9
|
+
cpu: 500m
|
|
10
|
+
memory: 1024Mi
|
|
11
|
+
requests:
|
|
12
|
+
cpu: 500m
|
|
13
|
+
memory: 1024Mi
|
|
14
|
+
|
|
15
|
+
autoscaling:
|
|
16
|
+
minReplicas: 6
|
|
17
|
+
maxReplicas: 16
|
|
18
|
+
averageCPU: 75
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
showInstalling "Redis"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
OCI_CHART="oci://registry-1.docker.io/bitnamicharts/redis"
|
|
6
6
|
|
|
7
|
-
[ -z "$REDIS_CHART_VERSION" ] && REDIS_CHART_VERSION="18"
|
|
8
|
-
|
|
7
|
+
[ -z "$REDIS_CHART_VERSION" ] && REDIS_CHART_VERSION="18.3.1"
|
|
8
|
+
|
|
9
|
+
helm upgrade --install redis $OCI_CHART \
|
|
9
10
|
--values redis/redis-local.yaml \
|
|
10
11
|
--version $REDIS_CHART_VERSION $HELM_WHAT
|
|
11
|
-
|
|
12
|
-
removeHelmRepo bitnami
|
|
@@ -6,7 +6,7 @@ TRAEFIK_NAMESPACE="traefik"
|
|
|
6
6
|
|
|
7
7
|
addHelmRepo traefik https://helm.traefik.io/traefik
|
|
8
8
|
|
|
9
|
-
[ -z "$TRAEFIK_CHART_VERSION" ] && TRAEFIK_CHART_VERSION="
|
|
9
|
+
[ -z "$TRAEFIK_CHART_VERSION" ] && TRAEFIK_CHART_VERSION="25"
|
|
10
10
|
helm upgrade --install traefik traefik/traefik \
|
|
11
11
|
--namespace $TRAEFIK_NAMESPACE --create-namespace \
|
|
12
12
|
--values traefik/traefik-local.yaml \
|
package/src/helmup.sh
CHANGED
package/src/pkgck.sh
CHANGED
|
@@ -54,7 +54,7 @@ check_eslint () {
|
|
|
54
54
|
|
|
55
55
|
check_license () {
|
|
56
56
|
local C_stat=$(meh)
|
|
57
|
-
local lic="`node -p \"require('./package.json').scripts.licenseCheck
|
|
57
|
+
local lic="`node -p \"require('./package.json').scripts.licenseCheck == undefined\"`"
|
|
58
58
|
[ $lic == true ] && C_stat=$(good)
|
|
59
59
|
printf $C_stat
|
|
60
60
|
}
|
package/src/send-to-slack.mjs
CHANGED
|
@@ -42,7 +42,6 @@ const slackSendOptions = [ // Use slackSendOptions to tie into the Usage stateme
|
|
|
42
42
|
default : false,
|
|
43
43
|
description : '{green display this help screen}',
|
|
44
44
|
},
|
|
45
|
-
/* eslint-enable max-len */
|
|
46
45
|
]
|
|
47
46
|
|
|
48
47
|
const sections = [
|
|
@@ -100,14 +99,14 @@ try {
|
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
// slack out the details to the configured channel
|
|
103
|
-
const account = await shellCmd( 'gcloud config get account' )
|
|
104
102
|
const slackData = {
|
|
105
|
-
text : args.message.replace(
|
|
103
|
+
text : args.message.replace( /^"|"$/g, '' ), // strip pesky leading/trailing "
|
|
106
104
|
channel : slackConfig.channel,
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
if ( process.env.BUILD_TOOLS_DEBUG || args.dryRun ) {
|
|
110
|
-
|
|
108
|
+
const account = await shellCmd( 'gcloud config get account' )
|
|
109
|
+
log( { account, slackConfig, slackData }, '<==Slack skipped' )
|
|
111
110
|
} else {
|
|
112
111
|
try {
|
|
113
112
|
const fetchStatus = await fetch( slackConfig.url, {
|