Deploying Flask/Bottle Python app( Rest API ) on SAP Cloud Foundry
I am writing this blog to describe some easy steps to deploy a Python based REST API( Bottle / Flask ) application on the SAP cloud foundry environment.
The current python application is a knapsack optimization problem solver created on Python using Bottle server and Google OR-tools.
Account setup Steps:
- You need to have an SCP neo trial account or a US – EAST (VA ) AWS account or a US West (CA) running on Azure in order to try SAP Cloud foundry.
- Once that is done, follow the steps 4 to 6 on the tutorial here provided by SAP which help you with basic account setup.
Application structuring and deployment:
- The basic structure of a Python application on the SAP Cloud foundry should be as below, can also be referred at my GIT( https://github.com/rafiqhasan/SAPCFKnapsack/tree/master/KnapSack )
- Procfile: File which contains Cloud foundry start command.
- requirements.txt: File which contains the names of external python libraries needed for this application.
- runtime.txt: Specifies python version to be installed for this application
- Once you have the application structured , start cmd on your windows based system( try similar command on linux / mac)
- CD to the project folder on your system, ex:
- To push the application to the cloud foundry environment, simply use the command:
cf push myappname
- where “myappname” can be any name that you want
After the application is deployed, you will get the output as below on the CMD console
The URL can be seen here which can then be tried on the web-browser or via postman tools to check if you application is working:
The application details can also be seen on your SAP Cloud platform account:
How to push if i have multiple py files in my project ?
Thanks in advance