Deploying Python Projects with CelerBuild Pro Using the FastAPI Framework Example

This guide demonstrates how to deploy a Python project using CelerBuild Pro Version, covering branch deployment, tag deployment, and tag version rollback operations with multiple roles. We'll use the celerbuild-example-python (opens in a new tab) project built with the FastAPI framework.

Note

  • This tutorial uses the Pro Version. For Standard Version features, please refer to the Standard Version Guide
  • Python 3.8+ is required for FastAPI compatibility

Prerequisites

Important Note:

  • For this tutorial, Python 3.8 or higher installation is required on the target server
  • Local Python installation is recommended depending on your build strategy:
    • If building locally and uploading to remote server: both local and remote installation needed
    • If building only on remote server: only remote installation needed
  • The System Service Setup must be configured on the target deployment server

1. System Prerequisites

Complete all Prerequisites setup steps.

2. Python Environment Setup

Installing Python and pip

macOS
# Using Homebrew
brew install [email protected]  # or any version 3.8+
 
# Add to ~/.zshrc
echo 'export PATH="/usr/local/opt/python/bin:$PATH"' >> ~/.zshrc
 
# Verify installation
python3 --version  # Should show 3.8 or higher
pip3 --version
Ubuntu/Debian
# Update package list
sudo apt update
 
# Install Python and pip (3.8 or higher)
sudo apt install python3 python3-pip python3-venv
 
# Verify installation
python3 --version  # Should show 3.8 or higher
pip3 --version
CentOS/RHEL
# Enable EPEL repository (required for Python 3.8+)
sudo yum install epel-release
 
# Install Python and pip
sudo yum install python3 python3-pip python3-devel
 
# If you need a specific version, you can use:
# sudo yum install python38 python38-pip python38-devel
 
# Verify installation
python3 --version  # Should show 3.8 or higher
pip3 --version

3. System Service Setup

On the target deployment server, create a systemd service file for managing the FastAPI application. This step is required for proper application management and auto-restart capabilities.

Important: This setup must be performed on each target deployment server.

sudo vim /etc/systemd/system/celerbuild-example-python.service

Add the following content:

[Unit]
Description=CelerBuild Example Python Application
After=network.target
 
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/celerbuild-example-python
# Set environment: use 'dev' for development, 'prod' for production
Environment=APP_ENV=dev
# Use the full path to gunicorn executable
# Find path using: which gunicorn (after adding ~/.local/bin to PATH)
ExecStart=/home/ubuntu/.local/bin/gunicorn app.main:app -c gunicorn/gunicorn.${APP_ENV}.py
# Exit code 143 indicates graceful termination
SuccessExitStatus=143
# Maximum time to wait for the service to stop
TimeoutStopSec=10
# Restart policy
Restart=on-failure
# Time to wait before restart attempts
RestartSec=5
 
[Install]
WantedBy=multi-user.target

Configuration Notes:

  • User: Change ubuntu to your actual service user
  • WorkingDirectory: Adjust /home/ubuntu/... to match your user's home directory
  • ExecStart: The path to gunicorn may vary based on your installation method
    • Find the correct path using: export PATH=$PATH:/home/ubuntu/.local/bin && which gunicorn
    • Common paths: /home/ubuntu/.local/bin/gunicorn or /usr/local/bin/gunicorn
  • Environment: Set APP_ENV=dev for development environment or APP_ENV=prod for production environment
    • Development: Environment=APP_ENV=dev
    • Production: Environment=APP_ENV=prod

Role Setup and Permissions

1. Team Structure

2. Initial Setup Process (by Tom)

2.1 Create Users

  1. Navigate to Base/Users
  2. Create team members' accounts:
Create Jerry's account:
- Username: jerry
- Email: [email protected]

Create Bob's account:
- Username: bob
- Email: [email protected]

Note:

  • By default, there is an admin user
  • You can promote yourself (Tom) to admin and then delete the default admin user
  • At least one admin user must exist in the system at all times

create-user-1

create-user-2

2.2 Create Space

  1. Navigate to Global/Spaces
  2. Create new space:
    • Name: python-example-space
    • Description (Optional): A dedicated space for Python language deployment examples, including FastAPI framework and other Python-based applications.

image

2.3 Import Space Members

Import members from the global user pool to ensure team members have access and can collaborate.

  1. Locate the space you just added.
  2. In the corresponding Actions menu, find and click the Members button.
  3. Click on Import Members to proceed with the import.

image

image

image

2.4 Set Space Owner

Designate a member as the space owner, responsible for managing resources and permissions within the space. In this example, set Tom as the Space Owner.

  1. Locate the user named Tom.
  2. In the corresponding Actions menu, click Edit.
  3. Change his permissions to Owner.

image

3. Create Server Infrastructure

3.1 Create Server Clusters

  1. Navigate to Global/Server Clusters
  2. Create development cluster:
  • Click "New"
  • Fill in cluster details:
    • Name: pro-example-python-server-cluster(dev)
    • Select Environment: dev
    • Select Status: Available
  • Click "Create"

