From 9149277c6ca47b9efc2a5567b4be542f822c83bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Sun, 23 Nov 2025 12:52:46 +0100 Subject: [PATCH] WIP: extensions --- .claude/settings.local.json | 9 ++++++ 17extra/Dockerfile | 40 +++++++++++++++++++++++++ 17extra/init-scripts/005-timescaledb.sh | 15 ++++++++++ 17extra/init-scripts/006-pg_cron.sh | 15 ++++++++++ 17extra/init-scripts/007-pgvector.sh | 15 ++++++++++ 17pig/Dockerfile | 22 ++++++++++++++ 17pig/init-scripts/001-extensions.sh | 20 +++++++++++++ Makefile | 13 ++++++++ shared/init-scripts/002-intarray.sh | 2 +- shared/init-scripts/003-unaccent.sh | 2 +- 10 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 .claude/settings.local.json create mode 100644 17extra/Dockerfile create mode 100755 17extra/init-scripts/005-timescaledb.sh create mode 100755 17extra/init-scripts/006-pg_cron.sh create mode 100755 17extra/init-scripts/007-pgvector.sh create mode 100644 17pig/Dockerfile create mode 100755 17pig/init-scripts/001-extensions.sh diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..d792ac9 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,9 @@ +{ + "permissions": { + "allow": [ + "Bash(chmod:*)" + ], + "deny": [], + "ask": [] + } +} diff --git a/17extra/Dockerfile b/17extra/Dockerfile new file mode 100644 index 0000000..667b0e5 --- /dev/null +++ b/17extra/Dockerfile @@ -0,0 +1,40 @@ +FROM dockette/postgres:17 + +# Install build dependencies and extension packages +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + postgresql-server-dev-${POSTGRES_VERSION} \ + curl \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Install pgvector +RUN git clone --branch v0.7.2 https://github.com/pgvector/pgvector.git /tmp/pgvector \ + && cd /tmp/pgvector \ + && make \ + && make install \ + && rm -rf /tmp/pgvector + +# Install pg_cron +RUN git clone --branch v1.7.1 https://github.com/citusdata/pg_cron.git /tmp/pg_cron \ + && cd /tmp/pg_cron \ + && make \ + && make install \ + && rm -rf /tmp/pg_cron + +# Install TimescaleDB +RUN curl -s https://packagecloud.io/install/repositories/timescale/timescaledb/script.deb.sh | bash \ + && apt-get update \ + && apt-get install -y --no-install-recommends timescaledb-2-postgresql-${POSTGRES_VERSION} \ + && rm -rf /var/lib/apt/lists/* + +# Copy extension init scripts +COPY ./17extra/init-scripts/* /docker-entrypoint-initdb.d/ +RUN chmod +x /docker-entrypoint-initdb.d/*.sh + +# Clean up build dependencies (optional, keeps image smaller) +RUN apt-get purge -y build-essential git \ + && apt-get autoremove -y \ + && apt-get clean + diff --git a/17extra/init-scripts/005-timescaledb.sh b/17extra/init-scripts/005-timescaledb.sh new file mode 100755 index 0000000..e58847b --- /dev/null +++ b/17extra/init-scripts/005-timescaledb.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create extension in template1 and $POSTGRES_DB +for DB in template1 "$POSTGRES_DB"; do + echo "Creating extension timescaledb into $DB" + "${psql[@]}" --dbname="$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS timescaledb; +EOSQL +done + diff --git a/17extra/init-scripts/006-pg_cron.sh b/17extra/init-scripts/006-pg_cron.sh new file mode 100755 index 0000000..1c92d48 --- /dev/null +++ b/17extra/init-scripts/006-pg_cron.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create extension in template1 and $POSTGRES_DB +for DB in template1 "$POSTGRES_DB"; do + echo "Creating extension pg_cron into $DB" + "${psql[@]}" --dbname="$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS pg_cron; +EOSQL +done + diff --git a/17extra/init-scripts/007-pgvector.sh b/17extra/init-scripts/007-pgvector.sh new file mode 100755 index 0000000..c327904 --- /dev/null +++ b/17extra/init-scripts/007-pgvector.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create extension in template1 and $POSTGRES_DB +for DB in template1 "$POSTGRES_DB"; do + echo "Creating extension vector into $DB" + "${psql[@]}" --dbname="$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS vector; +EOSQL +done + diff --git a/17pig/Dockerfile b/17pig/Dockerfile new file mode 100644 index 0000000..7187c2b --- /dev/null +++ b/17pig/Dockerfile @@ -0,0 +1,22 @@ +FROM postgres:17 + +ENV POSTGRES_VERSION=17 + +# Install pig extension package manager +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + && curl -fsSL https://repo.pigsty.io/pig | bash \ + && rm -rf /var/lib/apt/lists/* + +# Set up repositories and install extensions using pig +RUN pig repo set && \ + pig install -y -v ${POSTGRES_VERSION} timescaledb pg_cron pgvector + +# Preload required libraries (timescaledb and pg_cron require this) +RUN echo "shared_preload_libraries = 'timescaledb,pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample + +# Copy extension init scripts +COPY ./17pig/init-scripts/* /docker-entrypoint-initdb.d/ +RUN chmod +x /docker-entrypoint-initdb.d/*.sh + diff --git a/17pig/init-scripts/001-extensions.sh b/17pig/init-scripts/001-extensions.sh new file mode 100755 index 0000000..897c67e --- /dev/null +++ b/17pig/init-scripts/001-extensions.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Exit on subcommand errors +set -Eeuo pipefail + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create extensions in template1 and $POSTGRES_DB +for DB in template1 "$POSTGRES_DB"; do + echo "Creating extensions in $DB" + psql -d "$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS timescaledb; + CREATE EXTENSION IF NOT EXISTS vector; +EOSQL +done + +# pg_cron can only be installed in the postgres database +echo "Creating extension pg_cron in postgres" +psql -d postgres -c "CREATE EXTENSION IF NOT EXISTS pg_cron;" diff --git a/Makefile b/Makefile index 76741a4..b2f6e0d 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ build-15: _build-15 build-16: _build-16 build-17: _build-17 build-17extra: _build-17extra +build-17pig: _build-17pig build-18: _build-18 _build-%: BUILD_VERSION=$* @@ -15,3 +16,15 @@ _build-%: -t dockette/postgres:${BUILD_VERSION} \ -f ${BUILD_VERSION}/Dockerfile \ . + +_build-17extra: + docker build \ + -t dockette/postgres:17extra \ + -f 17extra/Dockerfile \ + . + +_build-17pig: + docker build \ + -t dockette/postgres:17pig \ + -f 17pig/Dockerfile \ + . diff --git a/shared/init-scripts/002-intarray.sh b/shared/init-scripts/002-intarray.sh index e28b2a8..612aaae 100644 --- a/shared/init-scripts/002-intarray.sh +++ b/shared/init-scripts/002-intarray.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e diff --git a/shared/init-scripts/003-unaccent.sh b/shared/init-scripts/003-unaccent.sh index 2ae532e..ef62beb 100644 --- a/shared/init-scripts/003-unaccent.sh +++ b/shared/init-scripts/003-unaccent.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e