@leverege/build-tools 2.52.0-beta.1 → 2.52.0-pedro.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 +8 -6
- package/src/Docker.mjs +12 -53
- package/src/Utils.mjs +1 -1
- package/src/build-tools.mjs +5 -4
- package/src/docker-to-registry.mjs +27 -43
- package/src/firebaseDeploy.mjs +1 -0
- package/src/firebaseServe.mjs +2 -3
- package/src/helm-charts/api-server/values-local.yaml +0 -11
- package/src/helm-charts/cnpg-db-psql-stack/helmup.plugin +0 -3
- package/src/helm-charts/cnpg-db-tsdb-basic/helmup.plugin +1 -4
- package/src/helm-charts/cnpg-db-tsdb-dense/helmup.plugin +1 -4
- package/src/helm-charts/elasticsearch8/helmup.plugin +1 -1
- package/src/helm-charts/redis/helmup.plugin +1 -1
- package/src/helmdn.sh +1 -0
- package/src/helmup.sh +7 -25
- package/src/refresh-py-idx-sa.sh +89 -0
- package/src/refresh-py-idx.sh +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.52.0-
|
|
3
|
+
"version": "2.52.0-pedro.1",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"pull-git": "src/pull-git.sh",
|
|
48
48
|
"push-my-chart": "src/push-my-chart.mjs",
|
|
49
49
|
"refresh-npm-token": "src/refresh-npm-token.mjs",
|
|
50
|
+
"refresh-py-idx-sa": "src/refresh-py-idx-sa.sh",
|
|
51
|
+
"refresh-py-idx": "src/refresh-py-idx.sh",
|
|
50
52
|
"send-to-slack": "src/send-to-slack.mjs",
|
|
51
53
|
"tag-release": "src/tag-release.mjs",
|
|
52
54
|
"unleash": "src/unleash.mjs"
|
|
@@ -61,10 +63,10 @@
|
|
|
61
63
|
"command-line-usage": "^7.0.3",
|
|
62
64
|
"deepmerge": "^4.3.1",
|
|
63
65
|
"enquirer": "^2.4.1",
|
|
64
|
-
"execa": "^9.
|
|
66
|
+
"execa": "^9.3.1",
|
|
65
67
|
"glob": "^11.0.0",
|
|
66
68
|
"handlebars": "^4.7.8",
|
|
67
|
-
"inquirer": "^
|
|
69
|
+
"inquirer": "^10.2.2",
|
|
68
70
|
"js-yaml": "^4.1.0",
|
|
69
71
|
"ms": "^2.1.3",
|
|
70
72
|
"npm-registry-fetch": "^17.1.0",
|
|
@@ -73,11 +75,11 @@
|
|
|
73
75
|
"read-pkg": "^9.0.1",
|
|
74
76
|
"readline-sync": "^1.4.10",
|
|
75
77
|
"semver": "^7.6.3",
|
|
76
|
-
"simple-git": "^3.
|
|
77
|
-
"zx": "^8.1.
|
|
78
|
+
"simple-git": "^3.26.0",
|
|
79
|
+
"zx": "^8.1.6"
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
82
|
"@leverege/eslint-config-leverege": "^4.2.0",
|
|
81
83
|
"npm": "^10.8.3"
|
|
82
84
|
}
|
|
83
|
-
}
|
|
85
|
+
}
|
package/src/Docker.mjs
CHANGED
|
@@ -40,12 +40,8 @@ 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
|
-
|
|
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}} && \
|
|
43
|
+
npm install -g npm@10 && \
|
|
44
|
+
npm ci --only=production --ignore-scripts --no-optional {{npmlogging}} && \
|
|
49
45
|
rm -f /usr/src/app/.npmrc /root/.ssh/*
|
|
50
46
|
|
|
51
47
|
# --------------------------------------------------------------
|
|
@@ -71,7 +67,7 @@ COPY --chown=node:node --from=intermediate /usr/src/app /usr/src/app
|
|
|
71
67
|
|
|
72
68
|
USER {{runuser}}
|
|
73
69
|
COPY ./bashrc /home/node/.bashrc
|
|
74
|
-
CMD [ "/bin/bash", "-c", "
|
|
70
|
+
CMD [ "/bin/bash", "-c", "node index.js" ]`
|
|
75
71
|
|
|
76
72
|
const pluginTemplate = `
|
|
77
73
|
# Dockerfile.plugin - optionally extend the service Docker image
|
|
@@ -136,19 +132,6 @@ dunm() {
|
|
|
136
132
|
du -sh /usr/src/app/node_modules/* | sort -sh
|
|
137
133
|
}
|
|
138
134
|
`
|
|
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
|
-
`
|
|
152
135
|
|
|
153
136
|
const defaultSettings = {
|
|
154
137
|
apkadds : '',
|
|
@@ -156,7 +139,6 @@ const defaultSettings = {
|
|
|
156
139
|
nodeimage : 'iron-alpine',
|
|
157
140
|
npmlogging : '--silent',
|
|
158
141
|
pluginfile : '# NO PLUGIN',
|
|
159
|
-
preInstallPluginfile : '# NO PRE-INSTALL PLUGIN',
|
|
160
142
|
regvers : 'package.version',
|
|
161
143
|
runuser : 'node',
|
|
162
144
|
}
|
|
@@ -186,14 +168,8 @@ const generateDockerfile = ( settings = defaultSettings ) => {
|
|
|
186
168
|
|
|
187
169
|
const bashrcFile = './docker/bashrc'
|
|
188
170
|
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
|
-
}
|
|
195
171
|
warning( `creating the missing ${bashrcFile} file in the docker directory` )
|
|
196
|
-
fs.writeFileSync( bashrcFile,
|
|
172
|
+
fs.writeFileSync( bashrcFile, bashrcTemplate )
|
|
197
173
|
}
|
|
198
174
|
|
|
199
175
|
const dockerfilePlugin = './docker/Dockerfile.plugin'
|
|
@@ -218,12 +194,7 @@ const generateDockerfile = ( settings = defaultSettings ) => {
|
|
|
218
194
|
errorExit( `***ERROR: something went wrong with ${dockerfilePlugin} plugin creation` )
|
|
219
195
|
}
|
|
220
196
|
|
|
221
|
-
const
|
|
222
|
-
if ( fs.existsSync( dockerfilePrePlugin ) ) {
|
|
223
|
-
defaultSettings.preInstallPluginfile = fs.readFileSync( dockerfilePrePlugin )
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const compiled = handlebars.compile( dockerfileTemplate, { noEscape : true } )
|
|
197
|
+
const compiled = handlebars.compile( dockerfileTemplate )
|
|
227
198
|
const replaced = compiled( settings )
|
|
228
199
|
// temporarily write the Dockerfile to the docker subdir - the container
|
|
229
200
|
// image builder will then move it over to the build subdir
|
|
@@ -255,10 +226,8 @@ const validateCloudBuildBucket = async ( artifactProject ) => {
|
|
|
255
226
|
}
|
|
256
227
|
|
|
257
228
|
const buildContainerImage = async ( {
|
|
258
|
-
artifactProject, artifactRegistry, containerName,
|
|
259
|
-
imageVersion, isNpmWorkspace, options
|
|
229
|
+
artifactProject, artifactRegistry, containerName, imageVersion, isNpmWorkspace,
|
|
260
230
|
} ) => {
|
|
261
|
-
const { useCloudBuildFile } = options || {}
|
|
262
231
|
const buildWorkspace = './build/workspace' // passed to Cloud Build
|
|
263
232
|
const imageName = `${artifactRegistry}/images/${containerName}`
|
|
264
233
|
|
|
@@ -287,24 +256,14 @@ const buildContainerImage = async ( {
|
|
|
287
256
|
const { fullName : builderName } = await getGcpAccount()
|
|
288
257
|
const gcloudBuild = `time gcloud builds submit --project ${artifactProject}`
|
|
289
258
|
const gcloudLogs = `--gcs-log-dir ${formCloudBuildBucketName( artifactProject )}/log`
|
|
290
|
-
|
|
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
|
-
}
|
|
259
|
+
const gcloudTags = `--tag ${imageName}:${imageVersion}`
|
|
300
260
|
|
|
301
261
|
log( chalk.green.bold( `
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
262
|
+
*** Submitting Build as ${builderName} ***
|
|
263
|
+
${gcloudBuild} \\
|
|
264
|
+
${gcloudLogs} \\
|
|
265
|
+
${gcloudTags}
|
|
266
|
+
` ) )
|
|
308
267
|
|
|
309
268
|
if ( process.env.DRY_RUN === '1' ) {
|
|
310
269
|
log( '\n***Exiting from DRY_RUN\n' )
|
package/src/Utils.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import YAML from 'js-yaml'
|
|
|
9
9
|
|
|
10
10
|
let debugEnabled = process.env.BUILD_TOOLS_DEBUG === '1'
|
|
11
11
|
|
|
12
|
-
export const disableDebug = () =>
|
|
12
|
+
export const disableDebug = () => debugEnabled = false
|
|
13
13
|
|
|
14
14
|
/* eslint-disable no-console */
|
|
15
15
|
export const err = console.error
|
package/src/build-tools.mjs
CHANGED
|
@@ -135,10 +135,11 @@ const checkAndAnnounce = () => {
|
|
|
135
135
|
checkForLatest()
|
|
136
136
|
.then( ( latestVersion ) => {
|
|
137
137
|
if ( semverLt( thisVersion, latestVersion ) ) {
|
|
138
|
-
console.log( chalk.white
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
console.log( chalk.white`
|
|
139
|
+
Update available ${chalk.grey( thisVersion )} \u2b62 ${chalk.green( latestVersion )}
|
|
140
|
+
Run ${chalk.cyan( 'npm i -g @leverege/build-tools' )} to update
|
|
141
|
+
`
|
|
142
|
+
)
|
|
142
143
|
process.exit( 1 )
|
|
143
144
|
} else {
|
|
144
145
|
process.exit( 0 )
|
|
@@ -26,22 +26,8 @@ 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
|
|
31
29
|
// Expected to be invoked like docker-to-registry v1.2.3
|
|
32
|
-
|
|
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
|
-
}
|
|
30
|
+
const imageVersion = process.argv[2]
|
|
45
31
|
if ( !imageVersion ) {
|
|
46
32
|
errorExit( '***Error: docker-to-registry requires an image version' )
|
|
47
33
|
}
|
|
@@ -165,41 +151,39 @@ if ( giveGuidance ) {
|
|
|
165
151
|
}
|
|
166
152
|
|
|
167
153
|
// do chart checks too
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const expectedChartRegistry = `${artifactRegistry}/images`
|
|
172
|
-
|
|
173
|
-
if ( expectedChartRegistry !== values.image?.registry ) {
|
|
174
|
-
log( `
|
|
175
|
-
${chalk.red.bold( '***Error: mismatched package.json registry and helm/values.yaml' )}
|
|
154
|
+
const chart = helmChart?.yaml['Chart.yaml']
|
|
155
|
+
const values = helmChart?.yaml['values.yaml']
|
|
156
|
+
const expectedChartRegistry = `${artifactRegistry}/images`
|
|
176
157
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
stored as the image.registry in the helm/values.yaml file.
|
|
158
|
+
if ( expectedChartRegistry !== values.image?.registry ) {
|
|
159
|
+
log( `
|
|
160
|
+
${chalk.red.bold( '***Error: mismatched package.json registry and helm/values.yaml' )}
|
|
181
161
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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.
|
|
185
166
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
Current settings:
|
|
168
|
+
package.json registry => ${chalk.yellow.bold( artifactRegistry )}
|
|
169
|
+
values.yaml registry => ${chalk.red.bold( values.image?.registry )}
|
|
189
170
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
171
|
+
Expected settings:
|
|
172
|
+
values.yaml registry => ${chalk.green.bold( expectedChartRegistry )}
|
|
173
|
+
` )
|
|
193
174
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
175
|
+
if ( !values.image ) {
|
|
176
|
+
log( `
|
|
177
|
+
${chalk.yellow.bold( '***DEPRECATED: legacy helm charts detected' )}
|
|
197
178
|
|
|
198
|
-
|
|
199
|
-
|
|
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.
|
|
200
182
|
|
|
201
|
-
|
|
183
|
+
` )
|
|
202
184
|
}
|
|
185
|
+
|
|
186
|
+
process.exit( 1 )
|
|
203
187
|
}
|
|
204
188
|
|
|
205
189
|
// Give the summary and the user a chance to proceed or not
|
|
@@ -272,7 +256,7 @@ if ( isNpmWorkspace ) {
|
|
|
272
256
|
await shellCmd( 'npm install --package-lock-only --workspaces false', { stdio : 'inherit' } )
|
|
273
257
|
}
|
|
274
258
|
|
|
275
|
-
await docker.buildContainerImage( {
|
|
259
|
+
await docker.buildContainerImage( { artifactProject, artifactRegistry, containerName, imageVersion, isNpmWorkspace } )
|
|
276
260
|
|
|
277
261
|
if ( willGitTag ) {
|
|
278
262
|
const tagDescription = `docker_${imageVersion}`
|
package/src/firebaseDeploy.mjs
CHANGED
|
@@ -213,6 +213,7 @@ try {
|
|
|
213
213
|
const hostingPrefix = CHANNEL ? '' : 'hosting:'
|
|
214
214
|
|
|
215
215
|
await $( { ac } )`npm run clean && DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} npm run build && firebase use ${TARGET.projectId} && firebase ${deployType} --only ${hostingPrefix}${TARGET.siteId}`
|
|
216
|
+
.pipe( process.stdout )
|
|
216
217
|
} catch ( err ) {
|
|
217
218
|
console.error( err )
|
|
218
219
|
}
|
package/src/firebaseServe.mjs
CHANGED
|
@@ -130,9 +130,8 @@ const ac = new AbortController()
|
|
|
130
130
|
|
|
131
131
|
EXIT_EVENTS
|
|
132
132
|
.forEach( ( event ) => {
|
|
133
|
-
process.on( event, (
|
|
133
|
+
process.on( event, () => {
|
|
134
134
|
if ( !exited ) {
|
|
135
|
-
console.error( d )
|
|
136
135
|
exited = true
|
|
137
136
|
fs.removeSync( path.join( process.cwd(), '.env.temp' ) )
|
|
138
137
|
ac.abort()
|
|
@@ -143,7 +142,7 @@ EXIT_EVENTS
|
|
|
143
142
|
await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
|
|
144
143
|
|
|
145
144
|
try {
|
|
146
|
-
await $( { ac } )`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} npm run serve --colors
|
|
145
|
+
await $( { ac } )`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} DEPLOYMENT_TARGET=${TARGET.siteId} npm run serve --colors`.pipe( process.stdout )
|
|
147
146
|
} catch ( err ) {
|
|
148
147
|
console.error( err )
|
|
149
148
|
}
|
|
@@ -17,17 +17,6 @@ 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
|
-
|
|
31
20
|
autoscaling:
|
|
32
21
|
minReplicas: 3
|
|
33
22
|
maxReplicas: 12
|
|
@@ -4,7 +4,7 @@ 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="20.
|
|
7
|
+
[ -z "$REDIS_CHART_VERSION" ] && REDIS_CHART_VERSION="20.0.5"
|
|
8
8
|
|
|
9
9
|
helm upgrade --install redis $OCI_CHART \
|
|
10
10
|
--values redis/redis-local.yaml \
|
package/src/helmdn.sh
CHANGED
package/src/helmup.sh
CHANGED
|
@@ -543,15 +543,14 @@ function initializeCnpgOperand() {
|
|
|
543
543
|
local IMAGINE_PW_NAME="$CNPG_SERVICE-imagine-pw"
|
|
544
544
|
local POSTGRES_PW_NAME="$CNPG_SERVICE-postgres-pw"
|
|
545
545
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
# warnOnError $? "the `color y $IMAGINE_PW_NAME` secret may already exist"
|
|
546
|
+
printf "\nCreating imagine db password for `color g $CNPG_SERVICE`\n"
|
|
547
|
+
kubectl create secret generic -n $CNPG_NAMESPACE "$IMAGINE_PW_NAME" \
|
|
548
|
+
--from-literal=username="imagine" \
|
|
549
|
+
--from-literal=password="$(generatePassword)" &> $DEVNULL
|
|
550
|
+
warnOnError $? "the `color y $IMAGINE_PW_NAME` secret may already exist"
|
|
552
551
|
|
|
553
|
-
#
|
|
554
|
-
|
|
552
|
+
# reflect the secret to default namespace
|
|
553
|
+
reflectSecretIntoNamespaces $IMAGINE_PW_NAME $CNPG_NAMESPACE "default"
|
|
555
554
|
|
|
556
555
|
printf "\nCreating postgres db password for `color g $CNPG_SERVICE`\n"
|
|
557
556
|
kubectl create secret generic -n $CNPG_NAMESPACE "$POSTGRES_PW_NAME" \
|
|
@@ -671,23 +670,6 @@ EOSNAPSC
|
|
|
671
670
|
sleep 2 # hold up processing for a moment to allow IAM mods to propagate
|
|
672
671
|
}
|
|
673
672
|
|
|
674
|
-
function ensureCnpgSecret() {
|
|
675
|
-
local mgrSecret=$1
|
|
676
|
-
local k8sSecret=$2
|
|
677
|
-
|
|
678
|
-
service-man --from-helmup --sync-secrets ${mgrSecret}=${k8sSecret}
|
|
679
|
-
|
|
680
|
-
if [ $? -ne 0 ];
|
|
681
|
-
then
|
|
682
|
-
cat<<BAD_SECRETS
|
|
683
|
-
`color r "There appears to be a problem with one, or both of the secrets. Please
|
|
684
|
-
rectify the situation and try again."`
|
|
685
|
-
|
|
686
|
-
BAD_SECRETS
|
|
687
|
-
exit 1
|
|
688
|
-
fi
|
|
689
|
-
}
|
|
690
|
-
|
|
691
673
|
function installVeleroEnvironment() {
|
|
692
674
|
# Follows instructions => https://github.com/vmware-tanzu/velero-plugin-for-gcp
|
|
693
675
|
showInstalling "Velero Backup Management"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Description: Refreshes the service account key for the leverege-python-packages artifact registry repository and updates current configuration.
|
|
3
|
+
|
|
4
|
+
GCP_ORGANIZATION_ID=741866105355
|
|
5
|
+
GCP_PROJECT_ID=leverege-registry
|
|
6
|
+
GCP_LOCATION=us
|
|
7
|
+
|
|
8
|
+
echo "GCP Organization ID: $GCP_ORGANIZATION_ID"
|
|
9
|
+
echo "GCP Project ID: $GCP_PROJECT_ID"
|
|
10
|
+
echo "GCP Location: $GCP_LOCATION"
|
|
11
|
+
|
|
12
|
+
# Get account from gcloud core config and set everything before the @ as the name variable and replace . with -.
|
|
13
|
+
NAME=$(gcloud config get-value account | cut -d'@' -f1 | sed 's/\./-/g')
|
|
14
|
+
SERVICE_ACCOUNT_NAME="$NAME-py"
|
|
15
|
+
|
|
16
|
+
echo "GCP Service Account Name: $SERVICE_ACCOUNT_NAME"
|
|
17
|
+
echo ""
|
|
18
|
+
|
|
19
|
+
# Fetch or create service account
|
|
20
|
+
SERVICE_ACCOUNTS=$(gcloud iam service-accounts list --format="value(email)" --filter="email:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" 2>/dev/null)
|
|
21
|
+
|
|
22
|
+
# If service account does not exist, create it
|
|
23
|
+
if [ -z "$SERVICE_ACCOUNTS" ]; then
|
|
24
|
+
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME --display-name "$SERVICE_ACCOUNT_NAME"
|
|
25
|
+
echo "Service Account Created: $SERVICE_ACCOUNT_NAME"
|
|
26
|
+
echo ""
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Enable service account
|
|
30
|
+
gcloud iam service-accounts enable $SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com
|
|
31
|
+
echo "Service Account Enabled: $SERVICE_ACCOUNT_NAME"
|
|
32
|
+
echo ""
|
|
33
|
+
|
|
34
|
+
# Permission key against the leverege-python-packages artifact registry repository
|
|
35
|
+
gcloud artifacts repositories add-iam-policy-binding leverege-python-packages \
|
|
36
|
+
--location=$GCP_LOCATION \
|
|
37
|
+
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
|
|
38
|
+
--role="organizations/$GCP_ORGANIZATION_ID/roles/leveregeRegistryAccess" >/dev/null
|
|
39
|
+
echo "Service Account Permission Granted: $SERVICE_ACCOUNT_NAME"
|
|
40
|
+
echo ""
|
|
41
|
+
|
|
42
|
+
# List service account keys
|
|
43
|
+
SERVICE_ACCOUNT_KEYS=$(gcloud iam service-accounts keys list --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --format="value(name)")
|
|
44
|
+
|
|
45
|
+
# If service account keys exist, delete them
|
|
46
|
+
if [ ! -z "$SERVICE_ACCOUNT_KEYS" ]; then
|
|
47
|
+
for key in $SERVICE_ACCOUNT_KEYS; do
|
|
48
|
+
echo ""
|
|
49
|
+
gcloud iam service-accounts keys delete $key --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --quiet
|
|
50
|
+
echo "Service Account Key Deleted: $key"
|
|
51
|
+
done
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
echo ""
|
|
55
|
+
|
|
56
|
+
SERVICE_ACCOUNT_KEY_PATH=$HOME/.config/gcloud/$SERVICE_ACCOUNT_NAME.json
|
|
57
|
+
|
|
58
|
+
# Silence the command
|
|
59
|
+
gcloud iam service-accounts keys create $SERVICE_ACCOUNT_KEY_PATH --iam-account=$SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com
|
|
60
|
+
echo "Service Account Key Created and Saved: $SERVICE_ACCOUNT_KEY_PATH"
|
|
61
|
+
echo ""
|
|
62
|
+
|
|
63
|
+
# Encode key to base64
|
|
64
|
+
ENCODED_KEY=$(base64 -i $SERVICE_ACCOUNT_KEY_PATH -o -)
|
|
65
|
+
|
|
66
|
+
# Write to pip.conf
|
|
67
|
+
mkdir -p $HOME/.config/pip
|
|
68
|
+
cat <<EOF > $HOME/.config/pip/pip.conf
|
|
69
|
+
[global]
|
|
70
|
+
extra-index-url = https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
|
|
71
|
+
EOF
|
|
72
|
+
echo "Updated $HOME/.config/pip/pip.conf"
|
|
73
|
+
|
|
74
|
+
# Write to pypirc
|
|
75
|
+
cat <<EOF > $HOME/.pypirc
|
|
76
|
+
[distutils]
|
|
77
|
+
index-servers =
|
|
78
|
+
leverege-python-packages
|
|
79
|
+
|
|
80
|
+
[leverege-python-packages]
|
|
81
|
+
repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
|
|
82
|
+
username: _json_key_base64
|
|
83
|
+
password: $ENCODED_KEY
|
|
84
|
+
EOF
|
|
85
|
+
echo "Updated $HOME/.pypirc"
|
|
86
|
+
|
|
87
|
+
# Set UV_EXTRA_INDEX_URL env var
|
|
88
|
+
export UV_EXTRA_INDEX_URL=="https://_json_key_base64:$ENCODED_KEY@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
|
|
89
|
+
echo "Updated UV_EXTRA_INDEX_URL"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Description: Refresh service account key using gcloud cli
|
|
2
|
+
|
|
3
|
+
# SERVICE_ACCOUNT_NAME="leverege-py-index"
|
|
4
|
+
# GCP_PROJECT_ID="leverege-registry"
|
|
5
|
+
|
|
6
|
+
# TOKEN=$(gcloud auth print-access-token --impersonate-service-account $SERVICE_ACCOUNT_NAME@$GCP_PROJECT_ID.iam.gserviceaccount.com --lifetime=12h)
|
|
7
|
+
TOKEN=$(gcloud auth print-access-token)
|
|
8
|
+
|
|
9
|
+
# Write to pip.conf
|
|
10
|
+
mkdir -p $HOME/.config/pip
|
|
11
|
+
cat <<EOF > $HOME/.config/pip/pip.conf
|
|
12
|
+
[global]
|
|
13
|
+
extra-index-url = https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple/
|
|
14
|
+
EOF
|
|
15
|
+
echo "Updated $HOME/.config/pip/pip.conf"
|
|
16
|
+
|
|
17
|
+
# Write to pypirc
|
|
18
|
+
cat <<EOF > $HOME/.pypirc
|
|
19
|
+
[distutils]
|
|
20
|
+
index-servers =
|
|
21
|
+
leverege-python-packages
|
|
22
|
+
|
|
23
|
+
[leverege-python-packages]
|
|
24
|
+
repository: https://us-python.pkg.dev/leverege-registry/leverege-python-packages/
|
|
25
|
+
username: oauth2accesstoken
|
|
26
|
+
password: $TOKEN
|
|
27
|
+
EOF
|
|
28
|
+
echo "Updated $HOME/.pypirc"
|
|
29
|
+
|
|
30
|
+
# Set UV_EXTRA_INDEX_URL env var
|
|
31
|
+
export UV_EXTRA_INDEX_URL=="https://oauth2accesstoken:$TOKEN@us-python.pkg.dev/leverege-registry/leverege-python-packages/simple"
|
|
32
|
+
echo "Updated UV_EXTRA_INDEX_URL"
|