[SAP Cloud Platform on Alibaba Cloud series] Develop Python App with Authentication and Authorization in Cloud Foundry – Part 1
With the landing of SAP Cloud Platform on Alibaba Cloud, more and more stakeholders have need to get onboard or have a try on it. Thus, the main purpose of writing this series of blog posts is to emphasize the minor but important differences when developing on Alibaba Cloud, so that readers can consume it more smoothly.
This topic Develop Python App with Authentication and Authorization in Cloud Foundry will guide you through creating a Python application, setting up authentication checks and authorization checks in Cloud Foundry (for ease of reading “CF).
Since this is a large topic, in order to give you a better reading experience, I would like to divide it into 3 parts:
This blog post is Part 1.
More details can be found here:
- python3 (version 3.5 or higher) and pip (or pip3) installed locally. See the installation guides for
- nodejs and npm installed locally.
- installed locally
Step 1: Create and Deploy a Python Application
1. Log on to Cloud Foundry
Open Cloud Platform Cockpit, navigate to your subaccount, find the corresponding
cf login -a <api-endpoint>
Password which are consistent with your Cockpit’s.
Check your target by executing CF command:
2. Create a Python Project
manifest.yml file under the
python-with-xsuaa directory with the following content:
--- applications: - name: myapp host: <host> path: . domain: <custom-domain> memory: 128M command: python server.py
Replace <host> with a unique name, so it does not clash with all other deployed applications. Replace <custom-domain> with the domain available in your org, you can check it by executing CF command `cf domains`. The URL of your application will be: <host.custom-domain>.
--- applications: - name: myapp host: myapp-ixxxxxx path: . domain: apps.sap-samples.scpcloud.top memory: 128M command: python server.py
Specify the Python runtime version your application by creating a
runtime.txt file, for example:
Buildpack only supports the stable Python versions, which are listed in the
The application will be a web server utilizing the Flask web framework. Specify Flask as an application dependency by creating a
requirements.txt file with the following content:
Available Flask versions:
server.py file, which will contain the following application logic:
import os from flask import Flask app = Flask(__name__) port = int(os.environ.get('PORT', 3000)) @app.route('/') def hello(): return "Hello World" if __name__ == '__main__': app.run(host='0.0.0.0', port=port)
This is a simple server, which will return a “Hello World” when requested.
3. Vendor dependencies
In case you will get problem of network in China when downloading dependencies during the process of deploying, you’d better deploy applications as self-contained, which means carry all of their dependencies so that the staging process does not require any network calls.
The Python buildpack provides a mechanism for that – applications can vendor their dependencies by creating a vendor folder in their root directory and execute the following command to download dependencies in it:
pip download -d vendor -r requirements.txt --platform manylinux1_x86_64 --only-binary=:all:
4. Deploy the application onto Cloud Foundry
Execute the following CF command in the root of
cf push is always executed in the same directory, where the
manifest.yml is located.
If your app deployment fails, you can troubleshoot by checking its logs:
cf logs myapp --recent
5. Access the application
When the staging and deployment steps are complete, you can check the state and URL of your application through Cockpit or CF command:
Open a Firefox Developer Edition browser window and enter the URL of the application, you should see the message
This blog post shared how to create and deploy Python app onto SAP Cloud Platform Alibaba Cloud.
Special point for Alibaba Cloud:
The most important point varies from Alibaba Cloud to Public Cloud is application domain. On the SAP Public Cloud, like AWS, Azure, etc, they will provide a public shared domain to developers. However, this kind of shared domain is not supported due to compliance in China, so in order to deploy apps onto Alibaba Cloud, developers should create a custom domain by themselves. More details on how to get your own custom domain can be found here: Use custom domain in SAP Cloud Platform on Alibaba Cloud
The next two parts will be published later, it will not take a long time, let’s stay tuned.
If you would like to get more step-by-step hands-ons on SAP Cloud Platform Alibaba Cloud, please follow me!