[PATCH 1 of 2] Improve Docker based setup

Wald Commits scm-commit at wald.intevation.org
Thu Feb 24 19:29:02 CET 2022


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1645724942 -3600
#      Thu Feb 24 18:49:02 2022 +0100
# Branch 3.2.x
# Node ID 13e2d38ad31441a36cf37965bc52e0e6618dcb04
# Parent  f3aa7a12c86aa6485e5ea8e0af5d46bf16fb6d85
Improve Docker based setup

_ Make CentOS based images more resilient against package installation
  problems
_ Upgrade database image to Debian bullseye to avoid OpenSSL bug that
  prevented downloading demo data and do some cleanup in passing
_ Add docker-compose file for more automated setup

diff -r f3aa7a12c86a -r 13e2d38ad314 docker/Dockerfile.artifacts
--- a/docker/Dockerfile.artifacts	Mon Jul 12 14:39:58 2021 +0200
+++ b/docker/Dockerfile.artifacts	Thu Feb 24 18:49:02 2022 +0100
@@ -5,7 +5,7 @@
 
 # Necessary to run further yum-installs inside Docker container,
 # if not already part of the base image:
-RUN yum -y install yum-plugin-ovl
+RUN yum -y install yum-plugin-ovl && rpm --rebuilddb
 
 # Install prerequisites
 RUN yum -y install maven mercurial curl
diff -r f3aa7a12c86a -r 13e2d38ad314 docker/Dockerfile.db
--- a/docker/Dockerfile.db	Mon Jul 12 14:39:58 2021 +0200
+++ b/docker/Dockerfile.db	Thu Feb 24 18:49:02 2022 +0100
@@ -1,7 +1,9 @@
 # Docker file for postgresql 9.4 on debain
 
-FROM debian:jessie
-MAINTAINER tom at intevation.de
+FROM debian:bullseye
+LABEL maintainer tom.gottfried at intevation.de
+
+ENV PG_VERSION 13
 
 #
 # Use utf-8
@@ -19,25 +21,25 @@
 #
 # Install packages
 #
-RUN apt-get update && \
-    apt-get install -y postgresql-9.4-postgis-2.1 postgis curl
+RUN apt-get install -y postgresql-$PG_VERSION-postgis-3 curl
+RUN apt-get -y clean
+
+ENV PGCONF /etc/postgresql/$PG_VERSION/main/postgresql.conf
+ENV PGBIN /usr/lib/postgresql/$PG_VERSION/bin/
+ENV PGDATA /var/lib/postgresql/$PG_VERSION/main
 
 #
 # Use user postgres to run the next commands
 #
 USER postgres
 
-RUN /etc/init.d/postgresql start && \
-    psql --command "CREATE USER admin WITH SUPERUSER PASSWORD 'secret';"
-
 #
 # Adjust PostgreSQL configuration so that remote connections to the
 # database are possible.
 #
 RUN echo "host all  all    0.0.0.0/0  md5" >> \
-    /etc/postgresql/9.4/main/pg_hba.conf
+    /etc/postgresql/$PG_VERSION/main/pg_hba.conf
 
-ENV PGCONF /etc/postgresql/9.4/main/postgresql.conf
 RUN echo "listen_addresses='*'" >> $PGCONF
 
 #
@@ -55,25 +57,25 @@
 ADD ./backend/doc/schema /opt/d4eriver_db
 
 # Go to postgres home for write permissions
-WORKDIR /var/lib/postgresql
 ENV DATA_ARCH demodaten_3.1.10-bis-3.2.x.tar.gz
-RUN curl -s "https://wald.intevation.org/frs/download.php/2282/$DATA_ARCH" | \
-    tar --wildcards -xz 'demodaten/*.dump.sql'
+RUN curl -sf "https://wald.intevation.org/frs/download.php/2282/$DATA_ARCH" | \
+    tar -C $HOME --wildcards -xz 'demodaten/*.dump.sql'
 
-ENV PGDATA /var/lib/postgresql/9.4/main
-RUN /usr/lib/postgresql/9.4/bin/pg_ctl start -wo "--config_file=$PGCONF" && \
+RUN $PGBIN/pg_ctl start -wo "--config_file=$PGCONF" && \
     /opt/d4eriver_db/postgresql-setup.sh && \
