@leverege/build-tools 2.59.1 → 2.59.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 +1 -1
- package/src/circleate.sh +2 -0
- package/src/build-cnpg-image.mjs +0 -167
package/package.json
CHANGED
package/src/circleate.sh
CHANGED
|
@@ -120,6 +120,7 @@ jobs:
|
|
|
120
120
|
path: reports
|
|
121
121
|
|
|
122
122
|
docs:
|
|
123
|
+
circleci_ip_ranges: true
|
|
123
124
|
docker:
|
|
124
125
|
- image: $CIRCLE_NODE_IMG
|
|
125
126
|
steps:
|
|
@@ -339,6 +340,7 @@ jobs:
|
|
|
339
340
|
path: reports
|
|
340
341
|
|
|
341
342
|
docs:
|
|
343
|
+
circleci_ip_ranges: true
|
|
342
344
|
docker:
|
|
343
345
|
- image: $CIRCLE_NODE_IMG
|
|
344
346
|
steps:
|
package/src/build-cnpg-image.mjs
DELETED
|
@@ -1,167 +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 full registry image tag that is used for tagging the docker image in the artifact registry}`,
|
|
55
|
-
},
|
|
56
|
-
]
|
|
57
|
-
const args = cliArgs( optionList, { partial : true } )
|
|
58
|
-
const help = cliHelp( sections )
|
|
59
|
-
|
|
60
|
-
debug( { args, help }, '<==Command Line Info?' )
|
|
61
|
-
|
|
62
|
-
// Show help if needed
|
|
63
|
-
if ( args.help ) {
|
|
64
|
-
console.log( help )
|
|
65
|
-
process.exit( 0 )
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Define defaults
|
|
69
|
-
const PG_VERSION = args.pgVersion || '16.4'
|
|
70
|
-
const { subTag } = args
|
|
71
|
-
if ( !subTag ) {
|
|
72
|
-
errorExit( `Error: An image version must be specified.` )
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const LEVEREGE_REGISTRY = 'us-docker.pkg.dev/leverege-registry/system/images/leverege-pgsql'
|
|
76
|
-
const LEVEREGE_IMAGE_TAG = `${PG_VERSION}-cnpg-lvrg-${subTag}`
|
|
77
|
-
const LEVEREGE_IMAGE_NAME_WITH_TAG = `${LEVEREGE_REGISTRY}:${LEVEREGE_IMAGE_TAG}`
|
|
78
|
-
|
|
79
|
-
const DOCKERFILE_TEMPLATE = `
|
|
80
|
-
FROM ghcr.io/cloudnative-pg/postgresql:{{PG_VERSION}}-bookworm
|
|
81
|
-
|
|
82
|
-
USER root
|
|
83
|
-
|
|
84
|
-
RUN set -xe; \\
|
|
85
|
-
apt-get update; \\
|
|
86
|
-
apt-get install -y --no-install-recommends \\
|
|
87
|
-
"postgresql-\${PG_MAJOR}-jsquery"; \\
|
|
88
|
-
rm -fr /tmp/*; \\
|
|
89
|
-
rm -rf /var/lib/apt/lists/*;
|
|
90
|
-
|
|
91
|
-
RUN apt-get update \\
|
|
92
|
-
&& apt-get install -y lsb-release wget \\
|
|
93
|
-
&& echo "deb https://packagecloud.io/timescale/timescaledb/debian/ \$(lsb_release -c -s) main" | tee /etc/apt/sources.list.d/timescaledb.list \\
|
|
94
|
-
&& wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add - \\
|
|
95
|
-
&& apt-get update \\
|
|
96
|
-
&& apt-get install -y "timescaledb-2-postgresql-\${PG_MAJOR}" \\
|
|
97
|
-
&& apt-get remove -y lsb-release wget \\
|
|
98
|
-
&& rm -fr /tmp/* \\
|
|
99
|
-
&& rm -rf /var/lib/apt/lists/*;
|
|
100
|
-
|
|
101
|
-
RUN usermod -u 26 postgres
|
|
102
|
-
USER 26
|
|
103
|
-
`
|
|
104
|
-
|
|
105
|
-
// Check for existing image
|
|
106
|
-
const checkExistingImage = async ( imageName ) => {
|
|
107
|
-
const dockerResults= await shellCmd( `docker image list ${imageName} --quiet` )
|
|
108
|
-
debug( { imageName, dockerResults }, '<==docker image list' )
|
|
109
|
-
return dockerResults !== ''
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Build and push Docker image
|
|
113
|
-
const buildAndPushImage = async () => {
|
|
114
|
-
const template = Handlebars.compile( DOCKERFILE_TEMPLATE )
|
|
115
|
-
const renderedDockerfile = template( { PG_VERSION } )
|
|
116
|
-
debug( { renderedDockerfile }, '<==Dockerfile' )
|
|
117
|
-
|
|
118
|
-
// Write the Dockerfile to a temporary location
|
|
119
|
-
const dockerfilePath = path.resolve( 'Dockerfile.temp' )
|
|
120
|
-
fs.writeFileSync( dockerfilePath, renderedDockerfile )
|
|
121
|
-
|
|
122
|
-
// Build the image
|
|
123
|
-
console.log( chalk.yellow( 'Building Docker image...' ) )
|
|
124
|
-
await shellCmd( `docker build --file ${dockerfilePath} --tag ${LEVEREGE_IMAGE_NAME_WITH_TAG} .` )
|
|
125
|
-
|
|
126
|
-
// Push the image
|
|
127
|
-
console.log( chalk.green( 'Pushing Docker image...' ) )
|
|
128
|
-
await shellCmd( `docker push ${LEVEREGE_IMAGE_NAME_WITH_TAG}` )
|
|
129
|
-
|
|
130
|
-
// Clean up the temporary Dockerfile
|
|
131
|
-
fs.unlinkSync( dockerfilePath )
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Main execution flow
|
|
135
|
-
try {
|
|
136
|
-
if ( await checkExistingImage( LEVEREGE_IMAGE_NAME_WITH_TAG ) ) {
|
|
137
|
-
console.error(
|
|
138
|
-
`${chalk.red( '*** ERROR ***' )
|
|
139
|
-
} The image already exists:\n` +
|
|
140
|
-
` Image : ${chalk.yellow( LEVEREGE_IMAGE_NAME_WITH_TAG )}\n` +
|
|
141
|
-
` Registry: ${chalk.green( LEVEREGE_REGISTRY )}\n` +
|
|
142
|
-
` Tag : ${chalk.green( LEVEREGE_IMAGE_TAG )}\n`
|
|
143
|
-
)
|
|
144
|
-
process.exit( 1 )
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
console.log( `${chalk.cyan( 'About to build a new Docker image:\n' )
|
|
148
|
-
} PostgreSQL => ${chalk.green( PG_VERSION )}\n` +
|
|
149
|
-
` Image Name => ${chalk.green( LEVEREGE_IMAGE_NAME_WITH_TAG )}\n` )
|
|
150
|
-
|
|
151
|
-
console.log( `Enter "${chalk.green( 'yes' )}" to proceed or anything else to exit.` )
|
|
152
|
-
const confirmation = await new Promise( ( resolve ) => {
|
|
153
|
-
process.stdin.once( 'data', data => resolve( data.toString().trim() ) )
|
|
154
|
-
} )
|
|
155
|
-
|
|
156
|
-
if ( confirmation !== 'yes' ) {
|
|
157
|
-
console.log( chalk.red( 'Aborted by user.' ) )
|
|
158
|
-
process.exit( 1 )
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
await buildAndPushImage()
|
|
162
|
-
console.log( chalk.green( 'Docker image build and push completed successfully!' ) )
|
|
163
|
-
process.exit( 0 )
|
|
164
|
-
} catch ( error ) {
|
|
165
|
-
console.error( chalk.red( 'An error occurred:' ), error.message )
|
|
166
|
-
process.exit( 1 )
|
|
167
|
-
}
|