From 262691c2c42753d03ea3c3c93e7f75f4685ef50b Mon Sep 17 00:00:00 2001 From: Francisco de la Vega Date: Fri, 14 Sep 2018 16:58:33 +0200 Subject: [PATCH] Update docker files to support environment configuration --- docker/Dockerfile | 12 ++++--- docker/README.md | 69 ++++++++++++++++++++++++++++----------- docker/docker-compose.yml | 41 +++++++++++++++++++++-- docker/entrypoint.sh | 58 ++++++++++++++++++-------------- 4 files changed, 129 insertions(+), 51 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9b164893..2266293c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:16.04 -MAINTAINER CoNWeT Lab. Universidad Politécnica de Madrid +LABEL Author="CoNWeT Lab. Universidad Politécnica de Madrid" RUN apt-get update && apt-get install -y --fix-missing \ gcc git wkhtmltopdf xvfb python2.7 python-pip \ @@ -11,18 +11,20 @@ RUN apt-get update && apt-get install -y --fix-missing \ ENV VERSION develop -WORKDIR business-ecosystem-charging-backend +WORKDIR /business-ecosystem-charging-backend RUN git checkout $VERSION && \ mkdir ./src/media && \ mkdir ./src/media/bills && \ mkdir ./src/media/assets && \ mkdir ./src/plugins && \ - mkdir ./src/user_settings + mkdir ./src/user_settings && \ + cp ./src/settings.py ./src/user_settings/settings.py && \ + cp ./src/services_settings.py ./src/user_settings/services_settings.py ENV WORKSPACE=`pwd` -# Install dependencies and sonfigure system to use volume settings +# Install dependencies and configure system to support volume settings RUN ./python-dep-install.sh && \ echo "from user_settings.settings import *" > ./src/settings.py @@ -33,7 +35,7 @@ VOLUME /business-ecosystem-charging-backend/src/plugins VOLUME /business-ecosystem-charging-backend/src/user_settings VOLUME /business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins -WORKDIR src +WORKDIR /business-ecosystem-charging-backend/src RUN rm wsgi.py COPY wsgi.py . diff --git a/docker/README.md b/docker/README.md index b8467003..4e9d0bcc 100644 --- a/docker/README.md +++ b/docker/README.md @@ -10,13 +10,11 @@ If you want to know what is behind the scenes of our container you can go ahead ## The Fastest Way -### New versions +Versions of the Business Ecosystem Charging Backend container higher than 5.4.1 use an external MongoDB container as database and are +configured in the same way as the software, using both, the standard `settings.py` file or the supported environment variables (min version 7.4.0). For details of the different configuration +options, have a look at the [Business API Ecosystem Installation Guide](https://business-api-ecosystem.readthedocs.io/en/develop/installation-administration-guide.html#configuring-the-charging-backend) -New versions of the Business Ecosystem Charging Backend container than 5.4.1 use an external MongoDB container as database and are -configured using the standard `settings.py` file as it is done with the software. - -To run the Business Ecosystem Charging Backend, `docker-compose` is used. To do so, you must create a folder to place a -new file file called `docker-compose.yml` that should include the following content: +To run the Business Ecosystem Charging Backend, `docker-compose` is used. To do so, you can use the file `docker-compose.yml` provided with the source code or create a new one with the following content: ``` version: '3' @@ -29,7 +27,7 @@ services: - ./charging-data:/data/db charging: - image: conwetlab/biz-ecosystem-charging-backend + image: conwetlab/biz-ecosystem-charging-backend:develop links: - mongo depends_on: @@ -37,28 +35,61 @@ services: ports: - 8006:8006 volumes: + # - ./charging-settings:/business-ecosystem-charging-backend/src/user_settings # Used if the settings files are provided through the volume - ./charging-bills:/business-ecosystem-charging-backend/src/media/bills - ./charging-assets:/business-ecosystem-charging-backend/src/media/assets - ./charging-plugins:/business-ecosystem-charging-backend/src/plugins - - ./charging-settings:/business-ecosystem-charging-backend/src/user_settings - ./charging-inst-plugins:/business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins environment: - - PAYPAL_CLIENT_ID=client_id - - PAYPAL_CLIENT_SECRET=client_secret -``` - -As you can see, some environment vars should be configured, in particular: - -* **PAYPAL_CLIENT_ID**: the client id of your application PayPal credentials used for charging users (a Sandbox account can be used for testing). -* **PAYPAL_CLIENT_SECRET**: the client secret of your application PayPal credentials used for charging users (a Sandbox account can be used for testing). - -Additionally, the biz-ecosystem-charging-backend image contains 4 volumes. In particular: + - BAE_CB_PAYMENT_METHOD=None # Paypal or None (testing mode payment disconected) + # - BAE_CB_PAYPAL_CLIENT_ID=client_id + # - BAE_CB_PAYPAL_CLIENT_SECRET=client_secret + + # ----- Database configuration ------ + - BAE_CB_MONGO_SERVER=mongo + - BAE_CB_MONGO_PORT=27017 + - BAE_CB_MONGO_DB=charging_db + # - BAE_CB_MONGO_USER=user + # - BAE_CB_MONGO_PASS=passwd + + # ----- Roles Configuration ----- + - BAE_LP_OAUTH2_ADMIN_ROLE=admin + - BAE_LP_OAUTH2_SELLER_ROLE=seller + - BAE_LP_OAUTH2_CUSTOMER_ROLE=customer + + # ----- Email configuration ------ + - BAE_CB_EMAIL=charging@email.com + # - BAE_CB_EMAIL_USER=user + # - BAE_CB_EMAIL_PASS=pass + # - BAE_CB_EMAIL_SMTP_SERVER=smtp.server.com + # - BAE_CB_EMAIL_SMTP_PORT=587 + + - BAE_CB_VERIFY_REQUESTS=True # Whether or not the BAE validates SSL certificates on requests to external components + + # ----- Site configuration ----- + - BAE_SERVICE_HOST=https://store.lab.fiware.org/ # External URL used to access the BAE + - BAE_CB_LOCAL_SITE=http://charging.docker:8006/ # Local URL of the charging backend + + # ----- APIs Conection config ----- + - BAE_CB_CATALOG=http://apis.docker:8080/DSProductCatalog + - BAE_CB_INVENTORY=http://apis.docker:8080/DSProductInventory + - BAE_CB_ORDERING=http://apis.docker:8080/DSProductOrdering + - BAE_CB_BILLING=http://apis.docker:8080/DSBillingManagement + - BAE_CB_RSS=http://rss.docker:8080/DSRevenueSharing + - BAE_CB_USAGE=http://apis.docker:8080/DSUsageManagement + - BAE_CB_AUTHORIZE_SERVICE=http://proxy.docker:8004/authorizeService/apiKeys +``` + +As you can see, the biz-ecosystem-charging-backend image defines 4 volumes. In particular: +* */business-ecosystem-charging-backend/src/user_settings*: This directory must include the *settings.py* and *services_settings.py* files with the software configuration, when the volume configuration is used. * */business-ecosystem-charging-backend/src/media/bills*: This directory contains the PDF invoices generated by the Business Ecosystem Charging Backend * */business-ecosystem-charging-backend/src/media/assets*: This directory contains the different digital assets uploaded by sellers to the Business Ecosystem Charging Backend * */business-ecosystem-charging-backend/src/plugins*: This directory is used for providing asset plugins (see section *Installing Asset Plugins*) -* */business-ecosystem-charging-backend/src/user_settings*: This directory must include the *settings.py* and *services_settings.py* files with the software configuration. * */business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins*: This directory includes the code of the plugins already installed +It can be seen, that the system can be configured with the environment variables defined by the software (min version 7.4.0). In this case, providing the settings file is +not mandatory, taking into account that the environment variables values override the file ones. + Once you have created the file, run the following command: ``` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7993e1a8..8576d2e3 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -16,11 +16,46 @@ services: ports: - 8006:8006 volumes: + # - ./charging-settings:/business-ecosystem-charging-backend/src/user_settings # Used if the settings files are provided through the volume - ./charging-bills:/business-ecosystem-charging-backend/src/media/bills - ./charging-assets:/business-ecosystem-charging-backend/src/media/assets - ./charging-plugins:/business-ecosystem-charging-backend/src/plugins - - ./charging-settings:/business-ecosystem-charging-backend/src/user_settings - ./charging-inst-plugins:/business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins environment: - - PAYPAL_CLIENT_ID=client_id - - PAYPAL_CLIENT_SECRET=client_secret + - BAE_CB_PAYMENT_METHOD=None # Paypal or None (testing mode payment disconected) + # - BAE_CB_PAYPAL_CLIENT_ID=client_id + # - BAE_CB_PAYPAL_CLIENT_SECRET=client_secret + + # ----- Database configuration ------ + - BAE_CB_MONGO_SERVER=mongo + - BAE_CB_MONGO_PORT=27017 + - BAE_CB_MONGO_DB=charging_db + # - BAE_CB_MONGO_USER=user + # - BAE_CB_MONGO_PASS=passwd + + # ----- Roles Configuration ----- + - BAE_LP_OAUTH2_ADMIN_ROLE=admin + - BAE_LP_OAUTH2_SELLER_ROLE=seller + - BAE_LP_OAUTH2_CUSTOMER_ROLE=customer + + # ----- Email configuration ------ + - BAE_CB_EMAIL=charging@email.com + # - BAE_CB_EMAIL_USER=user + # - BAE_CB_EMAIL_PASS=pass + # - BAE_CB_EMAIL_SMTP_SERVER=smtp.server.com + # - BAE_CB_EMAIL_SMTP_PORT=587 + + - BAE_CB_VERIFY_REQUESTS=True # Whether or not the BAE validates SSL certificates on requests to external components + + # ----- Site configuration ----- + - BAE_SERVICE_HOST=https://store.lab.fiware.org/ # External URL used to access the BAE + - BAE_CB_LOCAL_SITE=http://charging.docker:8006/ # Local URL of the charging backend + + # ----- APIs Conection config ----- + - BAE_CB_CATALOG=http://apis.docker:8080/DSProductCatalog + - BAE_CB_INVENTORY=http://apis.docker:8080/DSProductInventory + - BAE_CB_ORDERING=http://apis.docker:8080/DSProductOrdering + - BAE_CB_BILLING=http://apis.docker:8080/DSBillingManagement + - BAE_CB_RSS=http://rss.docker:8080/DSRevenueSharing + - BAE_CB_USAGE=http://apis.docker:8080/DSUsageManagement + - BAE_CB_AUTHORIZE_SERVICE=http://proxy.docker:8004/authorizeService/apiKeys diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 776ca838..80ce4366 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -29,17 +29,6 @@ function test_connection { echo "$1 connection, OK" } -# Validate that mandatory parameters has been provided -if [ -z $PAYPAL_CLIENT_ID ]; then - echo 'PAYPAL_CLIENT_ID environment variable not set' - exit 1 -fi - -if [ -z $PAYPAL_CLIENT_SECRET ]; then - echo 'PAYPAL_CLIENT_SECRET environment variable not set' - exit 1 -fi - # Check that the settings files have been included if [ ! -f /business-ecosystem-charging-backend/src/user_settings/settings.py ]; then echo "Missing settings.py file" @@ -55,35 +44,56 @@ if [ ! -f /business-ecosystem-charging-backend/src/user_settings/__init__.py ]; touch /business-ecosystem-charging-backend/src/user_settings/__init__.py fi -# Configure PayPal settings -sed -i "s|PAYPAL_CLIENT_ID = ''|PAYPAL_CLIENT_ID = '$PAYPAL_CLIENT_ID'|g" ./wstore/charging_engine/payment_client/paypal_client.py -sed -i "s|PAYPAL_CLIENT_SECRET = ''|PAYPAL_CLIENT_SECRET = '$PAYPAL_CLIENT_SECRET'|g" ./wstore/charging_engine/payment_client/paypal_client.py +# Create __init__.py file if not present (a volume has been bound) +if [ ! -f /business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins/__init__.py ]; then + touch /business-ecosystem-charging-backend/src/wstore/asset_manager/resource_plugins/plugins/__init__.py +fi # Ensure mongodb is running # Get MongoDB host and port from settings -MONGO_HOST=`grep -o "'HOST':.*" ./user_settings/settings.py | grep -o ": '.*'" | grep -oE "[^:' ]+"` -if [ -z ${MONGO_HOST} ]; then - MONGO_HOST=localhost +if [ -z ${BAE_CB_MONGO_SERVER} ]; then + MONGO_HOST=`grep -o "'HOST':.*" ./user_settings/settings.py | grep -o ": '.*'" | grep -oE "[^:' ]+"` + + if [ -z ${MONGO_HOST} ]; then + MONGO_HOST=localhost + fi +else + MONGO_HOST=${BAE_CB_MONGO_SERVER} fi -MONGO_PORT=`grep -o "'PORT':.*" ./user_settings/settings.py | grep -o ": '.*'" | grep -oE "[^:' ]+"` +if [ -z ${BAE_CB_MONGO_PORT} ]; then + MONGO_PORT=`grep -o "'PORT':.*" ./user_settings/settings.py | grep -o ": '.*'" | grep -oE "[^:' ]+"` -if [ -z ${MONGO_PORT} ]; then - MONGO_PORT=27017 + if [ -z ${MONGO_PORT} ]; then + MONGO_PORT=27017 + fi +else + MONGO_PORT=${BAE_CB_MONGO_PORT} fi test_connection "MongoDB" ${MONGO_HOST} ${MONGO_PORT} # Check that the required APIs are running -APIS_HOST=`grep "CATALOG =.*" ./user_settings/services_settings.py | grep -o "://.*:" | grep -oE "[^:/]+"` -APIS_PORT=`grep "CATALOG =.*" ./user_settings/services_settings.py | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +if [ -z ${BAE_CB_CATALOG} ]; then + APIS_HOST=`grep "CATALOG =.*" ./user_settings/services_settings.py | grep -o "://.*:" | grep -oE "[^:/]+"` + APIS_PORT=`grep "CATALOG =.*" ./user_settings/services_settings.py | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +else + APIS_HOST=`echo ${BAE_CB_CATALOG} | grep -o "://.*:" | grep -oE "[^:/]+"` + APIS_PORT=`echo ${BAE_CB_CATALOG} | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +fi test_connection "APIs" ${APIS_HOST} ${APIS_PORT} # Check that the RSS is running -RSS_HOST=`grep "RSS =.*" ./user_settings/services_settings.py | grep -o "://.*:" | grep -oE "[^:/]+"` -RSS_PORT=`grep "RSS =.*" ./user_settings/services_settings.py | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +if [ -z ${BAE_CB_RSS} ]; then + RSS_HOST=`grep "RSS =.*" ./user_settings/services_settings.py | grep -o "://.*:" | grep -oE "[^:/]+"` + RSS_PORT=`grep "RSS =.*" ./user_settings/services_settings.py | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +else + RSS_HOST=`echo ${BAE_CB_RSS} | grep -o "://.*:" | grep -oE "[^:/]+"` + RSS_PORT=`echo ${BAE_CB_RSS} | grep -oE ":[0-9]+" | grep -oE "[^:/]+"` +fi + test_connection "RSS" ${RSS_HOST} ${RSS_PORT} echo "Starting charging server"