@leverege/build-tools 2.61.7 → 2.62.0-alpha.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 +14 -8
- package/src/Docker.mjs +18 -44
- package/src/DockerPy.mjs +257 -0
- package/src/Utils.mjs +0 -6
- package/src/bash-funcs +0 -4
- package/src/docker-to-registry-py.mjs +291 -0
- package/src/docker-to-registry.mjs +1 -3
- package/src/docker-to-registry.sh +1 -1
- package/src/helm-charts/cnpg-db-pgbench/cluster.yaml.ovh +3 -2
- package/src/helm-charts/cnpg-db-psql-stack/cluster.yaml.ovh +3 -2
- package/src/helm-charts/cnpg-db-recovery/cluster.yaml.ovh +3 -2
- package/src/helm-charts/cnpg-db-tsdb-basic/cluster.yaml.ovh +3 -2
- package/src/helm-charts/cnpg-db-tsdb-dense/cluster.yaml.ovh +3 -2
- package/src/helm-charts/prom-operator/helmup.plugin +1 -4
- package/src/hook-and-release/Config.mjs +0 -9
- package/src/templates/bashrcTemplatePy.hbs +1 -0
- package/src/templates/dockerfileTemplate.hbs +6 -6
- package/src/templates/dockerfileTemplatePy.hbs +75 -0
- package/src/build-cnpg-image.mjs +0 -176
- package/src/chart-compass.mjs +0 -97
package/src/build-cnpg-image.mjs
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// A simple utility for easily building CNPG based psql images. The resultant
|
|
4
|
-
// image will contain PostgreSQL, the JS query and Timescale extensions, and
|
|
5
|
-
// the extensions that are required by CNPG like barman, pgaudit, pgvector and
|
|
6
|
-
// pg-failover-slots.
|
|
7
|
-
//
|
|
8
|
-
// Latest Versions:
|
|
9
|
-
// postgres => https://www.postgresql.org/
|
|
10
|
-
// timescale => https://docs.timescale.com/about/latest/
|
|
11
|
-
// CNPG images => https://github.com/cloudnative-pg/postgres-containers/pkgs/container/postgresql
|
|
12
|
-
|
|
13
|
-
import fs from 'node:fs'
|
|
14
|
-
import path from 'node:path'
|
|
15
|
-
|
|
16
|
-
import chalk from 'chalk'
|
|
17
|
-
import cliArgs from 'command-line-args'
|
|
18
|
-
import cliHelp from 'command-line-usage'
|
|
19
|
-
import Handlebars from 'handlebars'
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
debug,
|
|
23
|
-
log,
|
|
24
|
-
err,
|
|
25
|
-
errorExit,
|
|
26
|
-
shellCmd,
|
|
27
|
-
} from './Utils.mjs'
|
|
28
|
-
|
|
29
|
-
// Define CLI options
|
|
30
|
-
const optionList = [
|
|
31
|
-
{ name : 'sub-tag', type : String, description : '{green sub-tag to add to the image tag (required)}', defaultOption : true },
|
|
32
|
-
{ name : 'pg-version', type : String, description : '{green pgsql version (default: 16.6)}' },
|
|
33
|
-
{ name : 'version', type : Boolean, description : '{green show script version}' },
|
|
34
|
-
{ name : 'help', type : Boolean, description : '{green display this help screen}' },
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
const sections = [
|
|
38
|
-
{
|
|
39
|
-
header : 'Leverege CNPG Docker Image Builder',
|
|
40
|
-
content : `{green This tool will build a PostgreSQL based image that is suitable for
|
|
41
|
-
deployment by the CNPG operator. It builds the docker image by using an
|
|
42
|
-
official CNPG docker image as a base and added the jsquery and timescale
|
|
43
|
-
extensions for use within a Leverege k8s cluster. The resultant image may be
|
|
44
|
-
used in the standard PostgreSQL configuration which is used by the stack
|
|
45
|
-
components, as well as timescale based services like transponder tsdb and
|
|
46
|
-
dense history.}`
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
header : 'Options',
|
|
50
|
-
optionList
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
header : 'Leverege Registry Image Tag',
|
|
54
|
-
content : `{green The resultant image will be tagged with a label comprised of the PG version,
|
|
55
|
-
the specified --sub-tag and a fixed string:
|
|
56
|
-
|
|
57
|
-
{yellow <PG ver>-cnpg-lvrg-<sub tag>}
|
|
58
|
-
|
|
59
|
-
For example, version {yellow 16.6} with a sub tag of {yellow rel.1} will be tagged:
|
|
60
|
-
|
|
61
|
-
{yellow 16.6-cnpg-lvrg-rel.1}}`
|
|
62
|
-
},
|
|
63
|
-
]
|
|
64
|
-
const args = cliArgs( optionList, { camelCase : true, partial : true } )
|
|
65
|
-
const help = cliHelp( sections )
|
|
66
|
-
|
|
67
|
-
debug( { args, help }, '<==Command Line Info?' )
|
|
68
|
-
|
|
69
|
-
// Show help if needed
|
|
70
|
-
if ( args.help ) {
|
|
71
|
-
log( help )
|
|
72
|
-
process.exit( 0 )
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Define defaults
|
|
76
|
-
const PG_VERSION = args.pgVersion || '16.6'
|
|
77
|
-
const { subTag } = args
|
|
78
|
-
if ( !subTag ) {
|
|
79
|
-
errorExit( 'Error: An image version must be specified.' )
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const LEVEREGE_REGISTRY = 'us-docker.pkg.dev/leverege-registry/system/images/leverege-pgsql'
|
|
83
|
-
const LEVEREGE_IMAGE_TAG = `${PG_VERSION}-cnpg-lvrg-${subTag}`
|
|
84
|
-
const LEVEREGE_IMAGE_NAME_WITH_TAG = `${LEVEREGE_REGISTRY}:${LEVEREGE_IMAGE_TAG}`
|
|
85
|
-
|
|
86
|
-
const DOCKERFILE_TEMPLATE = `
|
|
87
|
-
FROM ghcr.io/cloudnative-pg/postgresql:{{PG_VERSION}}-bookworm
|
|
88
|
-
|
|
89
|
-
USER root
|
|
90
|
-
|
|
91
|
-
RUN set -xe; \\
|
|
92
|
-
apt-get update; \\
|
|
93
|
-
apt-get install -y --no-install-recommends \\
|
|
94
|
-
"postgresql-\${PG_MAJOR}-jsquery"; \\
|
|
95
|
-
rm -fr /tmp/*; \\
|
|
96
|
-
rm -rf /var/lib/apt/lists/*;
|
|
97
|
-
|
|
98
|
-
RUN apt-get update \\
|
|
99
|
-
&& apt-get install -y lsb-release wget \\
|
|
100
|
-
&& echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main" | tee /etc/apt/sources.list.d/timescaledb.list \\
|
|
101
|
-
&& wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add - \\
|
|
102
|
-
&& apt-get update \\
|
|
103
|
-
&& apt-get install -y "timescaledb-2-postgresql-\${PG_MAJOR}" \\
|
|
104
|
-
&& apt-get remove -y lsb-release wget \\
|
|
105
|
-
&& rm -fr /tmp/* \\
|
|
106
|
-
&& rm -rf /var/lib/apt/lists/*;
|
|
107
|
-
|
|
108
|
-
RUN usermod -u 26 postgres
|
|
109
|
-
USER 26
|
|
110
|
-
`
|
|
111
|
-
|
|
112
|
-
// Check for existing image
|
|
113
|
-
const checkExistingImage = async ( imageName ) => {
|
|
114
|
-
const dockerResults = await shellCmd( `docker image list ${imageName} --quiet` )
|
|
115
|
-
debug( { imageName, dockerResults }, '<==docker image list' )
|
|
116
|
-
return dockerResults
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Build and push Docker image
|
|
120
|
-
const buildAndPushImage = async () => {
|
|
121
|
-
const template = Handlebars.compile( DOCKERFILE_TEMPLATE )
|
|
122
|
-
const renderedDockerfile = template( { PG_VERSION } )
|
|
123
|
-
debug( { renderedDockerfile }, '<==Dockerfile' )
|
|
124
|
-
|
|
125
|
-
// Write the Dockerfile to a temporary location
|
|
126
|
-
const dockerfilePath = path.resolve( 'Dockerfile.temp' )
|
|
127
|
-
fs.writeFileSync( dockerfilePath, renderedDockerfile )
|
|
128
|
-
|
|
129
|
-
// Build the image
|
|
130
|
-
log( chalk.yellow( '\nBuilding Docker image...' ) )
|
|
131
|
-
await shellCmd( `docker build --file ${dockerfilePath} --tag ${LEVEREGE_IMAGE_NAME_WITH_TAG} .`, { stdio : 'inherit' } )
|
|
132
|
-
|
|
133
|
-
// Push the image
|
|
134
|
-
log( chalk.green( '\nPushing Docker image...' ) )
|
|
135
|
-
await shellCmd( `docker push ${LEVEREGE_IMAGE_NAME_WITH_TAG}`, { stdio : 'inherit' } )
|
|
136
|
-
|
|
137
|
-
// Clean up the temporary Dockerfile
|
|
138
|
-
fs.unlinkSync( dockerfilePath )
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Main execution flow
|
|
142
|
-
try {
|
|
143
|
-
if ( await checkExistingImage( LEVEREGE_IMAGE_NAME_WITH_TAG ) ) {
|
|
144
|
-
err(
|
|
145
|
-
`${chalk.red( '*** ERROR ***' )} The image already exists:\n` +
|
|
146
|
-
` Image : ${chalk.yellow( LEVEREGE_IMAGE_NAME_WITH_TAG )}\n` +
|
|
147
|
-
` Registry: ${chalk.green( LEVEREGE_REGISTRY )}\n` +
|
|
148
|
-
` Tag : ${chalk.green( LEVEREGE_IMAGE_TAG )}\n`
|
|
149
|
-
)
|
|
150
|
-
process.exit( 1 )
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
log( `${chalk.cyan( '\nAbout to build a new Docker image:\n' )}
|
|
154
|
-
PostgreSQL => ${chalk.green( PG_VERSION )}
|
|
155
|
-
Image Name => ${chalk.green( LEVEREGE_IMAGE_NAME_WITH_TAG )}\n` )
|
|
156
|
-
|
|
157
|
-
log( `Enter "${chalk.green( 'yes' )}" to proceed or anything else to exit.` )
|
|
158
|
-
const confirmation = await new Promise( ( resolve ) => {
|
|
159
|
-
process.stdin.once( 'data', data => resolve( data.toString().trim() ) )
|
|
160
|
-
} )
|
|
161
|
-
|
|
162
|
-
if ( confirmation !== 'yes' ) {
|
|
163
|
-
log( chalk.red( 'Aborted by user.' ) )
|
|
164
|
-
process.exit( 1 )
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
await buildAndPushImage()
|
|
168
|
-
log(
|
|
169
|
-
chalk.green( '\nImage built and successfully pushed - tagged => ' ) +
|
|
170
|
-
chalk.yellow( `${LEVEREGE_IMAGE_TAG}` )
|
|
171
|
-
)
|
|
172
|
-
process.exit( 0 )
|
|
173
|
-
} catch ( error ) {
|
|
174
|
-
err( chalk.red( 'An error occurred:' ), error.message )
|
|
175
|
-
process.exit( 1 )
|
|
176
|
-
}
|
package/src/chart-compass.mjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
/*
|
|
4
|
-
* chart-to-registry will...
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'node:fs'
|
|
7
|
-
|
|
8
|
-
import chalk from 'chalk'
|
|
9
|
-
import commandLineArgs from 'command-line-args'
|
|
10
|
-
import commandLineUsage from 'command-line-usage'
|
|
11
|
-
import { lt as semverLt } from 'semver'
|
|
12
|
-
import YAML from 'js-yaml'
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
condir,
|
|
16
|
-
debug,
|
|
17
|
-
errorExit,
|
|
18
|
-
log,
|
|
19
|
-
warning,
|
|
20
|
-
getGitRootDirectory,
|
|
21
|
-
parsePackageJson,
|
|
22
|
-
parseHelmChart,
|
|
23
|
-
shellCmd } from './Utils.mjs'
|
|
24
|
-
|
|
25
|
-
const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
name : 'location',
|
|
29
|
-
type : String,
|
|
30
|
-
description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name : 'project',
|
|
34
|
-
type : String,
|
|
35
|
-
description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name : 'repository',
|
|
39
|
-
type : String,
|
|
40
|
-
description : '{green the target repository to receive the pushed chart}',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name : 'dry-run',
|
|
44
|
-
type : Boolean,
|
|
45
|
-
description : '{yellow perform everything except the actual chart push}',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name : 'help',
|
|
49
|
-
type : Boolean,
|
|
50
|
-
description : '{green display this help screen}',
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
const sections = [
|
|
56
|
-
{
|
|
57
|
-
header : 'Leverege Helm Chart Compass (for helmup)',
|
|
58
|
-
content : `{green This tool helps helmup navigate the helm charts stored in the
|
|
59
|
-
artifact-registries.}`
|
|
60
|
-
},
|
|
61
|
-
{ header : 'Options',
|
|
62
|
-
optionList : commandLineOptions,
|
|
63
|
-
},
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
const args = commandLineArgs( commandLineOptions, { camelCase : true, partial : true } )
|
|
67
|
-
const usage = commandLineUsage( sections )
|
|
68
|
-
|
|
69
|
-
if ( args.help ) {
|
|
70
|
-
log( usage )
|
|
71
|
-
process.exit( 0 )
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* eslint-disable no-underscore-dangle */
|
|
75
|
-
if ( args._unknown ) {
|
|
76
|
-
log( usage )
|
|
77
|
-
log( `\nUnrecognized argument [${chalk.bold.red( args._unknown )}]\n` )
|
|
78
|
-
process.exit( 1 )
|
|
79
|
-
}
|
|
80
|
-
/* eslint-enable no-underscore-dangle */
|
|
81
|
-
|
|
82
|
-
const minNodejsVersion = '18.0.0'
|
|
83
|
-
if ( semverLt( process.version, minNodejsVersion ) ) {
|
|
84
|
-
errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// First of all, fail if we are not in a git repository
|
|
88
|
-
let gitRoot
|
|
89
|
-
try {
|
|
90
|
-
gitRoot = await getGitRootDirectory()
|
|
91
|
-
} catch ( error ) {
|
|
92
|
-
errorExit( chalk.red.bold( error ), { errorCode : 5 } )
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const chartCompass = YAML.load( fs.readFileSync( './registry-compass.yaml', 'utf8' ) )
|
|
96
|
-
|
|
97
|
-
condir( { chartCompass }, '<==Navigation' )
|