image

  1. Create production cluster:
    • Click "New"
    • Fill in cluster details:
      • Name: pro-example-python-server-cluster(prod)
      • Select Environment: prod
      • Select Status: Available
    • Click "Create"

image

3.2 Add Servers

  1. Navigate to Global/Servers

  2. Add development server:

  • Click "New"
  • Fill in server details:
    • Select cluster: pro-example-python-server-cluster(dev)
    • Server Name: pro-python-dev-server-1
    • Server IP: Your server IP
    • SSH Port: Your SSH port (default: 22)
  • Click "Create"

image

  1. Add production server:
  • Click "New"
  • Fill in server details:
    • Select cluster: pro-example-python-server-cluster(prod)
    • Server Name: pro-python-prod-server-1
    • Server IP: Your server IP
    • SSH Port: Your SSH port (default: 22)
  • Click "Create"

image

Note:

  • Server names are prefixed with "pro-" to distinguish from standard version
  • Ensure SSH access is properly configured for each server
  • Multiple servers can be added to each cluster if needed

3.3 Import Space Server Clusters

  1. Locate the left navigation and select Space Resources, then choose Server Cluster.
  2. Switch to the space you created earlier, python-example-space.
  3. Click the "Import Server Clusters" button and select the existing server cluster from Global to import.

Once imported, the space server cluster can be used as a selectable server cluster list for projects within the current space.

image

image

4. Create Projects and Import Project Members

4.1 Development Project

image

Import Template

The imported project name, Space, and server cluster need to be changed, and others need to be modified according to your own requirements

  1. Navigate to Projects/Projects
  2. Click "Import YAML"
  3. Upload the downloaded template
  4. Configure development project:
    • Project name: "pro-celerbuild-example-python-dev"
    • Select cluster: "pro-example-python-server-cluster(dev)"
    • The development environment can choose not to enable deployment approval (It is off by default)
  5. Click "Create Project"

image

image

image

Import Project Members
  1. In the newly created project, find Members under the Actions menu and click to import project members.
  2. Click "Import Members" to add project members.
  3. After importing, assign specific roles to the members:
    • Set Tom as the Project Owner
    • Set Jerry as the Project Master
    • Set Bob as the Developer

image

image

image

image

image

4.2 Production Project

Download Template
Import Template

The imported project name and server cluster need to be changed, and others need to be modified according to your own requirements

  1. Navigate to Projects/Projects
  2. Click "Import YAML"
  3. Upload the downloaded template
  4. Configure production project:
    • Project name: "pro-celerbuild-example-python-prod"
    • Select cluster: "pro-example-python-server-cluster(prod)"
  5. Click "Create Project"
  6. Enable deployment approval requirement

image

image

image

Import Project Members
  1. In the newly created project, find Members under the Actions menu and click to import project members.
  2. Click "Import Members" to add project members.
  3. After importing, assign specific roles to the members:
    • Set Tom as the Project Owner
    • Set Jerry as the Project Master
    • Set Bob as the Developer

image

image

image

image

image

Note:

  • Development project allows direct deployment without approval
  • Production project requires approval from Project Owner (Tom) or Project Master (Jerry)
  • Make sure to review project settings before creation

Deployment Workflows

Development Environment

Note: Development environment deployments don't require approval

Developer Role (Developer A or B)

  1. Create deployment application
  2. Execute deployment directly
  3. Monitor deployment status

Production Environment

1. Regular Deployment

Developer Role (Developer A or B):

  • Create deployment application
  • Fill in deployment details
  • Submit for review
  • Execute approved deployment after review
  • Monitor deployment process

Project Owner/Master Role (Leader/Developer A):

  • Review deployment application
  • Approve/Reject with comments
  • Monitor deployment status

2. Rollback Deployment

Developer Role (Developer A or B):

  • Create rollback application
  • Select version to rollback
  • Submit for review
  • Execute approved rollback after review
  • Monitor rollback process

Project Owner/Master Role (Leader/Developer A):

  • Review rollback application
  • Approve/Reject with comments
  • Monitor rollback status

Note:

  • The developer who creates the deployment/rollback application is responsible for executing it after approval
  • Project Owner/Master can review and approve but typically don't execute the deployment/rollback
  • This workflow ensures that the developer who initiated the change is also responsible for its execution

Example Deployment Scenarios

Scenario 1: Development Branch Deployment

  1. Developer B (Bob) creates deployment for dev environment:

Navigate to Operations/Applications

  • Select the space python-example-space.
  • Select project "pro-celerbuild-example-python-dev"
  • Fill in:
    • Title: "Deploy version update to Dev"
    • Description: "Deploy version update to Dev.Branch: dev"
  • Select dev branch (click the branch sync icon, and select the latest version)
  • Click "Submit Application"

image

image

  1. Developer B (Bob) executes deployment:

