@leverege/build-tools 2.44.0 → 2.45.0-beta.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 +7 -4
- package/src/Docker.mjs +252 -0
- package/src/Utils.mjs +192 -13
- package/src/docker-to-registry.mjs +71 -0
- package/src/helm-charts/db-postgres-stack/.nohelm +0 -0
- package/src/helm-charts/db-postgres-stack/.nohelmdn +0 -0
- package/src/helm-charts/db-postgres-stack/db-postgres-stack.yaml.ovh +110 -0
- package/src/helm-charts/db-postgres-stack/gitignore +1 -0
- package/src/helm-charts/db-postgres-stack/helmdn.plugin +3 -0
- package/src/helm-charts/db-postgres-stack/helmup.plugin +3 -0
- package/src/helm-charts/redis/helmup.plugin +1 -1
- package/src/helm-charts/timescale-db/timescale-db-local.yaml +10 -10
- package/src/helm-charts/traefik/helmup.plugin +1 -1
- package/src/helmup.sh +1 -1
- package/src/k8x.sh +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.45.0-beta.2",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"decrypt-secrets": "src/decrypt-secrets.sh",
|
|
20
20
|
"dirty-git": "src/dirty-git.sh",
|
|
21
21
|
"dockreate": "src/dockreate.sh",
|
|
22
|
-
"docker-to-registry": "src/docker-to-registry.
|
|
22
|
+
"docker-to-registry": "src/docker-to-registry.mjs",
|
|
23
23
|
"encrypt-secrets": "src/encrypt-secrets.sh",
|
|
24
24
|
"firebaseDeploy": "src/firebaseDeploy.mjs",
|
|
25
25
|
"firebaseServe": "src/firebaseServe.mjs",
|
|
@@ -60,18 +60,21 @@
|
|
|
60
60
|
"enquirer": "^2.4.1",
|
|
61
61
|
"execa": "^8.0.1",
|
|
62
62
|
"glob": "^10.3.10",
|
|
63
|
+
"handlebars": "^4.7.8",
|
|
64
|
+
"inquirer": "^9.2.14",
|
|
63
65
|
"js-yaml": "^4.1.0",
|
|
64
66
|
"ms": "^2.1.3",
|
|
65
67
|
"npm-registry-fetch": "^16.1.0",
|
|
68
|
+
"package-up": "^5.0.0",
|
|
66
69
|
"parse-gitignore": "^2.0.0",
|
|
67
70
|
"read-pkg": "^9.0.1",
|
|
68
71
|
"readline-sync": "^1.4.10",
|
|
69
|
-
"semver": "^7.
|
|
72
|
+
"semver": "^7.6.0",
|
|
70
73
|
"simple-git": "^3.22.0",
|
|
71
74
|
"zx": "^7.2.3"
|
|
72
75
|
},
|
|
73
76
|
"devDependencies": {
|
|
74
77
|
"@leverege/eslint-config-leverege": "^4.2.0",
|
|
75
|
-
"npm": "^10.
|
|
78
|
+
"npm": "^10.4.0"
|
|
76
79
|
}
|
|
77
80
|
}
|
package/src/Docker.mjs
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import handlebars from 'handlebars'
|
|
5
|
+
|
|
6
|
+
import { errorExit, log, shellCmd, warning } from './Utils.mjs'
|
|
7
|
+
|
|
8
|
+
// The contents of these variables were initially located in files that live in
|
|
9
|
+
// the build-tools repository, but it just became simpler to pull the contents
|
|
10
|
+
// directly into these variables and forego the file loading.
|
|
11
|
+
//
|
|
12
|
+
const dockerfileTemplate = `
|
|
13
|
+
# Version {{regvers}} @ {{date}}
|
|
14
|
+
#
|
|
15
|
+
# The FROM directive sets the Base Image for subsequent instructions
|
|
16
|
+
FROM node:{{nodeimage}} as intermediate
|
|
17
|
+
ENV NODE_ENV production
|
|
18
|
+
|
|
19
|
+
RUN mkdir -p /usr/src/app
|
|
20
|
+
WORKDIR /usr/src/app
|
|
21
|
+
|
|
22
|
+
# Install app dependencies
|
|
23
|
+
COPY ./workspace/ /usr/src/app/
|
|
24
|
+
ENV GRPC_VERBOSITY ERROR
|
|
25
|
+
|
|
26
|
+
# --------------------------------------------------------------
|
|
27
|
+
# copy the ssh keys into place, npm install, and remove them
|
|
28
|
+
# --------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
# Install packages to install private repos with ssh keys
|
|
31
|
+
COPY ./.npmrc /usr/src/app/.npmrc
|
|
32
|
+
RUN apk --no-cache add openssh-client && \
|
|
33
|
+
apk --update add --no-cache --virtual build-dep g++ gcc libgcc \\
|
|
34
|
+
libstdc++ linux-headers make {{apkadds}} && \
|
|
35
|
+
npm install -g npm@10 && \
|
|
36
|
+
npm ci --only=production --ignore-scripts --no-optional {{npmlogging}} && \
|
|
37
|
+
rm -f /usr/src/app/.npmrc /root/.ssh/*
|
|
38
|
+
|
|
39
|
+
# --------------------------------------------------------------
|
|
40
|
+
# On to the real build now, the thing before was just an intermediate container
|
|
41
|
+
# --------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
FROM node:{{nodeimage}}
|
|
44
|
+
|
|
45
|
+
# Install tini for PID 1 and replace shell with bash so we can source files
|
|
46
|
+
RUN apk update && \
|
|
47
|
+
apk add --no-cache bash curl tini vim {{apkadds}} && \
|
|
48
|
+
npm install -g npm@10 && \
|
|
49
|
+
rm /bin/sh && ln -s /bin/bash /bin/sh && \
|
|
50
|
+
mkdir -p /usr/src/app /tmp/levlog && \
|
|
51
|
+
chown node:node /usr/src/app
|
|
52
|
+
|
|
53
|
+
{{pluginfile}}
|
|
54
|
+
|
|
55
|
+
ENTRYPOINT [ "/sbin/tini", "--" ]
|
|
56
|
+
WORKDIR /usr/src/app
|
|
57
|
+
|
|
58
|
+
COPY --chown=node:node --from=intermediate /usr/src/app /usr/src/app
|
|
59
|
+
|
|
60
|
+
USER {{runuser}}
|
|
61
|
+
COPY ./bashrc /home/node/.bashrc
|
|
62
|
+
CMD [ "/bin/bash", "-c", "node index.js" ]`
|
|
63
|
+
|
|
64
|
+
const pluginTemplate = `
|
|
65
|
+
# Dockerfile.plugin - optionally extend the service Docker image
|
|
66
|
+
#
|
|
67
|
+
# This file may be used to run additional docker commands during the image
|
|
68
|
+
# build process without needing to maintain a local custom Dockerfile. For
|
|
69
|
+
# example, uncommenting the following docker RUN command will cause the
|
|
70
|
+
# curl and vim packages to be added to the deployed image thus making them
|
|
71
|
+
# available from the pod's command line on k8s:
|
|
72
|
+
#
|
|
73
|
+
# RUN apk update && apk add --no-cache curl vim
|
|
74
|
+
#
|
|
75
|
+
# Keep in mind that the Alpine Linux base image is used to keep image
|
|
76
|
+
# footprints small, so adding packages "just because" is not considered
|
|
77
|
+
# a best practice.
|
|
78
|
+
`
|
|
79
|
+
|
|
80
|
+
const bashrcTemplate = `
|
|
81
|
+
#!/bin/bash
|
|
82
|
+
#
|
|
83
|
+
alias h=history
|
|
84
|
+
|
|
85
|
+
alias ls='ls -CF --color=auto'
|
|
86
|
+
alias ll='ls -lh'
|
|
87
|
+
alias lla='ls -lha'
|
|
88
|
+
alias glep='grep -l -s'
|
|
89
|
+
alias m=less
|
|
90
|
+
alias menv='env | sort | less'
|
|
91
|
+
|
|
92
|
+
alias whatsmyip='wget -qO- ifconfig.co'
|
|
93
|
+
|
|
94
|
+
alias err='wget -q -O- localhost:5111/logLevel/error'
|
|
95
|
+
alias wrn='wget -q -O- localhost:5111/logLevel/warn'
|
|
96
|
+
alias inf='wget -q -O- localhost:5111/logLevel/info'
|
|
97
|
+
alias dbg='wget -q -O- localhost:5111/logLevel/debug'
|
|
98
|
+
alias trc='wget -q -O- localhost:5111/logLevel/trace'
|
|
99
|
+
|
|
100
|
+
socks()
|
|
101
|
+
{
|
|
102
|
+
netstat -ant | awk '{print }' | sort | uniq -c | sort -n
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
cmetrics()
|
|
106
|
+
{
|
|
107
|
+
wget -qO- localhost:5111/metrics
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
cmstat()
|
|
111
|
+
{
|
|
112
|
+
wget -qO- localhost:5111${1}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cmclear()
|
|
116
|
+
{
|
|
117
|
+
cmstat /status/clear
|
|
118
|
+
}
|
|
119
|
+
`
|
|
120
|
+
|
|
121
|
+
// Just uses the old dockreate of formatting the date.
|
|
122
|
+
const dateTimestamp = await shellCmd( 'date +%Y%m%d-%H%M' )
|
|
123
|
+
|
|
124
|
+
const defaultSettings = {
|
|
125
|
+
apkadds : '',
|
|
126
|
+
date : dateTimestamp,
|
|
127
|
+
nodeimage : 'iron-alpine',
|
|
128
|
+
npmlogging : '--silent',
|
|
129
|
+
pluginfile : '# NO PLUGIN',
|
|
130
|
+
regvers : 'package.version',
|
|
131
|
+
runuser : 'node',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const previousFile = './docker/.previous'
|
|
135
|
+
|
|
136
|
+
const getPreviousBuild = () => {
|
|
137
|
+
return fs.existsSync( previousFile ) ? fs.readFileSync( previousFile ) : 'FIRST BUILD'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const setPreviousBuild = ( version ) => {
|
|
141
|
+
fs.writeFileSync( previousFile, version )
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const generateDockerfile = ( settings = defaultSettings ) => {
|
|
145
|
+
|
|
146
|
+
log( chalk.green.bold( 'Validating the docker structure\n' ) )
|
|
147
|
+
|
|
148
|
+
// Ensure the presence of the docker dir with plugin and bashrc - this code
|
|
149
|
+
// could probably be tightened up a little.
|
|
150
|
+
try {
|
|
151
|
+
fs.readdirSync( './docker' )
|
|
152
|
+
} catch ( err ) {
|
|
153
|
+
warning( 'creating the missing ./docker directory' )
|
|
154
|
+
fs.mkdirSync( './docker' ) // TODO: blindly assumes the mkdir succeeds
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const bashrcFile = './docker/bashrc'
|
|
158
|
+
if ( !fs.existsSync( bashrcFile ) ) {
|
|
159
|
+
warning( `creating the missing ${bashrcFile} file in the docker directory` )
|
|
160
|
+
fs.writeFileSync( bashrcFile, bashrcTemplate )
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const dockerfilePlugin = './docker/Dockerfile.plugin'
|
|
164
|
+
if ( !fs.existsSync( dockerfilePlugin ) ) {
|
|
165
|
+
warning( `creating the missing ${dockerfilePlugin} file in the docker directory` )
|
|
166
|
+
fs.writeFileSync( dockerfilePlugin, pluginTemplate )
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
const build = fs.readdirSync( './build' )
|
|
171
|
+
if ( build.length === 0 ) {
|
|
172
|
+
errorExit( `***ERROR: the build dir is empty - ${chalk.yellow( 'run npm build' )}` )
|
|
173
|
+
}
|
|
174
|
+
} catch ( err ) {
|
|
175
|
+
errorExit( `***ERROR: expected the ./build directory to exist - ${chalk.yellow( 'run npm build' )}` )
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// At this point the plugin template better exist.
|
|
179
|
+
if ( fs.existsSync( dockerfilePlugin ) ) {
|
|
180
|
+
defaultSettings.pluginfile = fs.readFileSync( dockerfilePlugin )
|
|
181
|
+
} else {
|
|
182
|
+
errorExit( `***ERROR: something went wrong with ${dockerfilePlugin} plugin creation` )
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const compiled = handlebars.compile( dockerfileTemplate )
|
|
186
|
+
const replaced = compiled( settings )
|
|
187
|
+
const dockerfile = './docker/Dockerfile'
|
|
188
|
+
try {
|
|
189
|
+
fs.writeFileSync( dockerfile, replaced )
|
|
190
|
+
} catch ( err ) {
|
|
191
|
+
errorExit( `***ERROR: failed to write ${dockerfile}\n${err}` )
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const previousBuild = getPreviousBuild()
|
|
195
|
+
const dockerInfo = { dockerfile, previousBuild, ...defaultSettings }
|
|
196
|
+
delete dockerInfo.pluginfile
|
|
197
|
+
return dockerInfo
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const formCloudBuildBucketName = ( artifactProject ) => {
|
|
201
|
+
return `gs://${artifactProject}_cloudbuild`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const validateCloudBuildBucket = async ( artifactProject ) => {
|
|
205
|
+
const bucketName = formCloudBuildBucketName( artifactProject )
|
|
206
|
+
log( chalk.green.bold( `Verifying the build bucket exists => ${bucketName}\n` ) )
|
|
207
|
+
try {
|
|
208
|
+
await shellCmd( `gsutil ls -p ${artifactProject} -b ${bucketName}` )
|
|
209
|
+
} catch ( error ) {
|
|
210
|
+
errorExit( `***Error: from Docker.validateCloudBuildBucket\n\n${chalk.bold.yellow( error )}` )
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const buildContainerImage = async ( { artifactProject, artifactRegistry, containerName, imageVersion } ) => {
|
|
215
|
+
const cloudBuildWorkspace = './docker/workspace'
|
|
216
|
+
|
|
217
|
+
if ( fs.existsSync( cloudBuildWorkspace ) ) {
|
|
218
|
+
fs.renameSync( cloudBuildWorkspace, `${cloudBuildWorkspace}-junk` )
|
|
219
|
+
fs.rm( `${cloudBuildWorkspace}-junk`, { recursive : true }, ( err ) => {} ) // fire and forget
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fs.mkdirSync( cloudBuildWorkspace )
|
|
223
|
+
|
|
224
|
+
fs.cpSync( './build', './docker/workspace', { recursive : true } )
|
|
225
|
+
fs.cpSync( `${process.env.HOME}/.npmrc`, './docker/.npmrc' )
|
|
226
|
+
fs.cpSync( './package.json', './docker/workspace/package.json' )
|
|
227
|
+
fs.renameSync( './package-lock.json', './docker/workspace/package-lock.json' )
|
|
228
|
+
|
|
229
|
+
setPreviousBuild( imageVersion ) // update docker/.previous file
|
|
230
|
+
|
|
231
|
+
const gcloudBuild = `time gcloud builds submit --project ${artifactProject}`
|
|
232
|
+
const gcloudLogs = `--gcs-log-dir ${formCloudBuildBucketName( artifactProject )}/log`
|
|
233
|
+
const gcloudTags = `--tag ${artifactRegistry}/images/${containerName}:${imageVersion}`
|
|
234
|
+
|
|
235
|
+
log( chalk.green.bold( `
|
|
236
|
+
*** Submitting Build ***
|
|
237
|
+
${gcloudBuild} \\
|
|
238
|
+
${gcloudLogs} \\
|
|
239
|
+
${gcloudTags}
|
|
240
|
+
` ) )
|
|
241
|
+
|
|
242
|
+
await shellCmd( `${gcloudBuild} ${gcloudLogs} ${gcloudTags} ./docker`, { stdio : 'inherit' } )
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export default {
|
|
246
|
+
getPreviousBuild,
|
|
247
|
+
setPreviousBuild,
|
|
248
|
+
generateDockerfile,
|
|
249
|
+
formCloudBuildBucketName,
|
|
250
|
+
validateCloudBuildBucket,
|
|
251
|
+
buildContainerImage,
|
|
252
|
+
}
|
package/src/Utils.mjs
CHANGED
|
@@ -2,6 +2,9 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { $ } from 'execa'
|
|
5
|
+
import inquirer from 'inquirer'
|
|
6
|
+
import { glob } from 'glob'
|
|
7
|
+
import { packageUp } from 'package-up'
|
|
5
8
|
import YAML from 'js-yaml'
|
|
6
9
|
|
|
7
10
|
const debugEnabled = process.env.BUILD_TOOLS_DEBUG === '1'
|
|
@@ -19,12 +22,34 @@ export const condir = ( obj, text = '' ) => {
|
|
|
19
22
|
export const debug = ( obj, text ) => {
|
|
20
23
|
if ( debugEnabled ) { condir( obj, text ) }
|
|
21
24
|
}
|
|
25
|
+
export const warning = ( warningText ) => {
|
|
26
|
+
const fullWarning = `***WARNING: ${warningText}`
|
|
27
|
+
console.error( `\n${chalk.yellow.bold( fullWarning )}` )
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export const errorExit = ( error, opts = { errorCode : 1 } ) => {
|
|
23
31
|
console.error( `\n${chalk.red.bold( error )}\n` )
|
|
24
32
|
if ( opts?.errorCode ) { process.exit( opts.errorCode ) }
|
|
25
33
|
}
|
|
26
34
|
/* eslint-enable no-console */
|
|
27
35
|
|
|
36
|
+
/**
|
|
37
|
+
* General "yes" to proceed function.
|
|
38
|
+
*/
|
|
39
|
+
export const proceed = async ( query = 'Do you wish to proceed?' ) => {
|
|
40
|
+
await inquirer.prompt( [
|
|
41
|
+
{
|
|
42
|
+
type : 'confirm',
|
|
43
|
+
name : 'proceed',
|
|
44
|
+
message : query,
|
|
45
|
+
default : true,
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
).then( ( answer ) => {
|
|
49
|
+
if ( !answer.proceed ) { process.exit( 0 ) }
|
|
50
|
+
} )
|
|
51
|
+
}
|
|
52
|
+
|
|
28
53
|
export const shellCmd = async ( cmdstr, opts = {} ) => {
|
|
29
54
|
try {
|
|
30
55
|
// due to the escaping rules we pull apart the cmdstr and invoke $ using
|
|
@@ -85,15 +110,22 @@ export const parseJsonFile = async ( jsonFile ) => {
|
|
|
85
110
|
throw new Error( `${error} in ${jsonFile}` )
|
|
86
111
|
}
|
|
87
112
|
}
|
|
88
|
-
throw new Error( `
|
|
113
|
+
throw new Error( `Utils.parseJsonFile: file ${jsonFile} does not exist in ${process.cwd()}` )
|
|
89
114
|
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
90
115
|
}
|
|
91
116
|
|
|
92
117
|
// Parses the ./package.json file and verifies there is a properly formatted
|
|
93
118
|
// leverege.registry section present.
|
|
119
|
+
const deprecated = ( opts ) => {
|
|
120
|
+
log( chalk.red.bold( `\n ***DEPRECATED: ${opts.deprecationError}` ) )
|
|
121
|
+
log( chalk.white( opts.deprecationInfo ) )
|
|
122
|
+
process.exit( 1 )
|
|
123
|
+
}
|
|
124
|
+
|
|
94
125
|
export const parsePackageJson = async ( packageFileName ) => {
|
|
95
126
|
const packageJson = await parseJsonFile( packageFileName )
|
|
96
127
|
|
|
128
|
+
// deprecation checks are here to ease the pain of upgrading older repos
|
|
97
129
|
const leveregeClauseError = `leverege.registry statement, it should
|
|
98
130
|
resemble something like:
|
|
99
131
|
|
|
@@ -102,25 +134,116 @@ export const parsePackageJson = async ( packageFileName ) => {
|
|
|
102
134
|
},
|
|
103
135
|
|
|
104
136
|
`
|
|
105
|
-
|
|
106
|
-
if ( !
|
|
137
|
+
const registry = packageJson?.leverege?.registry
|
|
138
|
+
if ( !registry ) {
|
|
107
139
|
errorExit( `Error: package.json is missing a proper ${leveregeClauseError}` )
|
|
108
140
|
}
|
|
109
141
|
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
142
|
+
const registryComponents = registry.split( '/' )
|
|
143
|
+
if ( registryComponents.length !== 3 ) {
|
|
112
144
|
errorExit( `Error: package.json has a malformed ${leveregeClauseError}` )
|
|
113
145
|
}
|
|
114
146
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
147
|
+
const [ region, project, repository ] = registryComponents
|
|
148
|
+
const artifactRegistry = { region, project, repository }
|
|
149
|
+
|
|
150
|
+
// DEPRECATED: leverege.project
|
|
151
|
+
if ( packageJson?.leverege?.project ) {
|
|
152
|
+
const removeLine = `"project": "${packageJson.leverege.project}",`
|
|
153
|
+
|
|
154
|
+
const deprecationError = 'leverege.project is no longer supported'
|
|
155
|
+
const deprecationInfo = `
|
|
156
|
+
Setting the project in the package.json leverege section was used for builds
|
|
157
|
+
being stored in the deprecated GCP container registry. Remove the deprecated
|
|
158
|
+
leverege.project setting from package.json and try again.
|
|
159
|
+
|
|
160
|
+
"leverege": {
|
|
161
|
+
${chalk.red.bold( removeLine )}
|
|
162
|
+
...
|
|
163
|
+
}
|
|
164
|
+
`
|
|
165
|
+
deprecated( { deprecationError, deprecationInfo } )
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// DEPRECATED: leverege.container
|
|
169
|
+
if ( packageJson?.leverege?.container ) {
|
|
170
|
+
const removeLine = `"container": "${packageJson.leverege.container}",`
|
|
171
|
+
|
|
172
|
+
const deprecationError = 'leverege.container is no longer supported'
|
|
173
|
+
const deprecationInfo = `
|
|
174
|
+
Setting the container name explicitly from the package.json leverge block
|
|
175
|
+
is no longer supported. The container name will be automatically derived
|
|
176
|
+
from the git repository's remote root, which is the default behavior. Remove
|
|
177
|
+
the container line from the leverege section in package.json and try again.
|
|
178
|
+
|
|
179
|
+
"leverege": {
|
|
180
|
+
${chalk.red.bold( removeLine )}
|
|
181
|
+
...
|
|
182
|
+
}
|
|
183
|
+
`
|
|
184
|
+
deprecated( { deprecationError, deprecationInfo } )
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// DEPRECATED: leverege.nodeimg
|
|
188
|
+
if ( packageJson?.leverege?.nodeimg ) {
|
|
189
|
+
const removeLine = `"nodeimg": "${packageJson.leverege.nodeimg}",`
|
|
190
|
+
|
|
191
|
+
const deprecationError = 'leverege.nodeimg is no longer supported'
|
|
192
|
+
const deprecationInfo = `
|
|
193
|
+
Setting the node base image using the nodeimg statement in package.json is no
|
|
194
|
+
longer supported. By default the actual node image version will be defaulted
|
|
195
|
+
by this script and will rarely need to be a specific version. Remove the
|
|
196
|
+
nodeimg line from the leverege section in package.json and try again.
|
|
197
|
+
|
|
198
|
+
"leverege": {
|
|
199
|
+
${chalk.red.bold( removeLine )}
|
|
200
|
+
...
|
|
201
|
+
}
|
|
202
|
+
`
|
|
203
|
+
deprecated( { deprecationError, deprecationInfo } )
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// DEPRECATED: leverege.artifact
|
|
207
|
+
if ( packageJson?.leverege?.artifact ) {
|
|
208
|
+
const removeLine = `"artifact": "${packageJson.leverege.artifact}",`
|
|
209
|
+
const replaceLine = `"registry": "us-docker.pkg.dev/leverege-registry/${packageJson.leverege.artifact}",`
|
|
210
|
+
|
|
211
|
+
const deprecationError = 'leverege.artifact is no longer supported'
|
|
212
|
+
const deprecationInfo = `
|
|
213
|
+
Setting the registry folder via the ${chalk.yellow.bold( 'artifact' )} statement is no longer supported.
|
|
214
|
+
Instead use the ${chalk.green.bold( 'leverege.registry' )} setting to specify the full artifact registry
|
|
215
|
+
and folder used for storing the docker image. Replace the artifact line with the
|
|
216
|
+
full registry path in package.json and try again.
|
|
217
|
+
|
|
218
|
+
"leverege": {
|
|
219
|
+
${chalk.red.bold( removeLine )}
|
|
220
|
+
${chalk.green.bold( replaceLine )}
|
|
221
|
+
...
|
|
222
|
+
}
|
|
223
|
+
`
|
|
224
|
+
deprecated( { deprecationError, deprecationInfo } )
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// DEPRECATED: leverege.nodeops
|
|
228
|
+
if ( packageJson?.leverege?.nodeops ) {
|
|
229
|
+
const removeLine = `"nodeops": "${packageJson.leverege.nodeops}",`
|
|
230
|
+
|
|
231
|
+
const deprecationError = 'leverege.nodeops is no longer supported'
|
|
232
|
+
const deprecationInfo = `
|
|
233
|
+
Setting the hard coded node options on the image is no longer supported. The
|
|
234
|
+
better approach is to add ${chalk.green.bold( 'NODE_OPTIONS' )} to the config section of the chart's
|
|
235
|
+
values.yaml to allow downstream users to easily tune the options as needed.
|
|
236
|
+
Remove the nodeops line from the leverege section in package.json and try again.
|
|
237
|
+
|
|
238
|
+
"leverege": {
|
|
239
|
+
${chalk.red.bold( removeLine )}
|
|
240
|
+
...
|
|
123
241
|
}
|
|
242
|
+
`
|
|
243
|
+
deprecated( { deprecationError, deprecationInfo } )
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return { artifactRegistry, ...packageJson }
|
|
124
247
|
}
|
|
125
248
|
|
|
126
249
|
export const parseHelmChart = async ( helmroot ) => {
|
|
@@ -137,3 +260,59 @@ export const parseHelmChart = async ( helmroot ) => {
|
|
|
137
260
|
}
|
|
138
261
|
} )
|
|
139
262
|
}
|
|
263
|
+
|
|
264
|
+
export const describeRepository = async () => {
|
|
265
|
+
const gitRoot = await getGitRootDirectory()
|
|
266
|
+
const subPkgs = await glob( `${gitRoot}/packages/**/package.json`, { ignore : '/**/node_modules/**' } )
|
|
267
|
+
|
|
268
|
+
let rootPackageJson
|
|
269
|
+
try {
|
|
270
|
+
rootPackageJson = await parseJsonFile( `${gitRoot}/package.json` )
|
|
271
|
+
} catch ( error ) {
|
|
272
|
+
rootPackageJson = { inValid : true, error : 'invalid or non-existent root package.json file' }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
log( chalk.green.bold( '\nParsing and analyzing the package.json file\n' ) )
|
|
276
|
+
let closestPackageJson
|
|
277
|
+
try {
|
|
278
|
+
closestPackageJson = await parsePackageJson( './package.json' )
|
|
279
|
+
} catch ( error ) {
|
|
280
|
+
errorExit( error )
|
|
281
|
+
}
|
|
282
|
+
const containerName = closestPackageJson.name
|
|
283
|
+
const artifactProject = closestPackageJson.artifactRegistry.project
|
|
284
|
+
const artifactRegistry = closestPackageJson.leverege.registry
|
|
285
|
+
|
|
286
|
+
const currentDir = process.cwd()
|
|
287
|
+
const closestPkg = await packageUp()
|
|
288
|
+
|
|
289
|
+
// get the name of the current workspace, if we're in one
|
|
290
|
+
let wsName
|
|
291
|
+
try {
|
|
292
|
+
wsName = await shellCmd( 'npm exec -c pwd -ws' )
|
|
293
|
+
} catch ( err ) { }
|
|
294
|
+
|
|
295
|
+
let gitRemote
|
|
296
|
+
try {
|
|
297
|
+
gitRemote = await shellCmd( 'git config --get remote.origin.url' )
|
|
298
|
+
} catch ( err ) { }
|
|
299
|
+
|
|
300
|
+
// TODO: Add in Define VERBOSE_DOCKREATE_NPM="yes" for verbose build logging
|
|
301
|
+
// TODO: Validity check for version and package.json
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
artifactProject,
|
|
305
|
+
artifactRegistry,
|
|
306
|
+
containerName,
|
|
307
|
+
currentDir,
|
|
308
|
+
closestPkg,
|
|
309
|
+
gitRoot,
|
|
310
|
+
gitRemote,
|
|
311
|
+
isMonoRepo : subPkgs?.length > 0,
|
|
312
|
+
isNpmWorkspace : rootPackageJson?.workspaces?.length > 0,
|
|
313
|
+
rootPackageJson,
|
|
314
|
+
closestPackageJson,
|
|
315
|
+
subPkgs,
|
|
316
|
+
wsName,
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* docker-to-registry will...
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
debug, log,
|
|
9
|
+
errorExit,
|
|
10
|
+
describeRepository,
|
|
11
|
+
proceed,
|
|
12
|
+
shellCmd } from './Utils.mjs'
|
|
13
|
+
|
|
14
|
+
import docker from './Docker.mjs'
|
|
15
|
+
|
|
16
|
+
// refresh-npm-token does not throw so no need to try, but it emits in debug
|
|
17
|
+
const refreshErr = await shellCmd( 'refresh-npm-token' )
|
|
18
|
+
if ( refreshErr && !process.env.BUILD_TOOLS_DEBUG ) {
|
|
19
|
+
errorExit( `***Error: npm token refresh failed\n\n${refreshErr}` )
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Expected to be invoked like docker-to-registry v1.2.3
|
|
23
|
+
const imageVersion = process.argv[2]
|
|
24
|
+
const willGitTag = imageVersion.match( /^v\d+\.\d+\.\d+$/ )
|
|
25
|
+
const tagInfo = willGitTag ?
|
|
26
|
+
chalk.yellow.bold( 'will be git tagged' ) :
|
|
27
|
+
chalk.red( 'BETA RELEASE WILL NOT BE GIT TAGGED' )
|
|
28
|
+
|
|
29
|
+
const repoDescr = await describeRepository()
|
|
30
|
+
debug( { repoDescr }, '<==The Repo Description' )
|
|
31
|
+
|
|
32
|
+
const dockerInfo = await docker.generateDockerfile()
|
|
33
|
+
debug( { dockerInfo }, '<==The Docker Info' )
|
|
34
|
+
|
|
35
|
+
const { artifactProject, artifactRegistry, containerName } = repoDescr
|
|
36
|
+
|
|
37
|
+
await docker.validateCloudBuildBucket( artifactProject )
|
|
38
|
+
|
|
39
|
+
const registryFolder = `${artifactRegistry}/images/${containerName}`
|
|
40
|
+
|
|
41
|
+
// Update the dependencies...
|
|
42
|
+
log( chalk.green.bold( 'Updating dependencies and workspace...' ) )
|
|
43
|
+
await shellCmd( 'npm install', { stdio : 'inherit' } )
|
|
44
|
+
|
|
45
|
+
// Give the summary and the user a chance to proceed or not
|
|
46
|
+
log( `
|
|
47
|
+
${chalk.green.bold( 'Build Information:' )}
|
|
48
|
+
Container: ${chalk.green.bold( containerName )}
|
|
49
|
+
Version: ${chalk.green.bold( imageVersion )} ${tagInfo}
|
|
50
|
+
Registry: ${chalk.green.bold( artifactRegistry )}
|
|
51
|
+
Image Folder: ${chalk.yellow.bold( registryFolder )}
|
|
52
|
+
Monorepo: ${chalk.green.bold( repoDescr.isMonoRepo )}
|
|
53
|
+
NPM Workspace: ${chalk.green.bold( repoDescr.isNpmWorkspace )}
|
|
54
|
+
|
|
55
|
+
${chalk.green.bold( 'Docker Information:' )}
|
|
56
|
+
NodeImage: ${chalk.green.bold( dockerInfo.nodeimage )}
|
|
57
|
+
AddedPkgs: ${chalk.green.bold( dockerInfo.apkadds )}
|
|
58
|
+
Run User: ${chalk.green.bold( dockerInfo.runuser )}
|
|
59
|
+
Previous: ${chalk.yellow.bold( dockerInfo.previousBuild )}
|
|
60
|
+
DateStamp: ${chalk.green.bold( dockerInfo.date )}
|
|
61
|
+
NPM Logs: ${chalk.green.bold( dockerInfo.npmlogging )}
|
|
62
|
+
` )
|
|
63
|
+
|
|
64
|
+
await proceed()
|
|
65
|
+
|
|
66
|
+
if ( repoDescr.isNpmWorkspace ) {
|
|
67
|
+
log( chalk.yellow.bold( 'Generating an NPM workspace package-lock.json file' ) )
|
|
68
|
+
await shellCmd( 'npm install --package-lock-only --workspaces false', { stdio : 'inherit' } )
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await docker.buildContainerImage( { artifactProject, artifactRegistry, containerName, imageVersion } )
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Artifact Chart => https://artifacthub.io/packages/helm/cloudnative-pg/cloudnative-pg
|
|
2
|
+
# Examples Charts => https://cloudnative-pg.io/documentation/current/samples/
|
|
3
|
+
apiVersion: postgresql.cnpg.io/v1
|
|
4
|
+
kind: Cluster
|
|
5
|
+
metadata:
|
|
6
|
+
name: db-postgres-stack
|
|
7
|
+
namespace: cnpg-operands
|
|
8
|
+
spec:
|
|
9
|
+
instances: 1
|
|
10
|
+
# logLevel: debug
|
|
11
|
+
|
|
12
|
+
description: "Leverege Stack PostgreSQL DB"
|
|
13
|
+
imageName: us-docker.pkg.dev/leverege-registry/system/images/leverege-pgsql:16.1-cnpg-tsdb2-beta.10
|
|
14
|
+
bootstrap:
|
|
15
|
+
initdb:
|
|
16
|
+
database: imagine
|
|
17
|
+
owner: imagine
|
|
18
|
+
secret:
|
|
19
|
+
name: db-postgres-stack-imagine-pw # imagine db pw
|
|
20
|
+
|
|
21
|
+
enableSuperuserAccess: true
|
|
22
|
+
superuserSecret:
|
|
23
|
+
name: db-postgres-stack-postgres-pw # postgres db pw
|
|
24
|
+
|
|
25
|
+
affinity:
|
|
26
|
+
# enablePodAntiAffinity: true
|
|
27
|
+
# topologyKey: failure-domain.beta.kubernetes.io/zone
|
|
28
|
+
tolerations:
|
|
29
|
+
- key: "database"
|
|
30
|
+
operator: "Equal"
|
|
31
|
+
value: "true"
|
|
32
|
+
effect: "NoSchedule"
|
|
33
|
+
|
|
34
|
+
# Parameters and pg_hba configuration will be append
|
|
35
|
+
# to the default ones to make the cluster work
|
|
36
|
+
postgresql:
|
|
37
|
+
parameters:
|
|
38
|
+
# max_worker_processes: "60"
|
|
39
|
+
# max_worker_processes: "8"
|
|
40
|
+
# max_parallel_workers: "8"
|
|
41
|
+
max_connections: "500"
|
|
42
|
+
# shared_buffers: 2GB
|
|
43
|
+
# effective_cache_size: 6GB
|
|
44
|
+
# maintenance_work_mem: 1GB
|
|
45
|
+
# work_mem: 20MB
|
|
46
|
+
|
|
47
|
+
# - unsupervised: automated update of the primary once all
|
|
48
|
+
# replicas have been upgraded (default)
|
|
49
|
+
# - supervised: requires manual supervision to perform
|
|
50
|
+
# the switchover of the primary
|
|
51
|
+
primaryUpdateStrategy: unsupervised
|
|
52
|
+
|
|
53
|
+
serviceAccountTemplate:
|
|
54
|
+
metadata:
|
|
55
|
+
annotations:
|
|
56
|
+
iam.gke.io/gcp-service-account: cnpg-operands-sa@OVH:<PROJECT_ID>.iam.gserviceaccount.com
|
|
57
|
+
|
|
58
|
+
# Require 50Gi of space per instance using ssd storage class
|
|
59
|
+
storage:
|
|
60
|
+
storageClass: premium-rwo
|
|
61
|
+
size: 50Gi
|
|
62
|
+
# walStorage:
|
|
63
|
+
# storageClass: premium-rwo
|
|
64
|
+
# size: 1Gi
|
|
65
|
+
|
|
66
|
+
backup:
|
|
67
|
+
retentionPolicy: 30d
|
|
68
|
+
volumeSnapshot:
|
|
69
|
+
labels:
|
|
70
|
+
snapshotOf: db-postgres-stack
|
|
71
|
+
className: cnpg-snapshotclass
|
|
72
|
+
barmanObjectStore:
|
|
73
|
+
destinationPath: gs://OVH:<PROJECT_ID>-barman
|
|
74
|
+
googleCredentials:
|
|
75
|
+
gkeEnvironment: true
|
|
76
|
+
tags:
|
|
77
|
+
cnpgCluster: db-postgres-stack
|
|
78
|
+
wal:
|
|
79
|
+
compression: gzip
|
|
80
|
+
#---
|
|
81
|
+
#apiVersion: postgresql.cnpg.io/v1
|
|
82
|
+
#kind: Pooler
|
|
83
|
+
#metadata:
|
|
84
|
+
# name: db-postgres-stack-pool-rw
|
|
85
|
+
# namespace: cnpg-operands
|
|
86
|
+
#spec:
|
|
87
|
+
# cluster:
|
|
88
|
+
# name: db-postgres-stack
|
|
89
|
+
#
|
|
90
|
+
# instances: 1
|
|
91
|
+
# type: rw
|
|
92
|
+
# pgbouncer:
|
|
93
|
+
# poolMode: session
|
|
94
|
+
# parameters:
|
|
95
|
+
# max_client_conn: "500"
|
|
96
|
+
# default_pool_size: "10"
|
|
97
|
+
---
|
|
98
|
+
apiVersion: postgresql.cnpg.io/v1
|
|
99
|
+
kind: ScheduledBackup
|
|
100
|
+
metadata:
|
|
101
|
+
name: db-postgres-stack-backup
|
|
102
|
+
namespace: cnpg-operands
|
|
103
|
+
spec:
|
|
104
|
+
# https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format
|
|
105
|
+
schedule: "0 0 * * * *"
|
|
106
|
+
cluster:
|
|
107
|
+
name: db-postgres-stack
|
|
108
|
+
method: volumeSnapshot
|
|
109
|
+
backupOwnerReference: self
|
|
110
|
+
immediate: true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
db-timescale-dense.yaml
|
|
@@ -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="18.
|
|
7
|
+
[ -z "$REDIS_CHART_VERSION" ] && REDIS_CHART_VERSION="18.7.1"
|
|
8
8
|
|
|
9
9
|
helm upgrade --install redis $OCI_CHART \
|
|
10
10
|
--values redis/redis-local.yaml \
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
postgresql:
|
|
2
2
|
postgresqlExtendedConf:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
effectiveCacheSize: 6GB # 524288 8kB
|
|
4
|
+
idle_in_transaction_session_timeout: 30000 # 0 ms
|
|
5
|
+
maintenanceWorkMem: 1GB # 65536 kB
|
|
6
|
+
maxConnections: 500 # 100
|
|
7
|
+
maxParallelWorkers: 8 # 32
|
|
8
|
+
maxWalSize: 2GB # 80 MB
|
|
9
|
+
maxWorkerProcesses: 8 # 32
|
|
10
|
+
sharedBuffers: 2GB # 16384 8kB
|
|
11
|
+
walKeepSegments: 64 # deprecated
|
|
12
|
+
workMem: 20MB # 4096 kB
|
|
13
13
|
|
|
14
14
|
resources:
|
|
15
15
|
requests:
|
|
@@ -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="26"
|
|
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/k8x.sh
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
3
|
cmd=${@:-"bash"}
|
|
4
|
+
ns="default"
|
|
4
5
|
|
|
5
6
|
[ "$cmd" = "redis" ] || [ "$cmd" = "redis-cli" ] && FZFQ="--query=redis" && cmd='redis-cli'
|
|
6
7
|
|
|
7
8
|
[ "$cmd" = "pgsql" ] && FZFQ="--query=postgresql" && cmd='psql -U postgres'
|
|
8
9
|
|
|
10
|
+
[ "$cmd" = "cnpg" ] && ns="cnpg-operands" && cmd="bash"
|
|
11
|
+
|
|
9
12
|
[ -f overwhelm.yaml ] && [ -f package.json ] && npm run ahoy
|
|
10
13
|
|
|
11
14
|
[ ! -x "$(command -v fzf)" ] && printf "\n***ERROR: Missing fzf fuzzy matcher => brew install fzf\n\n" && exit 1
|
|
12
15
|
|
|
13
|
-
pod=$(kubectl -n
|
|
16
|
+
pod=$(kubectl -n $ns get pods -owide | fzf $FZFQ | awk '{print $1}')
|
|
14
17
|
|
|
15
|
-
kubecmd="kubectl exec -it $pod -- $cmd"
|
|
18
|
+
kubecmd="kubectl exec -n $ns -it $pod -- $cmd"
|
|
16
19
|
echo " run=[${kubecmd}]"
|
|
17
20
|
|
|
18
21
|
eval ${kubecmd}
|