diff --git a/roles/apps/templates/postgres/Containerfile.j2 b/roles/apps/templates/postgres/Containerfile.j2 new file mode 100644 index 0000000..4fbc947 --- /dev/null +++ b/roles/apps/templates/postgres/Containerfile.j2 @@ -0,0 +1,24 @@ +FROM almalinux:9-base + +# Install PostgreSQL 16 using built-in module +RUN dnf -y update && \ + dnf -y module enable postgresql:{{postsgresql_version}} && \ + dnf -y install postgresql-server && \ + dnf clean all + +# Create directory structure without initializing +RUN mkdir -p /var/lib/pgsql/data && \ + chown -R postgres:postgres /var/lib/pgsql && \ + chmod 700 /var/lib/pgsql/data + +# Add entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +USER postgres +ENV PGDATA=/var/lib/pgsql/data +EXPOSE 5432 + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["postgres", "-D", "/var/lib/pgsql/data"] + diff --git a/roles/apps/templates/postgres/entrypoint.sh b/roles/apps/templates/postgres/entrypoint.sh new file mode 100644 index 0000000..3151e1f --- /dev/null +++ b/roles/apps/templates/postgres/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Initialize only if data directory is empty +if [ -z "$(ls -A $PGDATA)" ]; then + echo "Initializing PostgreSQL database..." + /usr/bin/postgresql-setup --initdb +fi + +exec "$@" +