From 397e4978e200cf7843e675af827ad5256931b5f9 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 16 Feb 2024 11:01:46 +0100 Subject: [PATCH] docker refactor - use latest tag - use launcher (which builds and deploys the docker compose) - small fixes - updated README --- Makefile | 3 ++- README.md | 15 +++++++++++++-- docker-compose_devicehub-dpp.yml | 8 ++++---- docker/devicehub.entrypoint.sh | 7 +++++-- examples/env.example | 4 ++-- launcher.sh | 15 +++++++++++++++ 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100755 launcher.sh diff --git a/Makefile b/Makefile index 942d8495..e17d7822 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ project := dkr-dsg.ac.upc.edu/ereuse branch := `git branch --show-current` commit := `git log -1 --format=%h` -tag := ${branch}__${commit} +#tag := ${branch}__${commit} +tag := latest # docker images devicehub_image := ${project}/devicehub:${tag} diff --git a/README.md b/README.md index e306bb70..d81d69ff 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,9 @@ If you want to use oidc4vp you need set the vars: ``` You can see the [manual install step 9]('https://github.com/eReuse/devicehub-teal/blob/oidc4vp/README_MANUAL_INSTALLATION.md#installing') for get more detail. -4. Run the docker containers: +4. Build and run the docker containers: ``` - docker compose up + ./launcher.sh ``` To stop these docker containers you can use Ctl+C, and if you run again "compose up" you'll maintain the data and infrastructure state. @@ -79,6 +79,17 @@ If the deployment was end-to-end successful (two running Devicehub instances suc That means the two Devicehub instances are running in their containers, that can be reached as http://localhost:5000/ and http://localhost:5001/ +Once the devicehub instances are running, you might want to register a user bind to the DLT with the following commands (here, assumes you want to execute it on devicehub-id-client, you might also want to do it in devicehub-id-server). Change the variables accordingly + +``` + FILE=my_users_devicehub.json + DOCKER_SERVICE=devicehub-id-server + docker compose cp /path/to/${FILE} ${DOCKER_SERVICE}:/tmp/ + docker compose exec ${DOCKER_SERVICE} flask dlt_register_user /tmp/${FILE} +``` + +**my_users_devicehub.json** is a custom file which is similar to the one provided in `examples/users_devicehub.json` + 5. To shut down the services and remove the corresponding data, you can use: ``` docker compose down -v diff --git a/docker-compose_devicehub-dpp.yml b/docker-compose_devicehub-dpp.yml index c42f7e23..83bc700a 100644 --- a/docker-compose_devicehub-dpp.yml +++ b/docker-compose_devicehub-dpp.yml @@ -3,7 +3,7 @@ services: devicehub-id-server: init: true - image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp__c6ec6658 + image: dkr-dsg.ac.upc.edu/ereuse/devicehub:latest environment: - DB_USER=${DB_USER} - DB_PASSWORD=${DB_PASSWORD} @@ -32,7 +32,7 @@ services: - app_id_server:/opt/devicehub:rw postgres-id-server: - image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__c6ec6658 + image: dkr-dsg.ac.upc.edu/ereuse/postgres:latest # 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 @@ -49,7 +49,7 @@ services: devicehub-id-client: init: true - image: dkr-dsg.ac.upc.edu/ereuse/devicehub:dpp__c6ec6658 + image: dkr-dsg.ac.upc.edu/ereuse/devicehub:latest environment: - DB_USER=${DB_USER} - DB_PASSWORD=${DB_PASSWORD} @@ -78,7 +78,7 @@ services: - app_id_client:/opt/devicehub:rw postgres-id-client: - image: dkr-dsg.ac.upc.edu/ereuse/postgres:dpp__c6ec6658 + image: dkr-dsg.ac.upc.edu/ereuse/postgres:latest # 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 diff --git a/docker/devicehub.entrypoint.sh b/docker/devicehub.entrypoint.sh index dfc5fbda..24b5bb25 100755 --- a/docker/devicehub.entrypoint.sh +++ b/docker/devicehub.entrypoint.sh @@ -67,6 +67,7 @@ init_data() { # 11. Generate a minimal data structure. # TODO it has some errors (?) flask initdata || true + #flask dlt_register_user /opt/devicehub/examples/users_devicehub.json || true } big_error() { @@ -166,7 +167,8 @@ config_dpp_part1() { config_dpp_part2() { # 16. - flask check_install "${EMAIL_DEMO}" ${PASSWORD_DEMO} + # commented because this fails with wrong DLT credentials + #flask check_install "${EMAIL_DEMO}" "${PASSWORD_DEMO}" # 20. config server or client ID config_oidc } @@ -187,7 +189,8 @@ config_phase() { # # 15. Add inventory snapshots for user "${EMAIL_DEMO}". if [ "${IMPORT_SNAPSHOTS}" = 'y' ]; then - cp /mnt/snapshots/snapshot*.json ereuse_devicehub/commands/snapshot_files + mkdir -p ereuse_devicehub/commands/snapshot_files + cp /mnt/snapshots/snapshot*.json ereuse_devicehub/commands/snapshot_files/ /usr/bin/time flask snapshot "${EMAIL_DEMO}" ${PASSWORD_DEMO} fi diff --git a/examples/env.example b/examples/env.example index e781473e..732b684a 100644 --- a/examples/env.example +++ b/examples/env.example @@ -8,8 +8,8 @@ ABAC_URL=$ABAC_URL # you might change or register ID_FEDERATED if you change DEVICEHUB_HOST ID_FEDERATED='DH12' # TODO this should be guessed by DEVICEHUB_HOST, and avoid hardcode of ID_FEDERATED -SERVER_ID_FEDERATED='DH12' -CLIENT_ID_FEDERATED='DH20' +SERVER_ID_FEDERATED='DH8' +CLIENT_ID_FEDERATED='DH5' # Database Variables DB_USER='dhub' diff --git a/launcher.sh b/launcher.sh new file mode 100755 index 00000000..96a9e5c0 --- /dev/null +++ b/launcher.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e +set -u +# DEBUG +set -x + +main() { + cd "$(dirname "${0}")" + + make docker_build + docker compose up +} + +main "${@}"