Skip to content

Commit

Permalink
Update docker files to support environment configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelavega committed Sep 14, 2018
1 parent 721922b commit 262691c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 51 deletions.
12 changes: 7 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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

Expand All @@ -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 .
Expand Down
69 changes: 50 additions & 19 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -29,36 +27,69 @@ services:
- ./charging-data:/data/db
charging:
image: conwetlab/biz-ecosystem-charging-backend
image: conwetlab/biz-ecosystem-charging-backend:develop
links:
- mongo
depends_on:
- mongo
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:

```
Expand Down
41 changes: 38 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 34 additions & 24 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 262691c

Please sign in to comment.