changeset 2163:b6b699385302

Added docker compose support.
author Bjoern Schilberg <bjoern@intevation.de>
date Fri, 08 Feb 2019 13:18:34 +0100
parents 0627565fb4d2
children 0e2f4b059897
files docker/README.md docker/docker-compose.yml
diffstat 2 files changed, 154 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/docker/README.md	Fri Feb 08 13:06:16 2019 +0100
+++ b/docker/README.md	Fri Feb 08 13:18:34 2019 +0100
@@ -1,12 +1,15 @@
-# Setup dev environment using Docker
+# Build and run your dev environment using Docker
 
-- [Setup dev environment using Docker](#setup-dev-environment-using-docker)
-  - [Network setup](#network-setup)
-  - [Database setup](#database-setup)
-  - [Create ER diagrams](#create-er-diagrams)
-  - [GeoServer setup](#geoserver-setup)
-  - [Gemma backend setup](#gemma-backend-setup)
-  - [SPA setup](#spa-setup)
+- [Build and run your dev environment using Docker](#build-and-run-your-dev-environment-using-docker)
+  - [Build and run your gemma application with Docker Compose in one step](#build-and-run-your-gemma-application-with-docker-compose-in-one-step)
+    - [Hints and tricks](#hints-and-tricks)
+  - [Build and run the gemma application with Docker manually](#build-and-run-the-gemma-application-with-docker-manually)
+    - [Network setup](#network-setup)
+    - [Database setup](#database-setup)
+    - [Create ER diagrams](#create-er-diagrams)
+    - [GeoServer setup](#geoserver-setup)
+    - [Gemma backend setup](#gemma-backend-setup)
+    - [SPA setup](#spa-setup)
 
 Run the `build` commands from the root of your checkout, because it is
 assumed as the context!
@@ -14,7 +17,71 @@
 Other example commands, too, assume they are run from the root of your
 checkout.
 
-## Network setup
+## Build and run your gemma application with Docker Compose in one step
+
+Requires at least Docker Engine release 17.12.0+. Because of Compose file
+format 3.5 for named networks.
+
+If you fiddle around with the following error message: `Version in
+"./docker-compose.yml" is unsupported` take a look at the comments in the
+head of the `docker-compose.yml` file.
+
+From your docker directory, start up your gemma application by running
+`docker-compose up`. Here an example for build and running the gemma
+application:
+
+```shell
+cd docker
+docker-compose -p gemma up
+```
+
+Note: The `-p` flag specifies an alternate project name (default: directory
+name).
+
+Now you should be able to use the application in your browser by going to
+`http://HOSTNAME:8290`, with `HOSTNAME` being the hostname of your docker
+host.
+
+Stop the application, either by running `docker-compose down` from within your
+docker directory in the second terminal, or by hitting `CTRL+C` in the
+original terminal where you started the gemma application.
+
+### Hints and tricks
+
+If you want to run your services in the background, you can pass the `-d` flag
+(for `detached` mode) to `docker-compose up` and use `docker-compose ps` to see
+what is currently running. Take a look at the following example.
+
+```shell
+docker-compose up -d
+Starting gemma_db ...
+Starting gemma_db ... done
+Starting gemma_geoserver ...
+Starting gemma_geoserver ... done
+Starting gemma_backend ...
+Starting gemma_backend ... done
+Starting gemma_spa ...
+Starting gemma_spa ... done
+```
+
+```shell
+docker-compose ps
+     Name                    Command               State            Ports
+----------------------------------------------------------------------------------
+gemma_backend     /usr/local/bin/gemma -c /o ...   Up      0.0.0.0:8200->8000/tcp
+gemma_db          /usr/lib/postgresql/11/bin ...   Up      0.0.0.0:54321->5432/tcp
+gemma_geoserver   /usr/share/tomcat8/bin/cat ...   Up      0.0.0.0:8280->8080/tcp
+gemma_spa         /bin/sh -c make -f Makefil ...   Up      0.0.0.0:8290->8080/tcp
+```
+
+For more infos about Docker Compose take a look at:
+https://docs.docker.com/compose/
+
+## Build and run the gemma application with Docker manually
+
+Or build and run your dev enviroment manually by the following steps.
+
+### Network setup
 
 Create a network to connect containers:
 
@@ -22,7 +89,7 @@
 docker network create gemma
 ```
 
-## Database setup
+### Database setup
 
 Build `gemma_db` docker image with e.g.:
 
@@ -46,7 +113,7 @@
 docker exec gemma_db ./run_tests.sh
 ```
 
-## Create ER diagrams
+### Create ER diagrams
 
 Assuming you have installed `postgresql-autodoc` and
 [graphviz](http://graphviz.org/) on a machine from which you can reach your
@@ -64,7 +131,7 @@
 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.
 
-## GeoServer setup
+### GeoServer setup
 
 Build `gemma_geoserver` docker image with e.g.:
 
@@ -82,7 +149,7 @@
 Use `--network-alias gemma_geoserver` if you give your container
 a different name.
 
-## Gemma backend setup
+### Gemma backend setup
 
 Build `gemma_backend` docker image with e.g.:
 
@@ -100,7 +167,7 @@
 Use `--network-alias gemma_backend` if you give your container
 a different name.
 
-## SPA setup
+### SPA setup
 
 Build `gemma_spa` docker image with e.g.:
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/docker-compose.yml	Fri Feb 08 13:18:34 2019 +0100
@@ -0,0 +1,73 @@
+# If you fiddle around with the following error message:
+# Version in "./docker-compose.yml" is unsupported
+#
+# Option 1)
+# Update docker and docker compose to at least docker version 17.12.0+.
+#
+# Option 2)
+# Change version: "3.5" to version: "3"
+# And delete the name configuration form `networks:` below.
+#
+version: "3.5"
+services:
+  gemma_db:
+    container_name: gemma_db
+    build:
+      context: ../
+      dockerfile: docker/Dockerfile.db
+    image: "gemma_db"
+    volumes:
+    - ../schema:/opt/gemma
+    networks:
+    - gemma
+    ports:
+    - "54321:5432"
+  gemma_geoserver:
+    container_name: gemma_geoserver
+    build:
+      context: ../
+      dockerfile: docker/Dockerfile.geoserv
+    depends_on:
+      - gemma_db
+    image: "gemma_geoserver"
+    networks:
+    - gemma
+    ports:
+     - "8280:8080"
+  gemma_backend:
+    container_name: gemma_backend
+    build:
+      context: ../
+      dockerfile: docker/Dockerfile.backend
+    depends_on:
+      - gemma_db
+      - gemma_geoserver
+    image: "gemma_backend"
+    volumes:
+    - ../:/opt/gemma
+    networks:
+    - gemma
+    ports:
+     - "8200:8000"
+  gemma_spa:
+    container_name: gemma_spa
+    build:
+      context: ../
+      dockerfile: docker/Dockerfile.spa
+    depends_on:
+      - gemma_backend
+      - gemma_geoserver
+    image: "gemma_spa"
+    volumes:
+    - ../client:/opt/gemma/client
+    networks:
+    - gemma
+    ports:
+     - "8290:8080"
+
+networks:
+  gemma:
+      # name: gemma needs at least docker version 17.12.0+
+      # API version: "3.5"
+      # https://docs.docker.com/compose/compose-file/#name-1
+      name: gemma