move db setup to entrypoint bash file

This commit is contained in:
Ed Chalstrey 2022-02-08 10:31:54 +00:00
parent cac2c5bcf2
commit 7c0936a063
2 changed files with 22 additions and 7 deletions

View File

@ -46,6 +46,7 @@ RUN node --version
RUN npm --version RUN npm --version
RUN service postgresql start RUN service postgresql start
COPY ./init-user-db.sh /docker-entrypoint-initdb.d/init-user-db.sh
# RUN sed -i "s/#\?listen_address.*/listen_addresses '*'/" /etc/postgresql/12/main/postgresql.conf # RUN sed -i "s/#\?listen_address.*/listen_addresses '*'/" /etc/postgresql/12/main/postgresql.conf
@ -53,16 +54,16 @@ RUN service postgresql start
# RUN service postgresql restart # RUN service postgresql restart
RUN postgres psql -c "SELECT 1 FROM pg_user WHERE usename = 'dockeruser';" | grep -q 1 || postgres psql -c "CREATE ROLE dockeruser SUPERUSER LOGIN PASSWORD 'postgres';" # RUN psql -c "SELECT 1 FROM pg_user WHERE usename = 'dockeruser';" | grep -q 1 || psql -c "CREATE ROLE dockeruser SUPERUSER LOGIN PASSWORD 'postgres';"
RUN postgres psql -c "SELECT 1 FROM pg_database WHERE datname = 'colouringlondon';" | grep -q 1 || postgres createdb -E UTF8 -T template0 --locale=en_US.utf8 -O dockeruser colouringlondon # RUN psql -c "SELECT 1 FROM pg_database WHERE datname = 'colouringlondon';" | grep -q 1 || createdb -E UTF8 -T template0 --locale=en_US.utf8 -O dockeruser colouringlondon
RUN psql -d colouringlondon -U dockeruser -h localhost # RUN psql -d colouringlondon -U dockeruser -h localhost
RUN psql -d colouringlondon -c "create extension postgis;" # RUN psql -d colouringlondon -c "create extension postgis;"
RUN psql -d colouringlondon -c "create extension pgcrypto;" # RUN psql -d colouringlondon -c "create extension pgcrypto;"
RUN psql -d colouringlondon -c "create extension pg_trgm;" # RUN psql -d colouringlondon -c "create extension pg_trgm;"
RUN ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d colouringlondon < $migration; done; # RUN ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d colouringlondon < $migration; done;
RUN pyvenv colouringlondon RUN pyvenv colouringlondon
RUN source colouringlondon/bin/activate RUN source colouringlondon/bin/activate

14
init-user-db.sh Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
sed -i "s/#\?listen_address.*/listen_addresses '*'/" /etc/postgresql/12/main/postgresql.conf
echo "host all all all md5" | tee --append /etc/postgresql/12/main/pg_hba.conf > /dev/null
service postgresql restart
sudo -u postgres psql -c "SELECT 1 FROM pg_user WHERE usename = 'dockeruser';" | grep -q 1 || sudo -u postgres psql -c "CREATE ROLE dockeruser SUPERUSER LOGIN PASSWORD 'postgres';"
sudo -u postgres psql -c "SELECT 1 FROM pg_database WHERE datname = 'colouringlondon';" | grep -q 1 || sudo -u postgres createdb -E UTF8 -T template0 --locale=en_US.utf8 -O dockeruser colouringlondon
psql -d colouringlondon -U dockeruser -h localhost
psql -d colouringlondon -c "create extension postgis;"
psql -d colouringlondon -c "create extension pgcrypto;"
psql -d colouringlondon -c "create extension pg_trgm;"
ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d colouringlondon < $migration; done;