# Bake PostgreSQL 18 (server + pre-seeded app roles/databases) into the Legatus Qt6 # build image, so any container from legatus-qt6-prebuilt:latest has a local DB ready. # # build : docker build -f Dockerfile.legatus-db -t legatus-qt6-prebuilt:latest . # start : legatus-db-up # maps EXCDBS01/EXCADB01 -> 127.0.0.1 and starts pg # # Notes: # - The cluster + roles/dbs live in the image's /var/lib/postgresql/18/main; each new # container gets a fresh copy (in its writable layer). Start with `legatus-db-up`. # - /etc/hosts is docker-managed, so EXCDBS01/EXCADB01 are added by legatus-db-up (or # pass --add-host EXCDBS01:127.0.0.1 --add-host EXCADB01:127.0.0.1 at docker run). FROM legatus-qt6-prebuilt:orig ENV DEBIAN_FRONTEND=noninteractive # Install the server; init the cluster with the credentials the DB tools use: # dbUpdate -> postgres / postgres # dbAdministration -> ctc_sv / postgres RUN apt-get update \ && apt-get install -y postgresql-18 \ && rm -rf /var/lib/apt/lists/* \ && pg_ctlcluster 18 main start \ && sleep 2 \ && su postgres -c "psql -v ON_ERROR_STOP=1 -c \"ALTER USER postgres PASSWORD 'postgres'\"" \ && su postgres -c "psql -v ON_ERROR_STOP=1 -c \"CREATE ROLE ctc_sv LOGIN PASSWORD 'postgres' CREATEDB\"" \ && su postgres -c "createdb -O postgres lts_ets_pro" \ && su postgres -c "createdb -O postgres dbAdmin" \ && pg_ctlcluster 18 main stop # Convenience one-shot: map the hostnames + start the cluster (idempotent). RUN printf '%s\n' \ '#!/usr/bin/env bash' \ '# Map the DB hostnames to the local server and start PostgreSQL 18.' \ 'set -uo pipefail' \ 'grep -qE "EXCDBS01" /etc/hosts || echo "127.0.0.1 EXCDBS01 EXCADB01" >> /etc/hosts' \ 'pg_ctlcluster 18 main start || true' \ 'sleep 1' \ 'pg_isready -h 127.0.0.1 -p 5432' \ > /usr/local/bin/legatus-db-up \ && chmod +x /usr/local/bin/legatus-db-up