Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
kayur_goyal
Product and Topic Expert
Product and Topic Expert
1,738

Prerequisites

Before you start, make sure you have the following: - A Cloud Foundry account - Cloud Foundry Command Line Interface (CLI) installed - Python installed on your local machine - Node.js and npm installed for building your MTA archive.

Step 1: Set Up Your Project Directory

Create a new directory for your project.

 

mkdir python-cf-mta-project cd python-cf-mta-project

 

Step 2: Initialize a new Python project

 

python -m venv venv

source venv/bin/activate # On Windows, use `venv\Scripts\activate`

pip install Flask

 

Step 3: Create a simple Python application

Create a file named `app.py` with the following content:

 

from flask import Flask

import os

from cfenv import AppEnv

app = Flask(__name__)

cf_port = os.getenv("PORT")

env = AppEnv()

@app.route('/')

def home():

return "Hello, Cloud Foundry!"

if cf_port is None:

    app.run(host='0.0.0.0', port=8000, debug=False)

else:

    app.run(host='0.0.0.0', port=int(cf_port), debug=False)This starts a web server at port 8080.

 

Step 4: Create the requirement.txt file

flask

cfenv==0.5.3

Step 5: Create the mta.yaml file as below 

 

ID: python-cf-mta 
_schema-version: 3.3.0 
version: 1.1.0 
description: "Python web service with MTA" 
modules: 
  - name: python-web-cf-mta 
    type: python 
    path: ./ 
    provides: 
      - name: srv-api 
        properties: srv-url: ${default-url} 
    parameters: 
        memory: 1024M 
        disk-quota: 1024M 
        buildpacks: - python_buildpack 
        commands: - python app.py

 

 

Step 6: Setup MTA Archive build tool

 

npm install -g mbt

 

Step 7: Build your MTA archive

 

mbt build

 

This command will generate a file named `python-cf-mta-project_0.0.1.mtar` in your project directory.

Step 8: Deploy to Cloud Foundry

Log in to your Cloud Foundry account.

cf login -a your_cf_api_url -u your_username -p your_password

Deploy your MTA archive.

cf deploy python-cf-mta-project_0.0.1.mtar

Step 9: Verify the deployment

Check the status of your application.cf appsVisit the URL provided by Cloud Foundry to ensure your application is running. 

Finish, you have created a python cloud foundry project with MTA.yaml instead of using manifest.yml. 

In this blog, we have walked through the process of creating a Python Cloud Foundry project with an `mta.yaml` file containing the build instructions. This process includes setting up your project directory, creating the necessary `mta.yaml` files, building the MTA archive, and deploying it to Cloud Foundry.

 

 

 

 

SAP BTP, Cloud Foundry runtime and environment