From 56d8aadf837e5e6f49161b43c2cc09beb8e808c8 Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 27 Jan 2025 17:52:24 +0100 Subject: [PATCH] docker: docker for devicehub and idhub as profile --- .dockerignore | 2 ++ .env.example | 17 +++++++++++++---- docker-compose.yml | 19 ++++++++++++++----- docker-reset.sh | 11 ++++++++++- docker/devicehub-django.Dockerfile | 1 + 5 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9bdf429 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +db +.git diff --git a/.env.example b/.env.example index 9728685..f67e720 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,15 @@ +#### +# DEV OPTIONS +#### + +DEV_DOCKER_ALWAYS_BUILD=false + #### # DEVICEHUB #### -DH_DOMAIN=localhost -DH_PORT=8000 +DEVICEHUB_DOMAIN=localhost +DEVICEHUB_PORT=8001 DEMO=true # note that with DEBUG=true, logs are more verbose (include tracebacks) DEBUG=true @@ -20,7 +26,7 @@ EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend" EMAIL_FILE_PATH="/tmp/app-messages" ENABLE_EMAIL=false PREDEFINED_TOKEN='5018dd65-9abd-4a62-8896-80f34ac66150' -DH_ALLOWED_HOSTS=${DH_DOMAIN},${DH_DOMAIN}:${DH_PORT},127.0.0.1,127.0.0.1:${DH_PORT} +DEVICEHUB_ALLOWED_HOSTS=${DEVICEHUB_DOMAIN},${DEVICEHUB_DOMAIN}:${DEVICEHUB_PORT},127.0.0.1,127.0.0.1:${DEVICEHUB_PORT} # TODO review these vars #SNAPSHOTS_DIR=/path/to/TODO #EVIDENCES_DIR=/path/to/TODO @@ -29,8 +35,11 @@ DH_ALLOWED_HOSTS=${DH_DOMAIN},${DH_DOMAIN}:${DH_PORT},127.0.0.1,127.0.0.1:${DH_P # IDHUB #### +IDHUB_ENABLED=false + IDHUB_DOMAIN=localhost -IDHUB_ALLOWED_HOSTS=${IDHUB_DOMAIN},${IDHUB_DOMAIN}:9001,127.0.0.1,127.0.0.1:9001 +IDHUB_PORT=9001 +IDHUB_ALLOWED_HOSTS=${IDHUB_DOMAIN},${IDHUB_DOMAIN}:${IDHUB_PORT},127.0.0.1,127.0.0.1:${IDHUB_PORT} IDHUB_TIME_ZONE='Europe/Madrid' #IDHUB_SECRET_KEY='uncomment-it-and-fill-this' # enable dev flags when DEVELOPMENT deployment diff --git a/docker-compose.yml b/docker-compose.yml index 7b9653a..76fba2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,21 +1,29 @@ services: devicehub-django: init: true + image: farga.pangea.org/ereuse/devicehub-django/latest build: + context: . dockerfile: docker/devicehub-django.Dockerfile environment: - DEBUG=${DEBUG:-false} - - DOMAIN=${DH_DOMAIN:-localhost} - - PORT=${DH_PORT:-8000} - - ALLOWED_HOSTS=${DH_ALLOWED_HOSTS:-$DH_DOMAIN} + - DOMAIN=${DEVICEHUB_DOMAIN:-localhost} + - PORT=${DEVICEHUB_PORT:-8000} + - ALLOWED_HOSTS=${DEVICEHUB_ALLOWED_HOSTS:-$DEVICEHUB_DOMAIN} - DEMO=${DEMO:-false} - PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-} - DPP=${DPP:-false} + # TODO manage volumes dev vs prod volumes: - .:/opt/devicehub-django ports: - - ${DH_PORT}:${DH_PORT} + - ${DEVICEHUB_PORT:-8000}:${DEVICEHUB_PORT:-8000} + + # TODO add database service for idhub, meanwhile sqlite + idhub: + # https://docs.docker.com/compose/how-tos/profiles/ + profiles: [idhub] init: true image: farga.pangea.org/ereuse/idhub/latest environment: @@ -39,8 +47,9 @@ services: - EMAIL_PORT=${IDHUB_EMAIL_PORT} - EMAIL_USE_TLS=${IDHUB_EMAIL_USE_TLS} - EMAIL_BACKEND=${IDHUB_EMAIL_BACKEND} - - SUPPORTED_CREDENTIALS=['CourseCredential', 'EOperatorClaim', 'FederationMembership', 'FinancialVulnerabilityCredential', 'MembershipCard'] + - SUPPORTED_CREDENTIALS=['DeviceSnapshotV1'] - SYNC_ORG_DEV=${IDHUB_SYNC_ORG_DEV} ports: - 9001:9001 + # TODO add database service for idhub, meanwhile sqlite diff --git a/docker-reset.sh b/docker-reset.sh index 8bbc229..21a0856 100755 --- a/docker-reset.sh +++ b/docker-reset.sh @@ -19,12 +19,21 @@ main() { cp -v .env.example .env echo "WARNING: .env was not there, .env.example was copied, this only happens once" fi + + # load vars + . ./.env + + if [ "${IDHUB_ENABLED:-}" = 'true' ]; then + export COMPOSE_PROFILES='idhub' + fi # remove old database rm -vfr ./db/* # deactivate configured flag rm -vfr ./already_configured docker compose down -v - docker compose build + if [ "${DEV_DOCKER_ALWAYS_BUILD:-}" = 'true' ]; then + docker compose build + fi docker compose up ${detach_arg:-} } diff --git a/docker/devicehub-django.Dockerfile b/docker/devicehub-django.Dockerfile index 0f0d408..7145534 100644 --- a/docker/devicehub-django.Dockerfile +++ b/docker/devicehub-django.Dockerfile @@ -37,6 +37,7 @@ RUN pip install -i https://test.pypi.org/simple/ ereuseapitest==0.0.14 # Set PYTHONPATH to include the directory with the xapian module ENV PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages" +COPY . . COPY docker/devicehub-django.entrypoint.sh / RUN chown -R app:app /opt/devicehub-django