chore(docker): add database Dockerfile to be used with docker-compose
This commit is contained in:
parent
fe6189175b
commit
2b11694ca3
14
docker/database/Dockerfile
Normal file
14
docker/database/Dockerfile
Normal 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
14
docker/database/initdb.sh
Normal 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
|
||||
1
docker/database/pg_hba.conf
Normal file
1
docker/database/pg_hba.conf
Normal file
@ -0,0 +1 @@
|
||||
local all all trust
|
||||
6
docker/database/postgresql.conf
Normal file
6
docker/database/postgresql.conf
Normal 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
|
||||
5
docker/database/schema.sql
Normal file
5
docker/database/schema.sql
Normal 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;
|
||||
Reference in New Issue
Block a user