chore(docker): add database Dockerfile to be used with docker-compose

This commit is contained in:
Sarah Vaupel 2024-08-14 06:42:43 +02:00
parent fe6189175b
commit 2b11694ca3
5 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,14 @@
FROM postgres:12
# Allow for connecting to database without password authentication
ENV POSTGRES_HOST_AUTH_METHOD=trust
USER postgres
# postgresql.conf and postgres_hba.conf resulted in error (Invalid data directory or sth); using -o/--options in initdb.sh instead
# COPY --chown=postgres:postgres --chmod=644 ./postgresql.conf /etc/postgresql/12/main/postgresql.conf
# COPY --chown=postgres:postgres --chmod=644 ./pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
COPY ./schema.sql /schema.sql
COPY --chmod=755 ./initdb.sh /etc/fradrive-db
ENTRYPOINT /etc/fradrive-db

14
docker/database/initdb.sh Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
# Init and start the postgres daemon
initdb --no-locale
pg_ctl start -w -o "-c listen_addresses=0.0.0.0 -c unix_socket_permissions=0700 -c max_connections=9990 -c shared_preload_libraries=pg_stat_statements -c session_preload_libraries=auto_explain -c auto_explain.log_min_duration=100ms" # COPY postgresql.conf and postgres_hba.conf resulted in error (Invalid data directory)
POSTGRID=`cat /var/lib/postgresql/data/postmaster.pid | perl -le '<>=~m#(\d+)# and print $1'`
# Create uniworx and uniworx_test database
psql -f /schema.sql postgres
# Wait for postgres daemon to terminate
while [ -e /proc/$POSTGRID ]; do
sleep 0.5;
done

View File

@ -0,0 +1 @@
local all all trust

View File

@ -0,0 +1,6 @@
listen_addresses=0.0.0.0
unix_socket_permissions=0700
max_connections=9990
shared_preload_libraries=pg_stat_statements
session_preload_libraries=auto_explain
auto_explain.log_min_duration=100ms

View File

@ -0,0 +1,5 @@
CREATE USER uniworx WITH SUPERUSER;
CREATE DATABASE uniworx_test;
GRANT ALL ON DATABASE uniworx_test TO uniworx;
CREATE DATABASE uniworx;
GRANT ALL ON DATABASE uniworx TO uniworx;