view docker/README.md @ 4606:dfe9cde6a20c geoserver_sql_views

Reflect database model changes for SQL views in backend In principle, we could use many datasources with different database schemas, but this would imply changing GeoServer initialization, service filtering, endpoints and eventually more. Since we do not need it, just hard-code the schema name as a constant.
author Tom Gottfried <tom@intevation.de>
date Thu, 05 Sep 2019 12:23:31 +0200
parents 8dd59e2c9d3d
children
line wrap: on
line source

# Build and run your dev environment using Docker

- [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!

Other example commands, too, assume they are run from the root of your
checkout.

## 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:

```shell
docker network create gemma
```

### Database setup

Build `gemma_db` docker image with e.g.:

```shell
docker build -t gemma_db -f docker/Dockerfile.db .
```

In order to test the latest upstream PostgreSQL 11 and PostGIS 2.5,
use Dockerile.pg instead.

Get a running instance with e.g.:

```shell
docker run --name gemma-db -d -p 54321:5432 -v $PWD/schema:/opt/gemma \
           --network gemma gemma_db
```

Use `--network-alias gemma-db` if your container has a different name

Run tests for [Row-Level Security](https://www.postgresql.org/docs/11/ddl-rowsecurity.html) (RLS)
policies:

```shell
docker exec gemma-db ./run_tests.sh
```

### Create ER diagrams

Assuming you have installed `postgresql-autodoc` and
[graphviz](http://graphviz.org/) on a machine from which you can reach your
docker host, you can use the following:

ER diagram with waterway related tables:

```shell
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.

### GeoServer setup

Build `gemma_geoserver` docker image with e.g.:

```shell
docker build -t gemma_geoserver -f docker/Dockerfile.geoserv .
```

Get a running instance with e.g.:

```shell
docker run --name gemma-geoserver -d -p 8280:8080 --network gemma \
           gemma_geoserver
```

Use `--network-alias gemma-geoserver` if you give your container
a different name.

### Gemma backend setup

Build `gemma_backend` docker image with e.g.:

```shell
docker build -t gemma_backend -f docker/Dockerfile.backend .
```

Get a running instance with e.g.:

```shell
docker run --name gemma-backend -v $PWD:/opt/gemma -d -p 8200:8000 \
           --network gemma gemma_backend
```

Use `--network-alias gemma-backend` if you give your container
a different name.

### SPA setup

Build `gemma_spa` docker image with e.g.:

```shell
docker build -t gemma_spa -f docker/Dockerfile.spa .
```

Get a running instance with e.g.:

```shell
docker run --name gemma-spa -v $PWD/client:/opt/gemma/client -d -p 8290:8080 \
           --network gemma gemma_spa
```

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.