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:
Part 1:
Part 2: Part 3:This blog post is Part 1.
More details can be found here:
- CF Command Line Interface installed locally.
- python3 (version 3.5 or higher) and pip (or pip3) installed locally. See the installation guides for OS X, Windows, and Linux.
- nodejs and npm installed locally.
Open Cloud Platform Cockpit, navigate to your subaccount, find the corresponding API Endpoint
:
cf login -a <api-endpoint>
Enter your Email
and Password
which are consistent with your Cockpit’s.
org
and space
Check your target by executing CF command:
2. Create a Python Project
Create a 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>.
For example:
---
applications:
- name: myapp
host: myapp-ixxxxxx
path: .
domain: apps.sap-samples.scpcloud.top
memory: 128M
command: python server.py
runtime.txt
python-3.7.x
requirements.txt
Flask==1.1.0
server.py
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 python-with-xsuaa
directory:
cf push
manifest.yml
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:
cf apps
Conclusion
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.
Part 2:
Part 3:If you would like to get more step-by-step hands-ons on SAP Cloud Platform Alibaba Cloud, please follow me!