From c3da0947af82c6ef3959987ac4f2c610e411145a Mon Sep 17 00:00:00 2001
From: Markus Scheidgen <markus.scheidgen@gmail.com>
Date: Wed, 18 Nov 2020 14:58:01 +0100
Subject: [PATCH] Fixes to the oasis documentation and operation.

---
 .../gunicorn.conf => gunicorn.conf            |  0
 ops/docker-compose/nomad-oasis/README.md      | 18 +++++---
 .../nomad-oasis/docker-compose.yml            |  8 ++--
 .../nomad-oasis/gunicorn.log.conf             | 42 -------------------
 run.sh                                        | 10 +++--
 5 files changed, 22 insertions(+), 56 deletions(-)
 rename ops/docker-compose/nomad-oasis/gunicorn.conf => gunicorn.conf (100%)
 delete mode 100644 ops/docker-compose/nomad-oasis/gunicorn.log.conf

diff --git a/ops/docker-compose/nomad-oasis/gunicorn.conf b/gunicorn.conf
similarity index 100%
rename from ops/docker-compose/nomad-oasis/gunicorn.conf
rename to gunicorn.conf
diff --git a/ops/docker-compose/nomad-oasis/README.md b/ops/docker-compose/nomad-oasis/README.md
index bbc1396444..eecb3579c0 100644
--- a/ops/docker-compose/nomad-oasis/README.md
+++ b/ops/docker-compose/nomad-oasis/README.md
@@ -86,6 +86,8 @@ services:
         restart: always
         image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
         container_name: nomad_oasis_elastic
+        environment:
+            - discovery.type=single-node
         volumes:
             - nomad_oasis_elastic:/usr/share/elasticsearch/data
 
@@ -133,8 +135,6 @@ services:
         volumes:
             - ./nomad.yaml:/app/nomad.yaml
             - ./env.js:/app/gui/build/env.js
-            - ./gunicorn.log.conf:/app/gunicorn.log.conf
-            - ./gunicorn.conf:/app/gunicorn.conf
             - nomad_oasis_files:/app/.volumes/fs
         command: ["./run.sh", "/nomad-oasis"]
 
@@ -162,7 +162,7 @@ There are no mandatory changes necessary.
 
 A few things to notice:
 - All services use docker volumes for storage. This could be changed to host mounts.
-- It mounts three configuration files that need to be provided (see below): `nomad.yaml`, `nginx.conf`, `env.js`, `gunicorn.conf`, `gunicorn.log.conf`.
+- It mounts three configuration files that need to be provided (see below): `nomad.yaml`, `nginx.conf`, `env.js`.
 - The only exposed port is `80`. This could be changed to a desired port if necessary.
 - The NOMAD images are pulled from our gitlab in Garching, the other services use images from a public registry (*dockerhub*).
 - All container will be named `nomad_oasis_*`. These names can be used to later reference the container with the `docker` cmd.
@@ -289,13 +289,19 @@ A few things to notice:
 
 ### gunicorn
 
-Simply create empty `gunicorn.conf` and `gunicorn.log.conf` in the beginning. Gunicorn
-is the WSGI-server that runs the nomad app. Consult the [gunicorn documentation](https://docs.gunicorn.org/en/stable/configure.html)
-for configuration options.
+Gunicorn is the WSGI-server that runs the nomad app. Consult the
+[gunicorn documentation](https://docs.gunicorn.org/en/stable/configure.html) for
+configuration options.
 
 ## Starting and stopping
 
 If you prepared the above files, simply use the usual `docker-compose` commands to start everything.
+
+To make sure you have the latest docker images for everything run this first:
+```
+docker-compose pull
+```
+
 In the beginning and for debugging problems, it is recommended to start services separately:
 ```
 docker-compose up -d mongodb elastic rabbitmq
diff --git a/ops/docker-compose/nomad-oasis/docker-compose.yml b/ops/docker-compose/nomad-oasis/docker-compose.yml
index 56b51d96de..62316a72c5 100644
--- a/ops/docker-compose/nomad-oasis/docker-compose.yml
+++ b/ops/docker-compose/nomad-oasis/docker-compose.yml
@@ -24,6 +24,8 @@ services:
         restart: always
         image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
         container_name: nomad_oasis_elastic
+        environment:
+            - discovery.type=single-node
         volumes:
             - nomad_oasis_elastic:/usr/share/elasticsearch/data
 
@@ -42,7 +44,7 @@ services:
     # nomad worker (processing)
     worker:
         restart: always
-        image: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:oasis-migration
+        image: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:stable
         container_name: nomad_oasis_worker
         environment:
             <<: *nomad_backend_env
@@ -59,7 +61,7 @@ services:
     # nomad app (api + gui)
     app:
         restart: always
-        image: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:oasis-migration
+        image: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:stable
         container_name: nomad_oasis_app
         environment:
             <<: *nomad_backend_env
@@ -71,8 +73,6 @@ services:
         volumes:
             - ./nomad.yaml:/app/nomad.yaml
             - ./env.js:/app/gui/build/env.js
-            - ./gunicorn.log.conf:/app/gunicorn.log.conf
-            - ./gunicorn.conf:/app/gunicorn.conf
             - nomad_oasis_files:/app/.volumes/fs
         command: ["./run.sh", "/nomad-oasis"]
 
diff --git a/ops/docker-compose/nomad-oasis/gunicorn.log.conf b/ops/docker-compose/nomad-oasis/gunicorn.log.conf
deleted file mode 100644
index 00f47379ea..0000000000
--- a/ops/docker-compose/nomad-oasis/gunicorn.log.conf
+++ /dev/null
@@ -1,42 +0,0 @@
-[loggers]
-keys=root, gunicorn.error, gunicorn.access
-
-[handlers]
-keys=console, access, error
-
-[formatters]
-keys=generic
-
-[logger_root]
-level=INFO
-handlers=console
-
-[logger_gunicorn.error]
-level=INFO
-handlers=error
-qualname=gunicorn.error
-
-[logger_gunicorn.access]
-level=INFO
-handlers=access
-qualname=gunicorn.access
-
-[handler_console]
-class=StreamHandler
-formatter=generic
-args=(sys.stdout, )
-
-[handler_access]
-class=StreamHandler
-formatter=generic
-args=(sys.stdout, )
-
-[handler_error]
-class=StreamHandler
-formatter=generic
-args=(sys.stdout, )
-
-[formatter_generic]
-format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
-datefmt=%Y-%m-%d %H:%M:%S
-class=logging.Formatter
diff --git a/run.sh b/run.sh
index d2355df514..ce2668b1a4 100644
--- a/run.sh
+++ b/run.sh
@@ -1,4 +1,6 @@
-#!/bin/sh
-
-find gui/build -type f -exec sed -i "s_/fairdi/nomad/latest/gui_$1/gui_g" {} \;
-python -m gunicorn.app.wsgiapp --config gunicorn.conf --log-config gunicorn.log.conf -b 0.0.0.0:8000 nomad.app:app
\ No newline at end of file
+#!/bin/bash
+find gui/build -type f | xargs -L1 bash -c 'sed "s_/fairdi/nomad/latest/gui_$1/gui_g" $2 > /tmp/temp_file; cp /tmp/temp_file $2;' -- $1
+params=()
+[ -e gunicorn.conf ] && params+=(--config gunicorn.conf)
+[ -e gunicorn.log.conf ] && params+=(--log-config, gunicorn.log.conf)
+python -m gunicorn.app.wsgiapp "${params[@]}" -b 0.0.0.0:8000 nomad.app:app
\ No newline at end of file
-- 
GitLab