From bcb4c69677cf222563b27b1554b2785bcf000434 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 29 Sep 2023 10:51:48 +0200 Subject: [PATCH] add optional dpp_module and snapshots - dpp_module becomes optional - docker compose for simple devicehub and with the dpp module - changed logic in entrypoint so different parts are configured or - not depending on the new DPP_MODULE env var - optional snapshots - new default directory for SNAPSHOTS_PATH - new env var IMPORT_SNAPSHOTS to optionally import the snapshots or not - new Make file targets: - dc_up_devicehub: docker compose for simple devicehub - dc_up_devicehub_dpp: docker compose for devicehub with DPP_module --- .gitignore | 1 + Makefile | 14 ++++ docker-compose.yml | 96 +---------------------- docker-compose_devicehub-dpp.yml | 99 ++++++++++++++++++++++++ docker-compose_devicehub.yml | 48 ++++++++++++ docker/devicehub.entrypoint.sh | 65 +++++++++++----- examples/env.example | 15 ++-- examples/{ => snapshots}/snapshot01.json | 0 8 files changed, 216 insertions(+), 122 deletions(-) mode change 100644 => 120000 docker-compose.yml create mode 100644 docker-compose_devicehub-dpp.yml create mode 100644 docker-compose_devicehub.yml rename examples/{ => snapshots}/snapshot01.json (100%) diff --git a/.gitignore b/.gitignore index 39dff2b0..cde02b49 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,7 @@ env* examples/create-db2.sh package-lock.json snapshots/ +!examples/snapshots modules/ # emacs diff --git a/Makefile b/Makefile index a51c1cf5..942d8495 100644 --- a/Makefile +++ b/Makefile @@ -32,3 +32,17 @@ docker: $(MAKE) docker_build $(MAKE) docker_publish @printf "\ndocker images published\n" + +# manage 2 kinds of deployments with docker compose + +dc_up_devicehub: + docker compose -f docker-compose_devicehub.yml up || true + +dc_down_devicehub: + docker compose -f docker-compose_devicehub.yml down -v || true + +dc_up_devicehub_dpp: + docker compose -f docker-compose_devicehub-dpp.yml up || true + +dc_down_devicehub_dpp: + docker compose -f docker-compose_devicehub-dpp.yml down -v || true diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index e246a4c2..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,95 +0,0 @@ -version: "3.9" -services: - - devicehub-id-server: - init: true - image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp_docker__2c4b0006 - environment: - - DB_USER=${DB_USER} - - DB_PASSWORD=${DB_PASSWORD} - - DB_HOST=postgres-id-server - - DB_DATABASE=${DB_DATABASE} - - HOST=${HOST} - - EMAIL_DEMO=user5000@dhub.com - - PASSWORD_DEMO=${PASSWORD_DEMO} - - JWT_PASS=${JWT_PASS} - - SECRET_KEY=${SECRET_KEY} - - API_DLT=${API_DLT} - - API_RESOLVER=${API_RESOLVER} - - API_DLT_TOKEN=${API_DLT_TOKEN} - - DEVICEHUB_HOST=${SERVER_ID_DEVICEHUB_HOST} - - ID_FEDERATED=${SERVER_ID_FEDERATED} - - URL_MANUALS=${URL_MANUALS} - - ID_SERVICE=${SERVER_ID_SERVICE} - - AUTHORIZED_CLIENT_URL=${CLIENT_ID_DEVICEHUB_HOST} - ports: - - 5000:5000 - volumes: - - ${SNAPSHOTS_PATH}:/mnt/snapshots:ro - - shared:/shared:rw - - postgres-id-server: - image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp_docker__2c4b0006 - # 4. To create the database. - # 5. Give permissions to the corresponding users in the database. - # extra src https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables - environment: - - POSTGRES_PASSWORD=${DB_PASSWORD} - - POSTGRES_USER=${DB_USER} - - POSTGRES_DB=${DB_DATABASE} - # DEBUG - #ports: - # - 5432:5432 - # TODO persistence - #volumes: - # - pg_data:/var/lib/postgresql/data - - devicehub-id-client: - init: true - image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp_docker__2c4b0006 - environment: - - DB_USER=${DB_USER} - - DB_PASSWORD=${DB_PASSWORD} - - DB_HOST=postgres-id-client - - DB_DATABASE=${DB_DATABASE} - - HOST=${HOST} - - EMAIL_DEMO=user5001@dhub.com - - PASSWORD_DEMO=${PASSWORD_DEMO} - - JWT_PASS=${JWT_PASS} - - SECRET_KEY=${SECRET_KEY} - - API_DLT=${API_DLT} - - API_RESOLVER=${API_RESOLVER} - - API_DLT_TOKEN=${API_DLT_TOKEN} - - DEVICEHUB_HOST=${CLIENT_ID_DEVICEHUB_HOST} - - SERVER_ID_HOST=${SERVER_ID_DEVICEHUB_HOST} - - ID_FEDERATED=${CLIENT_ID_FEDERATED} - - URL_MANUALS=${URL_MANUALS} - - ID_SERVICE=${CLIENT_ID_SERVICE} - ports: - - 5001:5000 - volumes: - - ${SNAPSHOTS_PATH}:/mnt/snapshots:ro - - shared:/shared:ro - - postgres-id-client: - image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp_docker__2c4b0006 - # 4. To create the database. - # 5. Give permissions to the corresponding users in the database. - # extra src https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables - environment: - - POSTGRES_PASSWORD=${DB_PASSWORD} - - POSTGRES_USER=${DB_USER} - - POSTGRES_DB=${DB_DATABASE} - # 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 - -volumes: - shared: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 120000 index 00000000..2d3d96f0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1 @@ +docker-compose_devicehub-dpp.yml \ No newline at end of file diff --git a/docker-compose_devicehub-dpp.yml b/docker-compose_devicehub-dpp.yml new file mode 100644 index 00000000..089d7b80 --- /dev/null +++ b/docker-compose_devicehub-dpp.yml @@ -0,0 +1,99 @@ +version: "3.9" +services: + + devicehub-id-server: + init: true + image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp__285635b7 + environment: + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + - DB_HOST=postgres-id-server + - DB_DATABASE=${DB_DATABASE} + - HOST=${HOST} + - EMAIL_DEMO=${SERVER_ID_EMAIL_DEMO} + - PASSWORD_DEMO=${PASSWORD_DEMO} + - JWT_PASS=${JWT_PASS} + - SECRET_KEY=${SECRET_KEY} + - API_DLT=${API_DLT} + - API_RESOLVER=${API_RESOLVER} + - API_DLT_TOKEN=${API_DLT_TOKEN} + - DEVICEHUB_HOST=${SERVER_ID_DEVICEHUB_HOST} + - ID_FEDERATED=${SERVER_ID_FEDERATED} + - URL_MANUALS=${URL_MANUALS} + - ID_SERVICE=${SERVER_ID_SERVICE} + - AUTHORIZED_CLIENT_URL=${CLIENT_ID_DEVICEHUB_HOST} + - DPP_MODULE=y + - IMPORT_SNAPSHOTS=${IMPORT_SNAPSHOTS} + ports: + - 5000:5000 + volumes: + - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro + - shared:/shared:rw + + postgres-id-server: + image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__285635b7 + # 4. To create the database. + # 5. Give permissions to the corresponding users in the database. + # extra src https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables + environment: + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_USER=${DB_USER} + - POSTGRES_DB=${DB_DATABASE} + # DEBUG + #ports: + # - 5432:5432 + # TODO persistence + #volumes: + # - pg_data:/var/lib/postgresql/data + + devicehub-id-client: + init: true + image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp__285635b7 + environment: + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + - DB_HOST=postgres-id-client + - DB_DATABASE=${DB_DATABASE} + - HOST=${HOST} + - EMAIL_DEMO=${CLIENT_ID_EMAIL_DEMO} + - PASSWORD_DEMO=${PASSWORD_DEMO} + - JWT_PASS=${JWT_PASS} + - SECRET_KEY=${SECRET_KEY} + - API_DLT=${API_DLT} + - API_RESOLVER=${API_RESOLVER} + - API_DLT_TOKEN=${API_DLT_TOKEN} + - DEVICEHUB_HOST=${CLIENT_ID_DEVICEHUB_HOST} + - SERVER_ID_HOST=${SERVER_ID_DEVICEHUB_HOST} + - ID_FEDERATED=${CLIENT_ID_FEDERATED} + - URL_MANUALS=${URL_MANUALS} + - ID_SERVICE=${CLIENT_ID_SERVICE} + - DPP_MODULE=y + - IMPORT_SNAPSHOTS=${IMPORT_SNAPSHOTS} + ports: + - 5001:5000 + volumes: + - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro + - shared:/shared:ro + + postgres-id-client: + image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__285635b7 + # 4. To create the database. + # 5. Give permissions to the corresponding users in the database. + # extra src https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables + environment: + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_USER=${DB_USER} + - POSTGRES_DB=${DB_DATABASE} + # 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 + +volumes: + shared: diff --git a/docker-compose_devicehub.yml b/docker-compose_devicehub.yml new file mode 100644 index 00000000..567d7947 --- /dev/null +++ b/docker-compose_devicehub.yml @@ -0,0 +1,48 @@ +version: "3.9" +services: + + devicehub: + init: true + image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp__285635b7 + environment: + - DB_USER=${DB_USER} + - DB_PASSWORD=${DB_PASSWORD} + - DB_HOST=postgres + - DB_DATABASE=${DB_DATABASE} + - HOST=${HOST} + - EMAIL_DEMO=${EMAIL_DEMO} + - PASSWORD_DEMO=${PASSWORD_DEMO} + - JWT_PASS=${JWT_PASS} + - SECRET_KEY=${SECRET_KEY} + - DEVICEHUB_HOST=${DEVICEHUB_HOST} + - URL_MANUALS=${URL_MANUALS} + - AUTHORIZED_CLIENT_URL=${CLIENT_ID_DEVICEHUB_HOST} + - DPP_MODULE=n + - IMPORT_SNAPSHOTS=${IMPORT_SNAPSHOTS} + ports: + - 5000:5000 + volumes: + - ${SNAPSHOTS_PATH:-./examples/snapshots}:/mnt/snapshots:ro + - shared:/shared:rw + + postgres: + image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__285635b7 + # 4. To create the database. + # 5. Give permissions to the corresponding users in the database. + # extra src https://github.com/docker-library/docs/blob/master/postgres/README.md#environment-variables + environment: + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_USER=${DB_USER} + - POSTGRES_DB=${DB_DATABASE} + # 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 + +volumes: + shared: diff --git a/docker/devicehub.entrypoint.sh b/docker/devicehub.entrypoint.sh index 2678f8be..daf19950 100755 --- a/docker/devicehub.entrypoint.sh +++ b/docker/devicehub.entrypoint.sh @@ -7,16 +7,24 @@ set -x # 3. Generate an environment .env file. gen_env_vars() { - # generate config using env vars from docker - cat > .env < .env <