-    psql -f demodaten/d4e_demodata.dump.sql d4e && \
+    psql -f ~/demodaten/d4e_demodata.dump.sql d4e && \
     createuser -S -D -R seddb && \
     psql -c "ALTER USER seddb WITH PASSWORD 'seddb'" && \
     createdb seddb && \
-    psql -f demodaten/seddb_demodata.dump.sql seddb && \
+    psql -f ~/demodaten/seddb_demodata.dump.sql seddb && \
     psql -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO seddb" seddb && \
-    /usr/lib/postgresql/9.4/bin/pg_ctl stop
+    $PGBIN/pg_ctl stop -m smart
+
+RUN rm -r ~/demodaten
 
 #
 # Set the default command to run when starting the container
 #
-CMD ["/usr/lib/postgresql/9.4/bin/postgres", "-D", \
-     "/var/lib/postgresql/9.4/main", "-c", \
-     "config_file=/etc/postgresql/9.4/main/postgresql.conf"]
+CMD ["/usr/lib/postgresql/13/bin/postgres", "-D", \
+     "/var/lib/postgresql/13/main", "-c", \
+     "config_file=/etc/postgresql/13/main/postgresql.conf"]
diff -r f3aa7a12c86a -r 13e2d38ad314 docker/Dockerfile.gwt-client
--- a/docker/Dockerfile.gwt-client	Mon Jul 12 14:39:58 2021 +0200
+++ b/docker/Dockerfile.gwt-client	Thu Feb 24 18:49:02 2022 +0100
@@ -5,7 +5,7 @@
 
 # Necessary to run further yum-installs inside Docker container,
 # if not already part of the base image:
-RUN yum -y install yum-plugin-ovl
+RUN yum -y install yum-plugin-ovl && rpm --rebuilddb
 
 # Install prerequisites
 RUN yum -y install maven mercurial tomcat gnu-free-sans-fonts curl
diff -r f3aa7a12c86a -r 13e2d38ad314 docker/README
--- a/docker/README	Mon Jul 12 14:39:58 2021 +0200
+++ b/docker/README	Thu Feb 24 18:49:02 2022 +0100
@@ -8,22 +8,10 @@
   gwt-client/src/main/webapp/WEB-INF/config.yaml
 
 
-Build:
-
-$ docker build -f docker/Dockerfile.db -t d4e/river_db .
-$ docker build -f docker/Dockerfile.artifacts -t d4e/river_artifacts .
-$ docker build -f docker/Dockerfile.gwt-client -t d4e/river_client .
-
+Build and run:
 
-Run:
-
-$ docker network create d4e_river
-$ docker run --name d4eriver-db  --network d4e_river \
-    -dp 2345:5432 d4e/river_db:latest
-$ docker run --name d4eriver-artifacts --network d4e_river \
-    -dp 8181:8181 d4e/river_artifacts
-$ docker run --name d4eriver-client --network d4e_river \
-    -v $PWD:/opt/d4e/river -dp 8080:8080 d4e/river_client
+$ cd docker
+$ docker-compose up
 
 The application should now be accessible on your docker host under
 port 8080 and path /d4e-river (e.g. http://your-host:8080/d4e-river).
diff -r f3aa7a12c86a -r 13e2d38ad314 docker/docker-compose.yml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/docker-compose.yml	Thu Feb 24 18:49:02 2022 +0100
@@ -0,0 +1,37 @@
+version: "3.5"
+services:
+  db:
+    container_name: "d4eriver-db"
+    build:
+      context: ../
+      dockerfile: ./docker/Dockerfile.db
+    image: "d4e/river_db"
+    networks:
+      - d4e_river
+  server:
+    container_name: "d4eriver-artifacts"
+    build:
+      context: ../
+      dockerfile: ./docker/Dockerfile.artifacts
+    image: "d4e/river_artifacts"
+    networks:
+      - d4e_river
+    depends_on:
+      - db
+  client:
+    container_name: "d4eriver-client"
+    build:
+      context: ../
+      dockerfile: ./docker/Dockerfile.gwt-client
+    image: "d4e/river_client"
+    networks:
+      - d4e_river
+    depends_on:
+      - server
+    volumes:
+      - ../:/opt/d4e/river
+    ports:
+      - 8080:8080
+networks:
+  d4e_river:
+    name: d4e_river


More information about the Dive4Elements-commits mailing list