Navigate to Operations/Tasks

  • Find the deployment task
  • Click "Deploy"
  • Click "Start Deploy"
  • Monitor deployment progress in Operation Logs

image

image

image

  1. Verify deployment:
# Check version endpoint
curl http://server:8084/version
{"version":"1.0.1"}
 
# Check main endpoint
curl http://server:8084/
{"message":"Hello World from CelerBuild!"}

Note:

  • Replace "server" with your actual server IP address
  • A response similar to {"version":"1.0.1"} indicates successful deployment
  • If you cannot access the endpoint, check:
    • Server firewall settings
    • Port 8084 accessibility
    • Application running status

Scenario 2: Production Tag Deployment

  1. Developer B (Bob) creates deployment for prod environment:

Navigate to Operations/Applications

  • Select project "pro-celerbuild-example-python-prod"
  • Fill in:
    • Title: "Deploy v1.0.0 to Production"
    • Description: "Deploy v1.0.0 to Production"
  • Submit for review

image

image

Note:

  • Here we select v1.0.0 as an example
  • The deployment process remains the same regardless of which tag version you select
  1. Developer A (Jerry) reviews and approves:
    1. After logging in, ensure the correct space is selected.
    1. Check the notification icon for new messages. You'll see a new ticket assigned to you; click "View Details".
    1. Click "Review", select "Approved", provide feedback, and finally click "Submit Review".

image

image

  1. Developer B (Bob) executes deployment:
    1. After logging in, ensure the correct space is selected.
    1. Check the notifications for new messages. You'll see your ticket has been reviewed and approved; click "View Details".
    1. In the ticket details, click the "Deploy" button.
    1. Navigate to the specific task page, click "Start Deployment" to begin the deployment.
    1. Monitor the logs and server status. If any issues arise, a prompt will provide guidance.

image

image

image

image

  1. Verify deployment:
# Check version endpoint
curl http://server:8084/version
{"version":"1.0.0"}
 
# Check main endpoint
curl http://server:8084/
{"message":"Hello World from CelerBuild!"}

Rollback Operations

Note:

  • Branch deployment rollback is not demonstrated here because the system only maintains the latest committed version
  • We'll demonstrate rollback using tag deployments instead
  • Rollback can only be performed to previously deployed tags in the system

Tag Deployment Rollback Example

1. Initial Deployment (v1.0.0)

For detailed deployment steps, refer to the Production Tag Deployment section above.

  1. Developer B (Bob) creates deployment:

Navigate to Operations/Applications

  • Select project "pro-celerbuild-example-python-prod"
  • Fill in:
    • Title: "Initial Deploy v1.0.0"
    • Description: "Initial production deployment:Version: v1.0.0"
  • Select tag "v1.0.0"
  • Submit for review
  1. Developer A (Jerry) reviews and approves
  2. Developer B (Bob) executes deployment
  3. Verify deployment:
curl http://server:8084/version
{"version":"1.0.0"}

2. Upgrade to v1.0.1

For detailed deployment steps, refer to the Production Tag Deployment section above.

  1. Developer B (Bob) creates deployment:

Navigate to Operations/Applications

  • Select project "pro-celerbuild-example-python-prod"
  • Fill in:
    • Title: "Upgrade to v1.0.1"
    • Description: "Production version upgrade: From v1.0.0 To v1.0.1"
  • Select tag "v1.0.1"
  • Submit for review
  1. Developer A (Jerry) reviews and approves

  2. Developer B (Bob) executes deployment

  3. Verify upgrade:

curl http://server:8084/version
{"version":"1.0.1"}

3. Rollback to v1.0.0

  1. Developer B (Bob) initiates rollback:

Navigate to Operations/Applications

  • Find project
  • Click Actions → "Apply Rollback"
  • Fill in:
    • Title: "Rollback from v1.0.1 to v1.0.0"
    • Description: "Rolling back production version"
  • Select rollback version v1.0.0
  • Submit for review

image

image

  1. Leader (Tom) reviews and approves:

Navigate to Operations/Applications

  • Review rollback request
  • Select Review Status "Approved"
  • Add approval comments: "Rollback to v1.0.0 approved."
  • Click "Submit Review"

image

image

Note:

  • Both Project Owner (Tom) and Project Master (Jerry) have permission to review rollback requests
  • In this example, we demonstrate Tom reviewing the rollback for clarity of role responsibilities
  • In practice, Jerry could also review and approve this rollback request
  1. Developer B (Bob) executes rollback:
  • Check the notifications for new messages. You'll see your ticket has been reviewed and approved; click "View Details".
  • Click "Rollback"
  • Click "Start Rollback"
  • Monitor rollback progress

image

image

image

image

  1. Verify rollback:
curl http://server:8084/version
{"version":"1.0.0"}

For detailed rollback instructions, see:

Congratulations! You have successfully learned how to deploy FastAPI Framework using CelerBuild Pro Edition, including team-based deployment workflows, approval processes, and version management! 🎉