diff --git a/docker-compose_devicehub-dpp.yml b/docker-compose_devicehub-dpp.yml index d8fd14a6..4aec5f7d 100644 --- a/docker-compose_devicehub-dpp.yml +++ b/docker-compose_devicehub-dpp.yml @@ -29,6 +29,7 @@ services: volumes: - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro - shared:/shared:rw + - app_id_server:/opt/devicehub:rw postgres-id-server: image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__bcb4c696 @@ -74,6 +75,7 @@ services: volumes: - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro - shared:/shared:ro + - app_id_client:/opt/devicehub:rw postgres-id-client: image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__bcb4c696 @@ -97,3 +99,5 @@ services: volumes: shared: + app_id_client: + app_id_server: diff --git a/docker-compose_devicehub.yml b/docker-compose_devicehub.yml index eae7e3a6..f5b2bb7f 100644 --- a/docker-compose_devicehub.yml +++ b/docker-compose_devicehub.yml @@ -19,11 +19,13 @@ services: - AUTHORIZED_CLIENT_URL=${CLIENT_ID_DEVICEHUB_HOST} - DPP_MODULE=n - IMPORT_SNAPSHOTS=${IMPORT_SNAPSHOTS} + - DEPLOYMENT=${DEPLOYMENT} ports: - 5000:5000 volumes: - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro - shared:/shared:rw + - app:/opt/devicehub:rw postgres: image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__bcb4c696 @@ -34,15 +36,20 @@ services: - POSTGRES_PASSWORD=${DB_PASSWORD} - POSTGRES_USER=${DB_USER} - POSTGRES_DB=${DB_DATABASE} + volumes: + - pg_data:/var/lib/postgresql/data # DEBUG #ports: # - 5432:5432 - # TODO persistence - #volumes: - # - pg_data:/var/lib/postgresql/data - # TODO https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/ - #nginx + nginx: + image: nginx + ports: + - 8080:8080 + volumes: + - ./docker/nginx-devicehub.nginx.conf:/etc/nginx/nginx.conf:ro volumes: shared: + pg_data: + app: diff --git a/docker/devicehub.entrypoint.sh b/docker/devicehub.entrypoint.sh index daf19950..507befb0 100755 --- a/docker/devicehub.entrypoint.sh +++ b/docker/devicehub.entrypoint.sh @@ -172,7 +172,7 @@ config_dpp_part2() { } config_phase() { - init_flagfile='/already_configured' + init_flagfile='docker__already_configured' if [ ! -f "${init_flagfile}" ]; then # 7, 8, 9, 11 init_data @@ -211,10 +211,12 @@ main() { # 17. Use gunicorn # thanks https://akira3030.github.io/formacion/articulos/python-flask-gunicorn-docker.html - # TODO meanwhile no nginx (step 19), gunicorn cannot serve static files, then we prefer development server - #gunicorn --access-logfile - --error-logfile - --workers 4 -b :5000 app:app - # alternative: run development server - flask run --host=0.0.0.0 --port 5000 + if [ "${DEPLOYMENT:-}" = "PROD" ]; then + gunicorn --access-logfile - --error-logfile - --workers 4 -b :5000 app:app + else + # run development server + FLASK_DEBUG=1 flask run --host=0.0.0.0 --port 5000 + fi # DEBUG #sleep infinity diff --git a/docker/nginx-devicehub.nginx.conf b/docker/nginx-devicehub.nginx.conf new file mode 100644 index 00000000..759b396a --- /dev/null +++ b/docker/nginx-devicehub.nginx.conf @@ -0,0 +1,32 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +error_log /var/log/nginx/error.log; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + + +http { + #upstream socket_backend { + # server unix:/socket/gunicorn.sock fail_timeout=0; + #} + server { + listen 8080; + listen [::]:8080; + #server_name devicehub.example.org; + + location / { + # TODO env var on proxy_pass + proxy_pass http://devicehub:5000/; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + } + } +}