diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..832489424d3bdf0d30b2760b8f31f606120622d3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.* +host-files/ diff --git a/README.md b/README.md index 8b3cde8f03100bb62b978dae46df67d57f036650..3e3dee496b31aa6be0f893f819e23b119452490f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,14 @@ ESAP-DB is an ESAP component providing managed database services. ## Installation -This project should be cloned in the directory containing the repositories https://git.astron.nl/astron-sdc/esap-api-gateway and https://git.astron.nl/astron-sdc/esap-gui. Once it is done, add this .env file in the esap-db/host-files directory: +After cloning the ESAP-DB repository: + +```bash +git clone git@git.astron.nl:astron-sdc/esap-db.git +cd esap-db +``` + +add this .env file in the host-files directory: ``` DOMAIN=localhost @@ -19,9 +26,9 @@ DBPROJECT_PASSWORD=postgres To check that ESAP-DB is working locally: ```bash -$ esap-db/host-files/run-tests.sh +host-files/run-tests.sh ``` -Upon success, the tests should pass. +Installation is successful if the tests pass. ## Using ESAP-DB @@ -29,7 +36,7 @@ Upon success, the tests should pass. In order to use ESAP-DB locally, you can launch the required services in a ternminal: ```bash -$ esap-db/host-files/run.sh +host-files/run.sh ``` In a browser, the ESAP-DB apis can be tested at the url `http://localhost:8001/docs` or `http://localhost:8001/redoc`. diff --git a/app/apis/v0/tables.py b/app/apis/v0/tables.py index 52262b2b7658e3983c2fa8c88234507c3ab86284..ff43d890f1523c559f7f09d4039cff46a6983190 100644 --- a/app/apis/v0/tables.py +++ b/app/apis/v0/tables.py @@ -1,5 +1,6 @@ """Definitions of the endpoints related the tables.""" import logging +import os import requests from fastapi import APIRouter @@ -89,7 +90,7 @@ def _post_esap_gateway_operation_paginated( if query['archive_uri'] == 'apertif': query['page'] = page query['page_size'] = 500 - data = session.get('http://esap-api:8000/esap-api/query/query', params=query) + data = session.get(f'{os.environ["ESAP_HOST"]}/esap-api/query/query', params=query) results = data.json() if query['archive_uri'] == 'apertif': data = results.pop('results') diff --git a/host-files/docker-compose.yml b/host-files/docker-compose.yml index 915af9b344877d1a0c052d9fa68110049527b467..d284d895fdb8129f0f0d5c2213fdc146ee331f19 100644 --- a/host-files/docker-compose.yml +++ b/host-files/docker-compose.yml @@ -22,32 +22,13 @@ services: - POSTGRES_USER=${DBPROJECT_USER} - POSTGRES_PASSWORD=${DBPROJECT_PASSWORD} - esap_api: - image: esap_api:latest - container_name: esap-api - environment: - - OIDC_RP_CLIENT_ID=669d7bef-32c0-4980-ae35-d8ede56bd5ef - - OIDC_RP_CLIENT_SECRET - - OIDC_OP_JWKS_ENDPOINT=https://iam-escape.cloud.cnaf.infn.it/jwk - - OIDC_OP_AUTHORIZATION_ENDPOINT=https://iam-escape.cloud.cnaf.infn.it/authorize - - OIDC_OP_TOKEN_ENDPOINT=https://iam-escape.cloud.cnaf.infn.it/token - - OIDC_OP_USER_ENDPOINT=https://iam-escape.cloud.cnaf.infn.it/userinfo - - LOGIN_REDIRECT_URL=http://localhost:3000/esap-gui/login - - LOGOUT_REDIRECT_URL=http://localhost:3000/esap-gui/logout - - LOGIN_REDIRECT_URL_FAILURE=http://localhost:3000/esap-gui/error - build: - context: ${ESAP_ROOT}/esap-api-gateway/esap - ports: - - 8000:8000 - restart: always - command: "python manage.py runserver 0.0.0.0:8000 --settings=esap.settings.dev" - esap_db: image: esap_db:latest container_name: esap-db stdin_open: true # docker run -i tty: true # docker run -t environment: + - ESAP_HOST=https://sdc-dev.astron.nl - SERVER_NAME=${DOMAIN?Variable not set} - SERVER_HOST=https://${DOMAIN?Variable not set} - SENTRY_DSN=https://nowhere.com @@ -62,12 +43,12 @@ services: - FIRST_SUPERUSER=esapadmin@nowhere.com - FIRST_SUPERUSER_PASSWORD=esapadmin build: - context: ${ESAP_ROOT}/esap-db + context: .. args: INSTALL_DEV: ${INSTALL_DEV-false} command: bash -c "scripts/prepare-app.sh && uvicorn app.main:app --port 8001 --host 0.0.0.0 --reload" volumes: - - ${ESAP_ROOT}/esap-db:/code + - ..:/code ports: - "8001:8001" depends_on: diff --git a/host-files/run-tests.sh b/host-files/run-tests.sh index c8b96ddd638278f612cb079cb098d880c074a2e7..cce4772bda6311f608c683d0616d94e41b228e78 100755 --- a/host-files/run-tests.sh +++ b/host-files/run-tests.sh @@ -3,9 +3,8 @@ # Exit in case of error set -e -export ESAP_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../.. &> /dev/null && pwd )" -export ESAP_DB_PATH=${ESAP_ROOT}/esap-db/host-files +export ESAP_DB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" ESAP_RUN_OPTIONS="-d" ${ESAP_DB_PATH}/run.sh -docker-compose -f docker-stack.yml exec -T esap_db bash /code/scripts/run-tests.sh "$@" -docker-compose -f docker-stack.yml down -v --remove-orphans +docker-compose -f ${ESAP_DB_PATH}/docker-stack.yml exec -T esap_db bash /code/scripts/run-tests.sh "$@" +docker-compose -f ${ESAP_DB_PATH}/docker-stack.yml down -v --remove-orphans diff --git a/host-files/run.sh b/host-files/run.sh index bab1994839dceb7bf74e6aaf98b226f9f8ed6f71..d1e8cd4744b463605d3883947b201c7398489ef5 100755 --- a/host-files/run.sh +++ b/host-files/run.sh @@ -3,15 +3,14 @@ # Exit in case of error set -e -export ESAP_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../.. &> /dev/null && pwd )" -export ESAP_DB_PATH=${ESAP_ROOT}/esap-db/host-files +export ESAP_DB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" DOMAIN=backend \ SMTP_HOST="" \ TRAEFIK_PUBLIC_NETWORK_IS_EXTERNAL=false \ INSTALL_DEV=true \ -docker-compose -f ${ESAP_DB_PATH}/docker-compose.yml --env-file ${ESAP_DB_PATH}/.env config > docker-stack.yml +docker-compose -f ${ESAP_DB_PATH}/docker-compose.yml --env-file ${ESAP_DB_PATH}/.env config > ${ESAP_DB_PATH}/docker-stack.yml -docker-compose -f docker-stack.yml build -docker-compose -f docker-stack.yml down -v --remove-orphans # Remove possibly previous broken stacks left hanging after an error -docker-compose -f docker-stack.yml up ${ESAP_RUN_OPTIONS} +docker-compose -f ${ESAP_DB_PATH}/docker-stack.yml build +docker-compose -f ${ESAP_DB_PATH}/docker-stack.yml down -v --remove-orphans # Remove possibly previous broken stacks left hanging after an error +docker-compose -f ${ESAP_DB_PATH}/docker-stack.yml up ${ESAP_RUN_OPTIONS}