# syntax=docker/dockerfile:1.4 FROM ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive ENV LANG=C.UTF-8 ENV PGDATA=/var/lib/postgresql/data ENV TZ=Etc/GMT-0 RUN set -eux; \ apt-get update; \ apt-get install -y --no-install-recommends \ ca-certificates curl wget gnupg2 lsb-release \ locales \ gosu \ build-essential git openssh-client \ ; \ rm -rf /var/lib/apt/lists/*; \ locale-gen en_US.UTF-8 # Configure non-interactive timezone to avoid tzdata prompts RUN set -eux; \ echo "tzdata tzdata/Areas select Etc" | debconf-set-selections; \ echo "tzdata tzdata/Zones/Etc select GMT-0" | debconf-set-selections; \ apt-get update; \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata; \ rm -rf /var/lib/apt/lists/*; \ ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \ echo $TZ > /etc/timezone; \ dpkg-reconfigure -f noninteractive tzdata RUN set -eux; \ mkdir -p /root/.ssh; \ ssh-keyscan github.com >> /root/.ssh/known_hosts # Percona installation 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-{{MAJOR_VERSION}}; \ apt-get update; \ apt-get install -y --no-install-recommends \ percona-postgresql-{{MAJOR_VERSION}} \ percona-postgresql-server-dev-{{MAJOR_VERSION}} \ ; \ rm -rf /var/lib/apt/lists/* ENV PATH=/usr/lib/postgresql/{{MAJOR_VERSION}}/bin:$PATH 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 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/* # Extension installation RUN set -eux; \ apt-get update; \ {{EXTENSION_INSTALL_STEPS}} apt-get install -y --no-install-recommends percona-pg-tde{{MAJOR_VERSION}}; \ apt-get install -y --no-install-recommends \ 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; \ {{EXTENSION_CREATE_STEPS}} echo " CREATE EXTENSION IF NOT EXISTS tds_fdw;" >> /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 # Barman 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/* 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 COPY postgresql/*.conf /etc/postgresql/{{MAJOR_VERSION}}/main/ RUN chown postgres:postgres /etc/postgresql/{{MAJOR_VERSION}}/main/*.conf 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"]