diff --git a/docker/database/Dockerfile b/docker/database/Dockerfile new file mode 100644 index 000000000..215173812 --- /dev/null +++ b/docker/database/Dockerfile @@ -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 \ No newline at end of file diff --git a/docker/database/initdb.sh b/docker/database/initdb.sh new file mode 100644 index 000000000..775e14d4c --- /dev/null +++ b/docker/database/initdb.sh @@ -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 \ No newline at end of file diff --git a/docker/database/pg_hba.conf b/docker/database/pg_hba.conf new file mode 100644 index 000000000..a5e9c7250 --- /dev/null +++ b/docker/database/pg_hba.conf @@ -0,0 +1 @@ +local all all trust \ No newline at end of file diff --git a/docker/database/postgresql.conf b/docker/database/postgresql.conf new file mode 100644 index 000000000..0bccfecc3 --- /dev/null +++ b/docker/database/postgresql.conf @@ -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 \ No newline at end of file diff --git a/docker/database/schema.sql b/docker/database/schema.sql new file mode 100644 index 000000000..133a49338 --- /dev/null +++ b/docker/database/schema.sql @@ -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; \ No newline at end of file