Skip to content

Simply python applicaiotn , and make it runing on the SAP Business Technology Platform Cloud Foundry Enviroment

Notifications You must be signed in to change notification settings

seyaFly/SAPBTP_PYTHON_SIMPLE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 中文

Table Of Content

Preparation

BTP Account

Use this link to apply and setup the BTP trial or enterpise enviroment

Tools

Python

Option1:

Install and setup from python offical website

Option2:

Install and setup from python-guide

IDE

we can use the VSC as you favourite development IDE, or other IDE you like.

Development

Steps:

  1. download the dependency , vitualenv and flask

    pip install virtualenv
    pip install Flask
    
  2. create the project folder and Initializa vitual enviroment

       mkdir demo
       cd demo
       virtualenv flask
    
  3. add file app.py with the below simple python code

    app.py

    python code :

    from flask import Flask
    import os
    app = Flask(__name__)
    
    cf_port = os.getenv("PORT")
    
    @app.route('/')
    def hello_world():
       return 'Hello this is the BTP python demo!'
    
    if __name__ == '__main__':
      if cf_port is None:
       app.run(host='0.0.0.0', port=5000, debug=True)
    else:
       app.run(host='0.0.0.0', port=int(cf_port), debug=True)

Test(local)

  1. Run python project via command line python app.py

  2. Test with the link mentioned inthe command line

python_test

  1. after you get the below response , your python applicaiton is runtime fine
 Hello this is the BTP python demo!

Deployment

Deploy for BTP:

  1. set cloud foundry endpoint via command :

    cf api {EndpointURL}

    EndpointURL you can find in your subaccount : APIEndPoint

  2. login to your BTP endpoint with your btp user and password

    command :

    cf login

  3. add manifest.yml for CF BTP development

    manifest

  4. configure the route and python buildpacks

    1. Before config the python buildpack , we need to add 3 files(runtime.text, requirement.txt procfile ) according to guide

      runtimetime.text: used to defined the python runtime version, we can find the right python runtime releaes via the pythonBuildPackage Relaese

      example code :

      3.8.10
      

      requirement.txt :used to give the python applicaiton denpendency

      example code :

      Flask==2.0.1
      

      procfile: define the python applicaiton start comand

      example code :

      web: python app.py
      
    2. confgure the routes here we suggest use bellow format as recomendation :

         {subdomain}-{appname}.{cfappdoman}
      

      subdomain:

      subdomain

      appname: defined by business

      cfappsdomain: user the command cf domains to get the domain url

      cfappdomain

      Example:

      ---
      applications:
      - name: pyApp
      memory: 128MB
      buildpacks: 
         - python_buildpack
      routes: 
         - route: 91ccc175trial-pythonapp.cfapps.ap21.hana.ondemand.com 
      
  5. Deploy your nodjs project to your BTP Subaccount

    command :

    cf push

Test(BTP subaccount)

  1. Navigte to your space

space

  1. Go you applcation

space_application

  1. Get applicaiton URL

applicationOverview

  1. Test it with the URL

    {applicaitonURL}/#/
    

    after you get the below response , your python applicaiton is runtime fine

    Hello this is the BTP python demo!
    

Refrence

Create and deploy python app: btp-pyton-deploy

Flask guide : flask Guide

About

Simply python applicaiotn , and make it runing on the SAP Business Technology Platform Cloud Foundry Enviroment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published