Skip to content

Commit 70af938

Browse files
committed
feat: add PostGIS
Signed-off-by: Niccolò Fei <[email protected]>
1 parent fe4e837 commit 70af938

File tree

7 files changed

+85
-3
lines changed

7 files changed

+85
-3
lines changed

.github/workflows/bake.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
filters: |
3131
pgvector:
3232
- 'pgvector/**'
33+
postgis:
34+
- 'postgis/**'
3335
3436
# Compute a matrix containing the list of all extensions that have been modified
3537
- name: Compute matrix

.github/workflows/update.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ jobs:
4747
steps:
4848
- name: Checkout repository
4949
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
50-
with:
51-
persist-credentials: false
5250

5351
- name: Fetch latest extension versions
5452
id: fetch_versions
@@ -61,11 +59,17 @@ jobs:
6159
readarray -t POSTGRES_MAJORS < <(sed -n '/variable "pgVersions"/,/]/ { s/^[[:space:]]*"\([^"]*\)".*/\1/p }' docker-bake.hcl)
6260
# Get the extension name
6361
EXT_NAME=$(jq -r '.metadata.name' "$EXTENSION_NAME/metadata.json")
62+
# Get the extension major version
63+
EXT_MAJOR=$(jq -r '.metadata.major_version' "$EXTENSION_NAME/metadata.json")
6464
6565
for DISTRO in "${DISTROS[@]}"; do
6666
for MAJOR in "${POSTGRES_MAJORS[@]}"; do
67+
PKG="postgresql-${MAJOR}-${EXT_NAME}"
68+
if [[ -n "$EXT_MAJOR" ]] && [[ "$EXT_MAJOR" != "null" ]]; then
69+
PKG="postgresql-${MAJOR}-${EXT_NAME}-${EXT_MAJOR}"
70+
fi
6771
VERSION=$(curl -s "https://apt.postgresql.org/pub/repos/apt/dists/$DISTRO-pgdg/main/binary-amd64/Packages" \
68-
| awk -v pkg="postgresql-${MAJOR}-${EXT_NAME}" '
72+
| awk -v pkg="${PKG}" '
6973
$1 == "Package:" && $2 == pkg {show=1; next}
7074
show && $1 == "Version:" {print $2; show=0}
7175
' \

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ in CloudNativePG.
2121
## Supported Extensions
2222

2323
- [pgvector](pgvector) - Open-source vector similarity search for PostgreSQL
24+
- [pgvector](postgis) - Open-source geospatial database extension for PostgreSQL
2425

2526
---
2627

docker-bake.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ target "default" {
5656
args = {
5757
PG_MAJOR = "${pgVersion}"
5858
EXT_VERSION = "${getExtensionPackage(distro, pgVersion)}"
59+
EXT_MAJOR = "${metadata.major_version}"
5960
BASE = "${getBaseImage(distro, pgVersion)}"
6061
}
6162

postgis/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
2+
FROM $BASE AS builder
3+
4+
ARG PG_MAJOR
5+
ARG EXT_VERSION
6+
ARG EXT_MAJOR
7+
8+
USER 0
9+
10+
RUN set -eux && \
11+
# Initial system libraries
12+
ldconfig -p | awk '{print $NF}' | grep '^/' | sort | uniq > /tmp/base-image-libs.out && \
13+
# Install PostGIS
14+
apt-get update && \
15+
apt-get install -y --no-install-recommends "postgresql-${PG_MAJOR}-postgis-${EXT_MAJOR}=${EXT_VERSION}"
16+
17+
# Gather PostGIS system libraries and their licenses
18+
RUN mkdir -p /system /licenses && \
19+
# Get libraries
20+
ldd /usr/lib/postgresql/${PG_MAJOR}/lib/address_standardizer*.so \
21+
/usr/lib/postgresql/${PG_MAJOR}/lib/postgis*.so \
22+
| awk '{print $3}' | grep '^/' | sort | uniq > /tmp/all-deps.out && \
23+
comm -13 /tmp/base-image-libs.out /tmp/all-deps.out > /tmp/libraries.out && \
24+
for lib in $(cat /tmp/libraries.out); do cp -a "${lib%.so*}.so"* /system; done && \
25+
# Get licenses
26+
for lib in $(find /system -maxdepth 1 -type f -name '*.so*'); do \
27+
pkg=$(dpkg -S "$(basename "$lib")" | awk -F: '{print $1}'); \
28+
[ -z "$pkg" ] && continue; \
29+
mkdir -p "/licenses/$pkg" && cp -a /usr/share/doc/"$pkg"/* "/licenses/$pkg/"; \
30+
done
31+
32+
33+
FROM scratch
34+
ARG PG_MAJOR
35+
ARG EXT_MAJOR
36+
37+
# Licenses
38+
COPY --from=builder /licenses /licenses/
39+
COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-postgis-${EXT_MAJOR}/copyright /licenses/postgresql-${PG_MAJOR}-postgis-${EXT_MAJOR}/
40+
41+
# Libraries
42+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/address_standardizer* /usr/lib/postgresql/${PG_MAJOR}/lib/postgis* /lib/
43+
COPY --from=builder /usr/lib/postgresql/18/lib/bitcode/ /lib/bitcode/
44+
45+
# Share
46+
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/address_standardizer* /usr/share/postgresql/${PG_MAJOR}/extension/postgis* /share/extension/
47+
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/contrib/postgis* /share/contrib/
48+
49+
# System libs
50+
COPY --from=builder /system /system/
51+
52+
USER 65532:65532

postgis/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PostGIS
2+
3+
TODO

postgis/metadata.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"metadata": {
3+
"name": "postgis",
4+
"sql_name": "postgis",
5+
"shared_preload_libraries": [],
6+
"extension_control_path": [],
7+
"dynamic_library_path": [],
8+
"ld_library_path": ["/system"],
9+
"major_version": "3",
10+
"versions": {
11+
"bookworm": {
12+
"18": "3.6.0+dfsg-3.pgdg12+1"
13+
},
14+
"trixie": {
15+
"18": "3.6.0+dfsg-3.pgdg13+1"
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)