prole/prole-db/Dockerfile
chrisfu f2c9012cce Refactor installation and initialization logic, and expand test coverage
- install.py: Major update including configuration variable expansion, improved k3s/k3d handling, and enhanced installation logic.

- etc/ scripts: Significant refactoring of initialization scripts (Kerberos, Port Forwards, Garage Store, etc.).

- Port Forwards: Transitioned from XML to port-mappings.conf for managing kubectl port-forwards.

- Status Reporting: Improved status checking for common services.

- Infrastructure: Updated Ansible inventory and rsyslog role configurations.

- Tests: Added a comprehensive suite of tests for 'etc' initialization scripts in prole/tests/etc/.

- Documentation: Added prole-db-documentation-mcp-architecture.md.

- General: Updated Dockerfiles and various helper scripts.
2026-02-13 21:36:39 -08:00

157 lines
6.2 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# syntax=docker/dockerfile:1.4
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
# Official image expects PGDATA default to /var/lib/postgresql/data
ENV PGDATA=/var/lib/postgresql/data
# 1) Base runtime deps to match official behavior (gosu, locales, etc.)
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl wget gnupg2 lsb-release \
locales tzdata \
gosu \
build-essential git openssh-client \
; \
rm -rf /var/lib/apt/lists/*; \
locale-gen en_US.UTF-8
# Preload GitHub host key for non-interactive SSH clones.
RUN set -eux; \
mkdir -p /root/.ssh; \
ssh-keyscan github.com >> /root/.ssh/known_hosts
# 2) Add Percona apt repo + install Percona Server for PostgreSQL 17
# Percona docs: use percona-release + setup ppg-17, and avoid mixing with distro postgresql-17
RUN set -eux; \
apt-get update; \
wget -q "https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb"; \
dpkg -i "percona-release_latest.$(lsb_release -sc)_all.deb"; \
rm -f "percona-release_latest.$(lsb_release -sc)_all.deb"; \
apt-get update; \
percona-release setup ppg-17; \
apt-get update; \
apt-get install -y --no-install-recommends \
percona-postgresql-17 \
; \
rm -rf /var/lib/apt/lists/*
# install nfs & iscsi
# RUN apt-get install -y nfs-common
# RUN apt-get install -y open-iscsi
# Ensure postgres binaries are on PATH (official entrypoint expects `postgres`, `initdb`, `psql` in PATH)
# Percona’s deb layout is Debian-like; this is the common bindir.
ENV PATH=/usr/lib/postgresql/17/bin:$PATH
# 3) Install dev headers for PGXS builds
RUN set -eux; \
apt-get update; \
apt-cache search percona-postgresql | grep -i dev; \
apt-get install -y --no-install-recommends percona-postgresql-server-dev-17; \
rm -rf /var/lib/apt/lists/*
# 4) Create postgres user + dirs similar to official image expectations
RUN set -eux; \
groupadd -r postgres --gid=999 || true; \
useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres || true; \
mkdir -p /var/lib/postgresql /var/run/postgresql "$PGDATA" /docker-entrypoint-initdb.d /etc/prole; \
chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql /docker-entrypoint-initdb.d; \
chmod 3777 /var/run/postgresql
# 5) Build and install pg_prolelog module + PostgreSQL extensions
# Install dependencies for building pg_prolelog and other extensions
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
cmake \
libssl-dev \
libgdal-dev \
libproj-dev \
libgeos-dev \
libxml2-dev \
libjson-c-dev \
libprotobuf-c-dev \
protobuf-c-compiler \
; \
rm -rf /var/lib/apt/lists/*
# Copy and install pg_prolelog from local .deb package
ARG TARGETARCH
# COPY pg_prolelog/percona-postgresql-17-pg-prolelog_1.0-1_${TARGETARCH:-amd64}.deb /tmp/pg_prolelog.deb
# RUN set -eux; \
# apt-get update; \
# apt-get install -y --no-install-recommends /tmp/pg_prolelog.deb; \
# rm -f /tmp/pg_prolelog.deb; \
# rm -rf /var/lib/apt/lists/*
# Install PostgreSQL extensions
RUN set -eux; \
apt-get update; \
apt-cache search percona-postgresql-17 | grep -E "(pgvector|postgis|contrib)"; \
apt-get install -y --no-install-recommends \
percona-postgresql-17-pgvector \
percona-postgresql-17-postgis-3 \
percona-postgresql-contrib-17 \
percona-postgresql-contrib \
freetds-dev \
; \
rm -rf /var/lib/apt/lists/*
# Build and install tds_fdw
RUN --mount=type=ssh set -eux; \
cd /tmp; \
git clone https://github.com/tds-fdw/tds_fdw.git; \
cd tds_fdw; \
make USE_PGXS=1; \
make USE_PGXS=1 install; \
cd /; \
rm -rf /tmp/tds_fdw
# Create extension registration script
RUN set -eux; \
echo "#!/bin/bash" > /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo "set -e" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo 'psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL' >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo " CREATE EXTENSION IF NOT EXISTS vector;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo " CREATE EXTENSION IF NOT EXISTS pgcrypto;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo " CREATE EXTENSION IF NOT EXISTS tds_fdw;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo " CREATE EXTENSION IF NOT EXISTS postgis;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo " CREATE EXTENSION IF NOT EXISTS postgis_topology;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
# echo " CREATE EXTENSION IF NOT EXISTS pg_prolelog;" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
echo "EOSQL" >> /docker-entrypoint-initdb.d/20_create_extensions.sh; \
chmod +x /docker-entrypoint-initdb.d/20_create_extensions.sh
# Install barman-cloud
COPY requirements.txt /
RUN set -xe; apt-get update; apt-get install -y --no-install-recommends build-essential python3-dev python3-pip python3-psycopg2 python3-setuptools
RUN pip3 install --break-system-packages -r /requirements.txt
RUN apt-get remove -y --purge --autoremove build-essential python3-dev && rm -rf /var/lib/apt/lists/*
# 6) Add entrypoint scripts (official entrypoint verbatim + our tiny wrapper + OpenBao/pg_tde init hook)
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY prole-db-entrypoint.sh /usr/local/bin/prole-entrypoint.sh
COPY 10_pg_tde_openbao.sh /docker-entrypoint-initdb.d/10_pg_tde_openbao.sh
COPY prole-db-ssh-openbao.sh /usr/local/bin/prole-db-ssh-openbao.sh
# staged copies of the pgdata/*.conf files
COPY postgresql/*.conf /etc/postgresql/17/main/
RUN chown postgres:postgres /etc/postgresql/17/main/*.conf
# 7) Create new user
ARG PROLE_USER=prole
RUN set -eux; \
if [ -n "$PROLE_USER" ] && [ "$PROLE_USER" != "root" ] && [ "$PROLE_USER" != "postgres" ]; then \
if ! id -u "$PROLE_USER" >/dev/null 2>&1; then \
useradd -m -s /bin/bash "$PROLE_USER"; \
fi; \
fi
RUN set -eux; \
chmod +x /usr/local/bin/docker-entrypoint.sh /usr/local/bin/prole-entrypoint.sh /usr/local/bin/prole-db-ssh-openbao.sh /docker-entrypoint-initdb.d/10_pg_tde_openbao.sh
EXPOSE 5432
CMD ["postgres"]