Skip to content

Commit 2a798f7

Browse files
NiccoloFeifcanovaigbartolini
committed
feat: introduce PostGIS extension container image (#5)
PostGIS container image: - Added a dedicated PostGIS extension image. - Automatically derives required OS dependencies by diffing the base minimal image against the additional libraries installed by PostGIS. - Added PostGIS-specific Chainsaw tests to validate that all PostGIS-related extensions can be successfully installed. Additional improvements: - Enabled manual dispatch of builds for a specific extension target. - Removed `update.yml` in favour of Renovate’s Deb datasource for retrieving PGDG packages. - Converted boilerplate files from JSON to HCL to support Renovate comments and provide better customisation of the default Bake target. - Added support for specifying a custom name for the target container image, allowing it to differ from the extension’s name. - Adapted `pgvector` to above changes. - Created `BUILD.md` with detailed instructions. - Created a `Makefile` for a controlled local image building experience. Closes #4 Signed-off-by: Niccolò Fei <[email protected]> Signed-off-by: Francesco Canovai <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Co-authored-by: Francesco Canovai <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]>
1 parent fe4e837 commit 2a798f7

20 files changed

+593
-156
lines changed

.github/workflows/bake.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ name: Build, test and publish extensions
22

33
on:
44
push:
5+
workflow_dispatch:
6+
inputs:
7+
extension_name:
8+
description: "The PostgreSQL extension to build (directory name)"
9+
required: true
10+
type: choice
11+
options:
12+
- pgvector
13+
- postgis
514

615
defaults:
716
run:
@@ -30,14 +39,21 @@ jobs:
3039
filters: |
3140
pgvector:
3241
- 'pgvector/**'
42+
postgis:
43+
- 'postgis/**'
3344
3445
# Compute a matrix containing the list of all extensions that have been modified
3546
- name: Compute matrix
3647
id: get-matrix
3748
env:
3849
# JSON array containing the extensions that have been changed
3950
EXTENSIONS_CHANGED: ${{ steps.filter.outputs.changes }}
51+
# Input Extension name
52+
INPUT_EXTENSION_NAME: ${{ github.event.inputs.extension_name }}
4053
run: |
54+
if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
55+
EXTENSIONS_CHANGED="[\"$INPUT_EXTENSION_NAME\"]"
56+
fi
4157
echo "{\"name\": $EXTENSIONS_CHANGED}" > matrix.json
4258
echo "matrix=$(cat matrix.json)" >> "$GITHUB_OUTPUT"
4359
@@ -54,7 +70,6 @@ jobs:
5470
matrix: ${{ fromJSON(needs.change-triage.outputs.matrix) }}
5571
uses: ./.github/workflows/bake_targets.yml
5672
with:
57-
environment: ${{ (github.ref == 'refs/heads/main') && 'production' || 'testing'}}
5873
extension_name: ${{ matrix.name }}
5974
secrets:
6075
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

.github/workflows/bake_targets.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ name: Build, test and publish a target extension
33
on:
44
workflow_call:
55
inputs:
6-
environment:
7-
description: "Target environment for the image build (e.g. testing, production)."
8-
required: true
9-
type: string
10-
default: "testing"
116
extension_name:
127
description: "The PostgreSQL extension to build (directory name)"
138
required: true
@@ -59,7 +54,7 @@ jobs:
5954
registry: ghcr.io/${{ github.repository_owner }}
6055
revision: ${{ github.sha }}
6156
with:
62-
files: ./${{ inputs.extension_name }}/metadata.json,./docker-bake.hcl
57+
files: ./${{ inputs.extension_name }}/metadata.hcl,./docker-bake.hcl
6358
push: true
6459

6560
# From bake's metadata, extract each unique tag (e.g. the ones with the timestamp)
@@ -93,6 +88,7 @@ jobs:
9388
needs:
9489
- testbuild
9590
strategy:
91+
fail-fast: false
9692
matrix:
9793
image: ${{fromJson(needs.testbuild.outputs.images)}}
9894
steps:
@@ -119,6 +115,7 @@ jobs:
119115
needs:
120116
- testbuild
121117
strategy:
118+
fail-fast: false
122119
matrix:
123120
image: ${{fromJson(needs.testbuild.outputs.images)}}
124121
cnpg: ["main", "1.27"]
@@ -133,6 +130,12 @@ jobs:
133130
with:
134131
persist-credentials: false
135132

133+
- name: Install Go
134+
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
135+
with:
136+
cache: false
137+
go-version: 'stable'
138+
136139
- name: Create kind cluster
137140
uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0
138141
with:
@@ -158,16 +161,17 @@ jobs:
158161
EXT_IMAGE: ${{ matrix.image }}
159162
run: |
160163
# Get the PG base image
161-
PG_IMAGE=$(skopeo inspect "docker://$EXT_IMAGE" -f '{{ json .Labels }}' | jq -r '."io.cloudnativepg.image.base.name"')
164+
export PG_IMAGE=$(skopeo inspect "docker://$EXT_IMAGE" -f '{{ json .Labels }}' | jq -r '."io.cloudnativepg.image.base.name"')
162165
163-
# Merge metadata.json with runtime values to generate Chainsaw values.yaml
164-
jq --arg ext_image "$EXT_IMAGE" \
165-
--arg pg_image "$PG_IMAGE" \
166-
'.metadata + { extension_image: $ext_image, pg_image: $pg_image }' \
167-
"$EXT_NAME/metadata.json" > "$EXT_NAME/values.json"
166+
go install github.com/tmccombs/[email protected]
167+
go install github.com/mikefarah/yq/v4@v4
168168
169-
# Convert to YAML
170-
yq -p json -o yaml "$EXT_NAME/values.json" > "$EXT_NAME/values.yaml"
169+
# Convert metadata.hcl to YAML and merge it with runtime values to generate a valid Chainsaw values.yaml
170+
yq eval -P '
171+
.metadata.extension_image = strenv(EXT_IMAGE) |
172+
.metadata.pg_image = strenv(PG_IMAGE) |
173+
.metadata
174+
' <(hcl2json "$EXT_NAME/metadata.hcl") > "$EXT_NAME/values.yaml"
171175
cat "$EXT_NAME/values.yaml"
172176
173177
- name: Install Chainsaw
@@ -187,9 +191,7 @@ jobs:
187191
188192
copytoproduction:
189193
name: Copy images to production
190-
if: |
191-
github.ref == 'refs/heads/main' &&
192-
( github.event.inputs.environment == 'production' || github.event_name == 'schedule' )
194+
if: ${{ github.ref == 'refs/heads/main' }}
193195
runs-on: ubuntu-24.04
194196
needs:
195197
- testbuild

.github/workflows/update.yml

Lines changed: 0 additions & 114 deletions
This file was deleted.

BUILD.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Building Postgres Extensions Container Images for CloudNativePG
2+
3+
This guide explains how to build Postgres extensions operand images for
4+
[CloudNativePG](https://cloudnative-pg.io) using
5+
[Docker Bake](https://docs.docker.com/build/bake/) together with a
6+
[GitHub Actions workflow](.github/workflows/bake.yml).
7+
8+
Although it is not necessary, we recommend you use
9+
[GNU Make](https://www.gnu.org/software/make/) to build the images locally as
10+
outlined below.
11+
12+
## Prerequisites
13+
14+
Before you begin, ensure that you have met the following
15+
[prerequisites](https://github.com/cloudnative-pg/postgres-containers/blob/main/BUILD.md#prerequisites),
16+
which primarily include:
17+
18+
1. **Docker:** Must be installed and running.
19+
2. **Docker Command Line:** The `docker` command must be executable.
20+
3. **Docker Buildx:** The `docker buildx` plugin must be available.
21+
4. **Docker Context:** A valid Docker context must be configured.
22+
23+
---
24+
25+
## Usage and Targets
26+
27+
The `Makefile` dynamically discovers all subdirectories that contain a
28+
`metadata.hcl` file (e.g., `./pgvector/metadata.hcl`) and creates individual
29+
build targets for each project.
30+
31+
### 1. Check prerequisites only
32+
33+
To verify that Docker and Buildx are correctly installed and configured:
34+
35+
```bash
36+
make prereqs
37+
```
38+
39+
### 2. Build configuration check (dry run)
40+
41+
To verify the configuration (running `docker buildx bake --check`) for all
42+
projects without building or pulling layers:
43+
44+
```bash
45+
make check
46+
```
47+
48+
### 3. Build all projects
49+
50+
To check prerequisites and build all discovered projects:
51+
52+
```bash
53+
make
54+
# or
55+
make all
56+
```
57+
58+
### 4. Build a specific project
59+
60+
To build a single project (e.g., the directory named `pgvector`):
61+
62+
```bash
63+
make pgvector
64+
```
65+
66+
### 5. Push all images
67+
68+
To build all images and immediately push them to the configured registry:
69+
70+
```bash
71+
make push
72+
```
73+
74+
### 6. Push images for a specific project
75+
76+
To push images for a single project (e.g., the directory named `pgvector`):
77+
78+
```bash
79+
make push-pgvector
80+
```
81+
82+
### 7. Dry run mode
83+
84+
To see the commands that would be executed without running the actual `docker
85+
buildx bake` command, set the `DRY_RUN` flag:
86+
87+
```bash
88+
make DRY_RUN=true
89+
# or
90+
make pgvector DRY_RUN=true
91+
```

0 commit comments

Comments
 (0)