# HG changeset patch # User Tom Gottfried # Date 1535383448 -7200 # Node ID 156a805941b5f34ba913ba44f17884e206e79a92 # Parent e86d6e016bbb72013047df7db01a9e3a282a4841 Move docker stuff from schema to dedicated docker directory diff -r e86d6e016bbb -r 156a805941b5 docker/Dockerfile.db --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docker/Dockerfile.db Mon Aug 27 17:24:08 2018 +0200 @@ -0,0 +1,38 @@ +FROM centos:7 +LABEL authors="tom.gottfried@intevation.de" + +# Add the PostgreSQL PGP key to verify the official yum repository packages +RUN rpm --import https://yum.postgresql.org/RPM-GPG-KEY-PGDG-10 &&\ + # Add PostgreSQL's repository. It contains the most recent release + # of PostgreSQL, 10: + yum -q -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm &&\ + # Install PostgreSQL 10 and PostGIS + yum -q -y install postgresql10-server &&\ + yum -q -y install epel-release &&\ + yum -q -y install postgis24_10 pgtap10 +USER postgres +ENV PGBIN /usr/pgsql-10/bin/ + +# initdb PostgreSQL 10: +ENV PGDATA /var/lib/pgsql/10/data +ENV PGCONF /var/lib/pgsql/10/data/postgresql.conf +RUN $PGBIN/initdb -E UTF8 2>&1 < /dev/null &&\ + # Adjust PostgreSQL configuration so that remote connections to the + # database are possible. + echo "host all all 0.0.0.0/0 md5" >> /var/lib/pgsql/10/data/pg_hba.conf &&\ + echo "listen_addresses='*'" >> $PGCONF &&\ + # Keep log on stderr to be able to use docker logs + sed -i '/logging_collector/s/on/off/' $PGCONF +# Expose the PostgreSQL port +EXPOSE 5432 + +# Create GEMMA role and database +WORKDIR /opt/gemma +COPY schema/*.sql schema/*.sh ./ +COPY schema/demo-data ./demo-data/ +RUN $PGBIN/pg_ctl start -wo "--config_file=$PGCONF" && \ + ./install-db.sh --demo --metapw "geo2Serv" && \ + $PGBIN/pg_ctl stop -m smart + +# Set the default command to run when starting the container +CMD ["/usr/pgsql-10/bin/postgres", "-D", "/var/lib/pgsql/10/data"] diff -r e86d6e016bbb -r 156a805941b5 docker/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docker/README.md Mon Aug 27 17:24:08 2018 +0200 @@ -0,0 +1,40 @@ +# Setup dev environment using Docker + +Run the `build` commands from the root of your checkout, because it is +assumed as the context! + +Other example commands, too, assume they are run from the root of your +checkout. + +## Database setup + +- Build Dockerfile with e.g.: + ``` + docker build -t gemma_db -f docker/Dockerfile.db . + ``` + +- Get a running instance with e.g.: + ``` + docker run --name gemma_db -d -p 54321:5432 -v $PWD/schema:/opt/gemma \ + gemma_db + ``` + +- Run tests for RLS policies: + ``` + docker exec gemma_db ./run_tests.sh + ``` + +## Create ER diagrams + +Assuming you have installed postgresql_autodoc and graphviz on a machine +from wich you can reach your docker host, you can use the following: + +- ER diagram with waterway related tables: + ``` + postgresql_autodoc -p 54321 -h $dockerhost \ + -d gemma -U sophie --password=so2Phie4 -t dot -l . -s 'waterway' + dot -Tpdf gemma.dot > gemma_waterway.pdf + ``` + +Omit the `-s` option to get a diagram with all tables or use any other +schema name to see other parts of the whole picture. diff -r e86d6e016bbb -r 156a805941b5 schema/Dockerfile --- a/schema/Dockerfile Mon Aug 27 17:23:43 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -FROM centos:7 -LABEL authors="tom.gottfried@intevation.de" - -# Add the PostgreSQL PGP key to verify the official yum repository packages -RUN rpm --import https://yum.postgresql.org/RPM-GPG-KEY-PGDG-10 &&\ - # Add PostgreSQL's repository. It contains the most recent release - # of PostgreSQL, 10: - yum -q -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm &&\ - # Install PostgreSQL 10 and PostGIS - yum -q -y install postgresql10-server &&\ - yum -q -y install epel-release &&\ - yum -q -y install postgis24_10 pgtap10 -USER postgres -ENV PGBIN /usr/pgsql-10/bin/ - -# initdb PostgreSQL 10: -ENV PGDATA /var/lib/pgsql/10/data -ENV PGCONF /var/lib/pgsql/10/data/postgresql.conf -RUN $PGBIN/initdb -E UTF8 2>&1 < /dev/null &&\ - # Adjust PostgreSQL configuration so that remote connections to the - # database are possible. - echo "host all all 0.0.0.0/0 md5" >> /var/lib/pgsql/10/data/pg_hba.conf &&\ - echo "listen_addresses='*'" >> $PGCONF &&\ - # Keep log on stderr to be able to use docker logs - sed -i '/logging_collector/s/on/off/' $PGCONF -# Expose the PostgreSQL port -EXPOSE 5432 - -# Create GEMMA role and database -WORKDIR /opt/gemma -COPY *.sql *.sh ./ -COPY demo-data ./demo-data/ -RUN $PGBIN/pg_ctl start -wo "--config_file=$PGCONF" && \ - ./install-db.sh --demo --metapw "geo2Serv" && \ - $PGBIN/pg_ctl stop -m smart - -# Set the default command to run when starting the container -CMD ["/usr/pgsql-10/bin/postgres", "-D", "/var/lib/pgsql/10/data"] diff -r e86d6e016bbb -r 156a805941b5 schema/README --- a/schema/README Mon Aug 27 17:23:43 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -Build Dockerfile with e.g.: -$ docker build -t gemma_db . - -Get a running instance with e.g.: -$ docker run --name gemma_db -d -p 54321:5432 -v $PWD:/opt/gemma gemma_db - -Run tests for RLS policies: -$ docker exec gemma_db ./run_tests.sh - -Create ER diagrams with e.g.: -Auxiliary tables: -$ postgresql_autodoc -p 54321 -h $dockerhost \ - -d gemma -U sophie --password=so2Phie4 -t dot -l . -s 'gemma' -$ dot -Tpdf gemma.dot > gemma_auxiliary.pdf - -Waterway related tables: -$ postgresql_autodoc -p 54321 -h $dockerhost \ - -d gemma -U sophie --password=so2Phie4 -t dot -l . -s 'gemma_waterway' -$ dot -Tpdf gemma.dot > gemma_waterway.pdf - -Fairway/bottleneck related tables: -$ postgresql_autodoc -p 54321 -h $dockerhost \ - -d gemma -U sophie --password=so2Phie4 -t dot -l . -s 'gemma_fairway' -$ dot -Tpdf gemma.dot > gemma_fairway.pdf