From 89cca0e865d2d53f5ef70bbe8e65530413590432 Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 20 Nov 2026 04:49:34 +0100 Subject: [PATCH 1/5] feat(image): build postgis and pgvector on the official alpine image --- .dockerignore | 4 ++ .editorconfig | 13 ++++ .github/FUNDING.yml | 12 ++++ .github/semantic.yml | 5 ++ .github/smoke-test.sh | 47 ++++++++++++++ .github/workflows/ci.yml | 57 +++++++++++++++++ .github/workflows/ghcr-cleanup.yml | 21 +++++++ .github/workflows/image-scan.yml | 18 ++++++ .gitignore | 3 + .releaserc.json | 28 +++++++++ .renovaterc.json | 30 +++++++++ .vscode/extensions.json | 3 + .vscode/settings.json | 8 +++ AGENTS.md | 20 ++++++ CODEOWNERS | 1 + Dockerfile | 80 ++++++++++++++++++++++++ README.md | 14 +++++ docker-entrypoint-initdb.d/10_postgis.sh | 8 +++ package.json | 12 ++++ 19 files changed, 384 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .github/FUNDING.yml create mode 100644 .github/semantic.yml create mode 100755 .github/smoke-test.sh create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ghcr-cleanup.yml create mode 100644 .github/workflows/image-scan.yml create mode 100644 .gitignore create mode 100644 .releaserc.json create mode 100644 .renovaterc.json create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 AGENTS.md create mode 100644 CODEOWNERS create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 docker-entrypoint-initdb.d/10_postgis.sh create mode 100644 package.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fd16d73 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.claude +.git +.github +.worktrees diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5d12634 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..f78d206 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: [dargmuesli] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 0000000..40b6927 --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,5 @@ +# Always validate the PR title AND all the commits +titleAndCommits: true +# Allows use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns") +# this is only relevant when using commitsOnly: true (or titleAndCommits: true) +allowMergeCommits: true diff --git a/.github/smoke-test.sh b/.github/smoke-test.sh new file mode 100755 index 0000000..8eba0ee --- /dev/null +++ b/.github/smoke-test.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +IMAGE="${SMOKE_TEST_IMAGE:?SMOKE_TEST_IMAGE not set}" +CONTAINER="smoke-postgres-${GITHUB_RUN_ID:-$$}-${GITHUB_RUN_ATTEMPT:-1}" + +trap 'docker rm --force "$CONTAINER" >/dev/null 2>&1 || true' EXIT + +docker run --detach --name "$CONTAINER" \ + -e POSTGRES_DB=smoke \ + -e POSTGRES_PASSWORD=postgres \ + "$IMAGE" + +query() { + docker exec "$CONTAINER" psql -U postgres -d smoke -v ON_ERROR_STOP=1 -tAc "$1" +} + +# The entrypoint serves init scripts from a temporary server first, so only a query on the final server proves readiness. +for i in $(seq 1 60); do + if docker logs "$CONTAINER" 2>&1 | grep -q 'PostgreSQL init process complete' && query 'SELECT 1' >/dev/null 2>&1; then + echo "PostgreSQL is ready after ${i}s" + break + fi + sleep 1 +done + +fail() { + echo "$1" + docker logs "$CONTAINER" + exit 1 +} + +EXTENSIONS="$(query "SELECT string_agg(extname, ',' ORDER BY extname) FROM pg_extension")" +echo "Extensions created on init: $EXTENSIONS" +[ "$EXTENSIONS" = 'plpgsql,postgis,postgis_topology' ] || fail 'Expected PostGIS and its topology to be created on init' + +query 'CREATE EXTENSION vector' >/dev/null || fail 'pgvector is not installed' + +DISTANCE="$(query "SELECT round(ST_Distance(ST_Point(9.48, 51.31, 4326)::geography, ST_Point(11.58, 48.14, 4326)::geography) / 1000)")" +echo "Distance from Kassel to Munich: ${DISTANCE} km" +[ "$DISTANCE" = '384' ] || fail 'Unexpected geography distance' + +VECTOR_DISTANCE="$(query "SELECT '[1,2]'::vector <-> '[2,2]'::vector")" +echo "Vector distance: $VECTOR_DISTANCE" +[ "$VECTOR_DISTANCE" = '1' ] || fail 'Unexpected vector distance' + +echo "Smoke test passed." diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7f1c173 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +permissions: {} + +on: + pull_request: + push: + branches: + - alpha + - beta + - main + - renovate/** + +# Release branches queue instead of being cancelled, so a release never stops halfway. +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ !contains(fromJSON('["refs/heads/alpha", "refs/heads/beta", "refs/heads/main"]'), github.ref) }} + +jobs: + ci-optimization: + name: CI optimization + uses: dargmuesli/github-actions/.github/workflows/ci-optimization.yml@66040b4567381bad6e0b9a68caa17643e1d365bd # 5.10.0 + permissions: + pull-requests: read + release_semantic_dry: + needs: ci-optimization + if: needs.ci-optimization.outputs.continue == 'true' + name: Release (semantic, dry) + uses: dargmuesli/github-actions/.github/workflows/release-semantic.yml@66040b4567381bad6e0b9a68caa17643e1d365bd # 5.10.0 + permissions: + contents: write + id-token: write + secrets: + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + with: + DRY_RUN: true + build: + needs: release_semantic_dry + name: Build + uses: dargmuesli/github-actions/.github/workflows/docker.yml@66040b4567381bad6e0b9a68caa17643e1d365bd # 5.10.0 + permissions: + attestations: write + id-token: write + packages: write + with: + PLATFORMS: linux/amd64,linux/arm64 + SMOKE_TEST_SCRIPT: .github/smoke-test.sh + TAG: ${{ needs.release_semantic_dry.outputs.new_release_version }} + release_semantic: + needs: build + name: Release (semantic) + uses: dargmuesli/github-actions/.github/workflows/release-semantic.yml@66040b4567381bad6e0b9a68caa17643e1d365bd # 5.10.0 + permissions: + contents: write + id-token: write + secrets: + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} diff --git a/.github/workflows/ghcr-cleanup.yml b/.github/workflows/ghcr-cleanup.yml new file mode 100644 index 0000000..01876ef --- /dev/null +++ b/.github/workflows/ghcr-cleanup.yml @@ -0,0 +1,21 @@ +name: GHCR Cleanup + +permissions: {} + +on: + schedule: + - cron: "0 1 * * 0" # Every Sunday at 01:00 AM UTC + workflow_dispatch: + inputs: + DRY_RUN: + default: true + type: boolean + +jobs: + ghcr-cleanup: + name: GHCR cleanup + uses: dargmuesli/github-actions/.github/workflows/ghcr-cleanup.yml@66040b4567381bad6e0b9a68caa17643e1d365bd # 5.10.0 + permissions: + packages: write + with: + DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.DRY_RUN }} diff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.yml new file mode 100644 index 0000000..0d7fa1a --- /dev/null +++ b/.github/workflows/image-scan.yml @@ -0,0 +1,18 @@ +name: Image scan + +permissions: {} + +on: + schedule: + - cron: "0 4 * * *" # Every day at 04:00 AM UTC on the default branch + workflow_dispatch: + +jobs: + image-scan: + name: Image scan + uses: dargmuesli/github-actions/.github/workflows/image-scan.yml@ab8e226263168a9aab8c98d6db89ce707f77497e # 5.11.0 + permissions: + contents: read + packages: read + secrets: + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a34baa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.claude +.worktrees +node_modules diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..342931f --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,28 @@ +{ + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "presetConfig": {} + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": {} + } + ], + "@semantic-release/changelog", + [ + "@semantic-release/exec", + { + "prepareCmd": "pnpm version ${nextRelease.version} --no-git-tag-version --no-git-checks" + } + ], + "@semantic-release/github", + "@semantic-release/git" + ], + "tagFormat": "${version}" +} diff --git a/.renovaterc.json b/.renovaterc.json new file mode 100644 index 0000000..7ae1a5e --- /dev/null +++ b/.renovaterc.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "customManagers": [ + { + "customType": "regex", + "datasourceTemplate": "github-tags", + "managerFilePatterns": [ + "/^Dockerfile$/" + ], + "matchStrings": [ + "#\\s+renovate:\\s+datasource=github-tags\\s+depName=(?\\S+)\\s+ENV\\s+\\S+_VERSION=(?\\S+)" + ] + } + ], + "extends": [ + "github>dargmuesli/renovate-config" + ], + "packageRules": [ + { + "allowedVersions": "<19", + "matchDatasources": [ + "docker" + ], + "matchPackageNames": [ + "postgres" + ] + } + ], + "semanticCommitType": "fix" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..9c4b1cc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["editorconfig.editorconfig"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..629d9cb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } +} diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..4ed49ba --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,20 @@ +--- +applyTo: '**' +--- + +# Project Instructions + +This project builds the PostgreSQL container image of `vibetype`, an event community platform, for the `postgres` and `reccoom-postgres` services of the `stack` repository. + +## Image + +- PostGIS and pgvector are compiled from source in the `build` stage, as `postgis/postgis` publishes no arm64 image + - The PostGIS build follows the upstream Alpine Dockerfile at https://github.com/postgis/docker-postgis, so compare against it when PostGIS updates + - pgvector is built with an empty `OPTFLAGS`, as the default `-march=native` would tie the image to the build machine's CPU +- The base stays on Alpine, as a switch to a glibc based image changes the collation of existing databases, which invalidates their text indexes +- The PostgreSQL major stays at 18, as a new major needs a `pg_upgrade` of every deployed database; Renovate is limited accordingly +- A new database gets `postgis` and `postgis_topology` from `docker-entrypoint-initdb.d`, as `sqitch` migrations expect PostGIS to exist + +## Verification + +- `.github/smoke-test.sh` runs in CI against the built image and checks the extensions; extend it when the image gains a feature diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..b5cafd7 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @dargmuesli diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b06e362 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,80 @@ +# syntax=docker/dockerfile:1 + +# PostGIS is compiled here instead of using `postgis/postgis`, which publishes no arm64 image. +# The build follows https://github.com/postgis/docker-postgis/blob/master/18-3.7/alpine/Dockerfile, without its regression tests. + +######################## +# Provide the base. + +FROM postgres:18.7-alpine3.24@sha256:ff64c9e3bdf8e2120107d3559de8db314e8305f7e38c5105903c6295876738ff AS base + + +######################## +# Compile the extensions. + +FROM base AS build + +# renovate: datasource=github-tags depName=postgis/postgis +ENV POSTGIS_VERSION=3.7.0 +# renovate: datasource=github-tags depName=pgvector/pgvector +ENV PGVECTOR_VERSION=v0.8.7 + +ADD https://github.com/postgis/postgis.git#${POSTGIS_VERSION} /usr/src/postgis +ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_VERSION} /usr/src/pgvector + +# `DOCKER_PG_LLVM_DEPS` names the clang and llvm versions that the base image's PostgreSQL was built with, which its JIT bitcode needs. +RUN apk add --no-cache \ + $DOCKER_PG_LLVM_DEPS \ + autoconf \ + automake \ + file \ + g++ \ + gcc \ + gdal-dev \ + geos-dev \ + gettext-dev \ + gmp-dev \ + json-c-dev \ + libtool \ + libxml2-dev \ + make \ + pcre2-dev \ + perl \ + proj-dev \ + protobuf-c-dev \ + sfcgal-dev + +WORKDIR /usr/src/postgis + +RUN gettextize \ + && ./autogen.sh \ + && ./configure --enable-lto \ + && make -j"$(nproc)" \ + && make install DESTDIR=/srv/extensions + +WORKDIR /usr/src/pgvector + +# An empty `OPTFLAGS` drops `-march=native`, which would tie the build to the CPU of the machine building it. +RUN make OPTFLAGS="" \ + && make install DESTDIR=/srv/extensions + + +######################## +# Serve the database. + +FROM base AS production + +RUN apk add --no-cache \ + ca-certificates \ + gdal \ + geos \ + gmp \ + json-c \ + libstdc++ \ + pcre2 \ + proj \ + protobuf-c \ + sfcgal + +COPY --from=build /srv/extensions/usr/local /usr/local +COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1018194 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# postgres + +Vibetype's PostgreSQL container image, which adds [PostGIS](https://postgis.net/) and [pgvector](https://github.com/pgvector/pgvector) to the official [`postgres`](https://hub.docker.com/_/postgres) Alpine image. +It is published for `linux/amd64` and `linux/arm64` as `ghcr.io/maevsi/postgres`. + +## Usage + +The image is configured like the official `postgres` image. +A new database starts with the `postgis` and `postgis_topology` extensions, like with `postgis/postgis`. +pgvector is installed but not created, so a database that needs it runs `CREATE EXTENSION vector`. + +## Development + +Build the image with `docker build -t postgres .` and test it with `SMOKE_TEST_IMAGE=postgres .github/smoke-test.sh`. diff --git a/docker-entrypoint-initdb.d/10_postgis.sh b/docker-entrypoint-initdb.d/10_postgis.sh new file mode 100755 index 0000000..f8b2f82 --- /dev/null +++ b/docker-entrypoint-initdb.d/10_postgis.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +# Like `postgis/postgis`, a new database starts with PostGIS, which migrations expect to exist already. +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS postgis; + CREATE EXTENSION IF NOT EXISTS postgis_topology; +EOSQL diff --git a/package.json b/package.json new file mode 100644 index 0000000..7c3a229 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "devEngines": { + "packageManager": { + "name": "pnpm", + "version": "12.21.0" + } + }, + "name": "@maevsi/postgres", + "private": true, + "type": "module", + "version": "0.0.0-development" +} From f310ad6ba0a7435552b4f7db2fe1d4f90f58a78c Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 20 Nov 2026 06:07:19 +0100 Subject: [PATCH 2/5] feat(image): install the extensions from the postgresql apt repository on debian --- .github/workflows/ci.yml | 3 ++ .releaserc.json | 6 --- .renovaterc.json | 17 ++------ AGENTS.md | 14 ++++--- Dockerfile | 83 ++++------------------------------------ README.md | 2 +- package.json | 12 ------ 7 files changed, 25 insertions(+), 112 deletions(-) delete mode 100644 package.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f1c173..81c3e42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} with: DRY_RUN: true + PACKAGE_MANAGER: npm build: needs: release_semantic_dry name: Build @@ -55,3 +56,5 @@ jobs: id-token: write secrets: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + with: + PACKAGE_MANAGER: npm diff --git a/.releaserc.json b/.releaserc.json index 342931f..e7e56b9 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -15,12 +15,6 @@ } ], "@semantic-release/changelog", - [ - "@semantic-release/exec", - { - "prepareCmd": "pnpm version ${nextRelease.version} --no-git-tag-version --no-git-checks" - } - ], "@semantic-release/github", "@semantic-release/git" ], diff --git a/.renovaterc.json b/.renovaterc.json index 7ae1a5e..46e74bd 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -1,28 +1,19 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "customManagers": [ - { - "customType": "regex", - "datasourceTemplate": "github-tags", - "managerFilePatterns": [ - "/^Dockerfile$/" - ], - "matchStrings": [ - "#\\s+renovate:\\s+datasource=github-tags\\s+depName=(?\\S+)\\s+ENV\\s+\\S+_VERSION=(?\\S+)" - ] - } - ], "extends": [ "github>dargmuesli/renovate-config" ], "packageRules": [ { - "allowedVersions": "<19", + "automerge": false, "matchDatasources": [ "docker" ], "matchPackageNames": [ "postgres" + ], + "matchUpdateTypes": [ + "major" ] } ], diff --git a/AGENTS.md b/AGENTS.md index 4ed49ba..3c93047 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,13 +8,17 @@ This project builds the PostgreSQL container image of `vibetype`, an event commu ## Image -- PostGIS and pgvector are compiled from source in the `build` stage, as `postgis/postgis` publishes no arm64 image - - The PostGIS build follows the upstream Alpine Dockerfile at https://github.com/postgis/docker-postgis, so compare against it when PostGIS updates - - pgvector is built with an empty `OPTFLAGS`, as the default `-march=native` would tie the image to the build machine's CPU -- The base stays on Alpine, as a switch to a glibc based image changes the collation of existing databases, which invalidates their text indexes -- The PostgreSQL major stays at 18, as a new major needs a `pg_upgrade` of every deployed database; Renovate is limited accordingly +- PostGIS and pgvector come as packages from the PostgreSQL project's apt repository, which the official Debian based `postgres` image already configures and which builds them for amd64 and arm64 + - The package names follow the base image's `PG_MAJOR`, so a new major installs the matching extensions + - Their versions follow the repository at build time, so a rebuild can bring a newer PostGIS, after which a database needs `ALTER EXTENSION postgis UPDATE` +- A new PostgreSQL major needs a `pg_upgrade` of every deployed database, so Renovate opens such updates without merging them automatically +- The base stays on Debian: a switch of the C library, as to Alpine, changes the collation of existing databases, which invalidates their text indexes - A new database gets `postgis` and `postgis_topology` from `docker-entrypoint-initdb.d`, as `sqitch` migrations expect PostGIS to exist +## Release + +- semantic-release versions the image from git tags alone, so the repository has no `package.json` + ## Verification - `.github/smoke-test.sh` runs in CI against the built image and checks the extensions; extend it when the image gains a feature diff --git a/Dockerfile b/Dockerfile index b06e362..f62a1b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,80 +1,13 @@ # syntax=docker/dockerfile:1 -# PostGIS is compiled here instead of using `postgis/postgis`, which publishes no arm64 image. -# The build follows https://github.com/postgis/docker-postgis/blob/master/18-3.7/alpine/Dockerfile, without its regression tests. +FROM postgres:18.7-trixie@sha256:eb63372c1e05c755f55fa30cbd07aecc443676fc6c0fa90b9002d01537841e1a AS production -######################## -# Provide the base. +# The base image ships the PostgreSQL project's apt repository, which builds both extensions for every architecture. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + "postgresql-${PG_MAJOR}-pgvector" \ + "postgresql-${PG_MAJOR}-postgis-3" \ + "postgresql-${PG_MAJOR}-postgis-3-scripts" \ + && rm -rf /var/lib/apt/lists/* -FROM postgres:18.7-alpine3.24@sha256:ff64c9e3bdf8e2120107d3559de8db314e8305f7e38c5105903c6295876738ff AS base - - -######################## -# Compile the extensions. - -FROM base AS build - -# renovate: datasource=github-tags depName=postgis/postgis -ENV POSTGIS_VERSION=3.7.0 -# renovate: datasource=github-tags depName=pgvector/pgvector -ENV PGVECTOR_VERSION=v0.8.7 - -ADD https://github.com/postgis/postgis.git#${POSTGIS_VERSION} /usr/src/postgis -ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_VERSION} /usr/src/pgvector - -# `DOCKER_PG_LLVM_DEPS` names the clang and llvm versions that the base image's PostgreSQL was built with, which its JIT bitcode needs. -RUN apk add --no-cache \ - $DOCKER_PG_LLVM_DEPS \ - autoconf \ - automake \ - file \ - g++ \ - gcc \ - gdal-dev \ - geos-dev \ - gettext-dev \ - gmp-dev \ - json-c-dev \ - libtool \ - libxml2-dev \ - make \ - pcre2-dev \ - perl \ - proj-dev \ - protobuf-c-dev \ - sfcgal-dev - -WORKDIR /usr/src/postgis - -RUN gettextize \ - && ./autogen.sh \ - && ./configure --enable-lto \ - && make -j"$(nproc)" \ - && make install DESTDIR=/srv/extensions - -WORKDIR /usr/src/pgvector - -# An empty `OPTFLAGS` drops `-march=native`, which would tie the build to the CPU of the machine building it. -RUN make OPTFLAGS="" \ - && make install DESTDIR=/srv/extensions - - -######################## -# Serve the database. - -FROM base AS production - -RUN apk add --no-cache \ - ca-certificates \ - gdal \ - geos \ - gmp \ - json-c \ - libstdc++ \ - pcre2 \ - proj \ - protobuf-c \ - sfcgal - -COPY --from=build /srv/extensions/usr/local /usr/local COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md index 1018194..b45be63 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # postgres -Vibetype's PostgreSQL container image, which adds [PostGIS](https://postgis.net/) and [pgvector](https://github.com/pgvector/pgvector) to the official [`postgres`](https://hub.docker.com/_/postgres) Alpine image. +Vibetype's PostgreSQL container image, which adds [PostGIS](https://postgis.net/) and [pgvector](https://github.com/pgvector/pgvector) to the official Debian based [`postgres`](https://hub.docker.com/_/postgres) image. It is published for `linux/amd64` and `linux/arm64` as `ghcr.io/maevsi/postgres`. ## Usage diff --git a/package.json b/package.json deleted file mode 100644 index 7c3a229..0000000 --- a/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "devEngines": { - "packageManager": { - "name": "pnpm", - "version": "12.21.0" - } - }, - "name": "@maevsi/postgres", - "private": true, - "type": "module", - "version": "0.0.0-development" -} From 3966ffce23fb0d794a37d5201f0c7bb629bd2af3 Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 20 Nov 2026 07:08:57 +0100 Subject: [PATCH 3/5] feat(image): return to the compiled alpine build --- .renovaterc.json | 37 ++++++++++++++------- AGENTS.md | 15 ++++++--- Dockerfile | 83 +++++++++++++++++++++++++++++++++++++++++++----- README.md | 2 +- 4 files changed, 112 insertions(+), 25 deletions(-) diff --git a/.renovaterc.json b/.renovaterc.json index 46e74bd..e111d28 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -1,20 +1,35 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "github>dargmuesli/renovate-config" + "customManagers": [ + { + "customType": "regex", + "datasourceTemplate": "github-tags", + "managerFilePatterns": ["/^Dockerfile$/"], + "matchStrings": [ + "#\\s+renovate:\\s+datasource=github-tags\\s+depName=(?\\S+)\\s+ENV\\s+\\S+_VERSION=(?\\S+)" + ] + } ], + "extends": ["github>dargmuesli/renovate-config"], "packageRules": [ { "automerge": false, - "matchDatasources": [ - "docker" - ], - "matchPackageNames": [ - "postgres" - ], - "matchUpdateTypes": [ - "major" - ] + "description": "A new PostgreSQL major needs a `pg_upgrade` of every deployed database.", + "matchDatasources": ["docker"], + "matchPackageNames": ["postgres"], + "matchUpdateTypes": ["major"] + }, + { + "automerge": false, + "description": "A new PostGIS major renames its library, so existing databases fail until they are upgraded.", + "matchPackageNames": ["postgis/postgis"], + "matchUpdateTypes": ["major"] + }, + { + "automerge": false, + "description": "pgvector is still on 0.x, where a minor may break as much as a major.", + "matchPackageNames": ["pgvector/pgvector"], + "matchUpdateTypes": ["major", "minor"] } ], "semanticCommitType": "fix" diff --git a/AGENTS.md b/AGENTS.md index 3c93047..aa11e91 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,12 +8,17 @@ This project builds the PostgreSQL container image of `vibetype`, an event commu ## Image -- PostGIS and pgvector come as packages from the PostgreSQL project's apt repository, which the official Debian based `postgres` image already configures and which builds them for amd64 and arm64 - - The package names follow the base image's `PG_MAJOR`, so a new major installs the matching extensions - - Their versions follow the repository at build time, so a rebuild can bring a newer PostGIS, after which a database needs `ALTER EXTENSION postgis UPDATE` -- A new PostgreSQL major needs a `pg_upgrade` of every deployed database, so Renovate opens such updates without merging them automatically -- The base stays on Debian: a switch of the C library, as to Alpine, changes the collation of existing databases, which invalidates their text indexes +- PostGIS and pgvector are compiled from source in the `build` stage, as `postgis/postgis` publishes no arm64 image and Alpine's own packages lag behind the PostGIS version in use + - The PostGIS build follows the upstream Alpine Dockerfile at https://github.com/postgis/docker-postgis, so compare against it when PostGIS updates + - pgvector is built with an empty `OPTFLAGS`, as the default `-march=native` would tie the image to the build machine's CPU + - The arm64 build compiles under emulation and takes about 25 minutes in CI +- The base stays on Alpine, as a switch of the C library changes the collation of existing databases, which invalidates their text indexes +- Renovate tracks PostGIS and pgvector through the `# renovate:` comments in the `Dockerfile`, and does not merge updates automatically that need care: + - a new PostgreSQL major needs a `pg_upgrade` of every deployed database + - a new PostGIS major renames its library, so existing databases fail until they are upgraded; a minor only needs `SELECT postgis_extensions_upgrade()` at some point + - pgvector is still on 0.x, where a minor may break as much as a major - A new database gets `postgis` and `postgis_topology` from `docker-entrypoint-initdb.d`, as `sqitch` migrations expect PostGIS to exist + - pgvector is only installed, as the services that use it create it in their own migrations, which also reach existing databases ## Release diff --git a/Dockerfile b/Dockerfile index f62a1b8..b06e362 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,80 @@ # syntax=docker/dockerfile:1 -FROM postgres:18.7-trixie@sha256:eb63372c1e05c755f55fa30cbd07aecc443676fc6c0fa90b9002d01537841e1a AS production +# PostGIS is compiled here instead of using `postgis/postgis`, which publishes no arm64 image. +# The build follows https://github.com/postgis/docker-postgis/blob/master/18-3.7/alpine/Dockerfile, without its regression tests. -# The base image ships the PostgreSQL project's apt repository, which builds both extensions for every architecture. -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - "postgresql-${PG_MAJOR}-pgvector" \ - "postgresql-${PG_MAJOR}-postgis-3" \ - "postgresql-${PG_MAJOR}-postgis-3-scripts" \ - && rm -rf /var/lib/apt/lists/* +######################## +# Provide the base. +FROM postgres:18.7-alpine3.24@sha256:ff64c9e3bdf8e2120107d3559de8db314e8305f7e38c5105903c6295876738ff AS base + + +######################## +# Compile the extensions. + +FROM base AS build + +# renovate: datasource=github-tags depName=postgis/postgis +ENV POSTGIS_VERSION=3.7.0 +# renovate: datasource=github-tags depName=pgvector/pgvector +ENV PGVECTOR_VERSION=v0.8.7 + +ADD https://github.com/postgis/postgis.git#${POSTGIS_VERSION} /usr/src/postgis +ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_VERSION} /usr/src/pgvector + +# `DOCKER_PG_LLVM_DEPS` names the clang and llvm versions that the base image's PostgreSQL was built with, which its JIT bitcode needs. +RUN apk add --no-cache \ + $DOCKER_PG_LLVM_DEPS \ + autoconf \ + automake \ + file \ + g++ \ + gcc \ + gdal-dev \ + geos-dev \ + gettext-dev \ + gmp-dev \ + json-c-dev \ + libtool \ + libxml2-dev \ + make \ + pcre2-dev \ + perl \ + proj-dev \ + protobuf-c-dev \ + sfcgal-dev + +WORKDIR /usr/src/postgis + +RUN gettextize \ + && ./autogen.sh \ + && ./configure --enable-lto \ + && make -j"$(nproc)" \ + && make install DESTDIR=/srv/extensions + +WORKDIR /usr/src/pgvector + +# An empty `OPTFLAGS` drops `-march=native`, which would tie the build to the CPU of the machine building it. +RUN make OPTFLAGS="" \ + && make install DESTDIR=/srv/extensions + + +######################## +# Serve the database. + +FROM base AS production + +RUN apk add --no-cache \ + ca-certificates \ + gdal \ + geos \ + gmp \ + json-c \ + libstdc++ \ + pcre2 \ + proj \ + protobuf-c \ + sfcgal + +COPY --from=build /srv/extensions/usr/local /usr/local COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md index b45be63..1018194 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # postgres -Vibetype's PostgreSQL container image, which adds [PostGIS](https://postgis.net/) and [pgvector](https://github.com/pgvector/pgvector) to the official Debian based [`postgres`](https://hub.docker.com/_/postgres) image. +Vibetype's PostgreSQL container image, which adds [PostGIS](https://postgis.net/) and [pgvector](https://github.com/pgvector/pgvector) to the official [`postgres`](https://hub.docker.com/_/postgres) Alpine image. It is published for `linux/amd64` and `linux/arm64` as `ghcr.io/maevsi/postgres`. ## Usage From f8918fb36167a5133e4a84308573133b5cb98305 Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 20 Nov 2026 07:10:53 +0100 Subject: [PATCH 4/5] feat(image): leave creating the extensions to migrations --- .github/smoke-test.sh | 5 +---- AGENTS.md | 4 ++-- Dockerfile | 1 - README.md | 3 +-- docker-entrypoint-initdb.d/10_postgis.sh | 8 -------- 5 files changed, 4 insertions(+), 17 deletions(-) delete mode 100755 docker-entrypoint-initdb.d/10_postgis.sh diff --git a/.github/smoke-test.sh b/.github/smoke-test.sh index 8eba0ee..72d0f73 100755 --- a/.github/smoke-test.sh +++ b/.github/smoke-test.sh @@ -30,10 +30,7 @@ fail() { exit 1 } -EXTENSIONS="$(query "SELECT string_agg(extname, ',' ORDER BY extname) FROM pg_extension")" -echo "Extensions created on init: $EXTENSIONS" -[ "$EXTENSIONS" = 'plpgsql,postgis,postgis_topology' ] || fail 'Expected PostGIS and its topology to be created on init' - +query 'CREATE EXTENSION postgis' >/dev/null || fail 'PostGIS is not installed' query 'CREATE EXTENSION vector' >/dev/null || fail 'pgvector is not installed' DISTANCE="$(query "SELECT round(ST_Distance(ST_Point(9.48, 51.31, 4326)::geography, ST_Point(11.58, 48.14, 4326)::geography) / 1000)")" diff --git a/AGENTS.md b/AGENTS.md index aa11e91..6393e34 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,8 +17,8 @@ This project builds the PostgreSQL container image of `vibetype`, an event commu - a new PostgreSQL major needs a `pg_upgrade` of every deployed database - a new PostGIS major renames its library, so existing databases fail until they are upgraded; a minor only needs `SELECT postgis_extensions_upgrade()` at some point - pgvector is still on 0.x, where a minor may break as much as a major -- A new database gets `postgis` and `postgis_topology` from `docker-entrypoint-initdb.d`, as `sqitch` migrations expect PostGIS to exist - - pgvector is only installed, as the services that use it create it in their own migrations, which also reach existing databases +- Both extensions are only installed, unlike in `postgis/postgis`, whose init script creates PostGIS + - The services that use them create them in their own migrations, `sqitch` for PostGIS and `reccoom` for pgvector, which also reach existing databases, while an init script only runs for a new data directory ## Release diff --git a/Dockerfile b/Dockerfile index b06e362..a7ff58e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -77,4 +77,3 @@ RUN apk add --no-cache \ sfcgal COPY --from=build /srv/extensions/usr/local /usr/local -COPY ./docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md index 1018194..78fe428 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ It is published for `linux/amd64` and `linux/arm64` as `ghcr.io/maevsi/postgres` ## Usage The image is configured like the official `postgres` image. -A new database starts with the `postgis` and `postgis_topology` extensions, like with `postgis/postgis`. -pgvector is installed but not created, so a database that needs it runs `CREATE EXTENSION vector`. +Both extensions are installed but not created, so a database that needs one runs `CREATE EXTENSION postgis` or `CREATE EXTENSION vector`, ideally in its migrations. ## Development diff --git a/docker-entrypoint-initdb.d/10_postgis.sh b/docker-entrypoint-initdb.d/10_postgis.sh deleted file mode 100755 index f8b2f82..0000000 --- a/docker-entrypoint-initdb.d/10_postgis.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -eu - -# Like `postgis/postgis`, a new database starts with PostGIS, which migrations expect to exist already. -psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-'EOSQL' - CREATE EXTENSION IF NOT EXISTS postgis; - CREATE EXTENSION IF NOT EXISTS postgis_topology; -EOSQL From b3917bf98ccb1ac154db9c8183081cb19216cf6a Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Fri, 20 Nov 2026 07:11:48 +0100 Subject: [PATCH 5/5] fix(image): install bison and flex for regenerated postgis parsers --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index a7ff58e..c7bb0f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,11 +23,14 @@ ADD https://github.com/postgis/postgis.git#${POSTGIS_VERSION} /usr/src/postgis ADD https://github.com/pgvector/pgvector.git#${PGVECTOR_VERSION} /usr/src/pgvector # `DOCKER_PG_LLVM_DEPS` names the clang and llvm versions that the base image's PostgreSQL was built with, which its JIT bitcode needs. +# A git checkout gives all files arbitrary modification times, so make may regenerate the committed parsers, which needs bison and flex. RUN apk add --no-cache \ $DOCKER_PG_LLVM_DEPS \ autoconf \ automake \ + bison \ file \ + flex \ g++ \ gcc \ gdal-dev \