Technical Articles
Running UI5 , Python (Flask) Application Docker Containers along with SAP’s PostgreSQL and XSUAA on SAP Cloud Platform (Foundry)
Introduction
Docker has been there for a while and offers a variety of advantages. SAP Cloud Platform also supports the deployment of Docker Images, which is a feature of Cloud Foundry, for further details the official documentation can be referred. Cloud Foundry uses Deigo to run the docker images.
In this tutorial, we will run 2 docker images (UI5 and Python) which will be bonded with PostgreSQL services and XSUAA for app routing, apart from these 2 images, an app router will be required to run the route between these applications.
This tutorial is more of a POC, hence all the best practices and security guidelines might not be taken into account 🙂
Prerequisite
- SAP Cloud Foundry account having (APP Runtime, PostgreSQL Instance, XSUAA).
- CF CLI – tutorial for downloading.
- App Router – blog for setting it up, for more understanding – use the link.
Let’s Get Started
- Use cf login to login to your SAP Cloud Platform sub account and space via command line.
- Let us push the ui5 image first (Replace APP-NAME with your application name)
cf push APP-NAME --docker-image munishsuri/ui5-test:latest
3. push the python image (Which will be talking to the PostgreSQL service) (Replace APP-NAME with your application name)
cf push APP-NAME --docker-image munishsuri/python-test:latest
4. Now we have to configure the app-router , bet before that let us create XSUAA instance and for that , let us use xs-security.json to create the service instance.
{
"xsappname" : "<your app name>",
"tenant-mode" : "dedicated"
}
go to the directory , where you have saved the xs-security.json file then execute the below command via cli to create the instance
cf create-service xsuaa application <INSTANCE_NAME> -c xs-security.json
5. Now let us configure the app router.
a. xs-app.json for routing
{
"authenticationMethod": "route",
"routes": [
{
"source": "^/myappopen/(.*)$",
"target": "$1",
"destination": "myappopen"
},{
"source": "^/python-test/(.*)$",
"target": "$1",
"destination": "python-test"
}
]
}
b. manifest.yml of app router
things to be configured
- <APP_ROUTER_NAME> – name which you want to give to the approuter
- <PATH_OF_APP_ROUTER> – directory where app router is stored
- <URL_OF_UI5_APP> – the previously deployed ui5 app (docker)
- <URL_OF_PYTHON_APP> – the previously deployed python app (docker)
- <XSUAA_INSTANCE_NAME> – the name of instance which was given in the cli.
applications:
- name: <APP_ROUTER_NAME>
path: <PATH_OF_APP_ROUTER>
memory: 256M
env:
destinations: >
[
{
"name":"myappopen",
"url":"<URL_OF_UI5_APP>"
},{
"name":"python-test",
"url":"<URL_OF_PYTHON_APP>"
}
]
services:
- <XSUAA_INSTANCE_NAME>
Please use the below command
cf push
Now the approuter should be up and running and you can access the app via the below link.
<YOUR_APP_ROUTER>/myappopen/
<YOUR_APPA_ROUTER> – will be the URL, you will get post-app deployment. /myappopen/ , was configured in the manifest.yml and xs-app.json
Let us create an instance of PostgreSQL , from the cloud platform sub-account , we will be using the dev version of it.
Post creation of this, we will be using the environment variables values to set up via (though it is not a best practice, for the purpose of POC we are using it), ideally, the app should be able to access the environment variables.
you may bind the instance of PostgreSQL to the python app deployed.
Post Binding copy the parameter values and paste in the ui.
Kindly restart the python application post binding the service.
To View the UI : use the below URL
<URL_APP_ROUTER>/myappopen/
Click on Set Pstgres Values to the set the Parameter, click on Add Id to insert a Random number in the DB, which will displayed in the list automatically.
!!! Congratulations !!!
You have successfully deployed Python and UI5 application container on SAP Cloud Platform, having XSUAA and PostgreSQL in place, along with an app router.