Skip to content

Commit

Permalink
Add Dockerfile for database setup
Browse files Browse the repository at this point in the history
This allows to quickly setup a database for an development setup
  • Loading branch information
awoestmann committed Jul 10, 2024
1 parent 6693fee commit 800b7d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG POSTGRES_VERSION=13
FROM postgres:${POSTGRES_VERSION}-bookworm

LABEL maintainer="[email protected]"

ARG POSTGRES_VERSION
ARG POSTGIS_VERSION=3

# Postgres password
ENV POSTGRES_PASSWORD secret
#DB name
ENV DB_NAME fisumwelt
#AUIK user and password
ENV USERNAME auikadmin
ENV USER_PW secret

RUN apt-get update && apt-get install -y postgresql-${POSTGRES_VERSION}-postgis-${POSTGIS_VERSION}

USER postgres

#Copy init script
COPY docker/init_db.sh /docker-entrypoint-initdb.d/

ADD data/db /opt/auik_db/
WORKDIR /opt/auik_db/

CMD ["/usr/local/bin/docker-entrypoint.sh","postgres"]
22 changes: 22 additions & 0 deletions docker/init_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh -e
echo "###Setting up database###"

schema_dir=/opt/auik_db
schema_file=$schema_dir/version1_0_schema.sql
update_file_1_1_0=$schema_dir/updateTo_1_1_0.sql
import_script=$schema_dir/import_csv.sql

psql --command "CREATE DATABASE $DB_NAME;" >> /dev/null
psql -d $DB_NAME --command "CREATE EXTENSION postgis;" >> /dev/null
#Create user and assign roles
psql -d $DB_NAME --command "CREATE USER ${USERNAME} with password '${USER_PW}';" >> /dev/null
psql -d $DB_NAME --command "ALTER USER ${USERNAME} with superuser;" >> /dev/null

echo "Database: $DB_NAME"
echo "Example user(password): ${USERNAME}(${USER_PW})"

echo "Applying schema"
psql -d $DB_NAME -f $schema_file >> /dev/null
psql -d $DB_NAME -f $update_file_1_1_0 >> /dev/null
psql -d $DB_NAME -f $import_script

0 comments on commit 800b7d3

Please sign in to comment.