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 orAPP_ENV=prod
for production environment
- Development:
Environment=APP_ENV=dev
- Production:
Environment=APP_ENV=prod
Role Setup and Permissions
1. Team Structure
-
Leader (Tom): Admin + Space Owner + Project Owner
- Username: tom
- Email: [email protected]
-
Developer A (Jerry): Project Master
- Username: jerry
- Email: [email protected]
-
Developer B (Bob): Developer
- Username: bob
- Email: [email protected]
2. Initial Setup Process (by Tom)
2.1 Create Users
- Navigate to
Base/Users
- 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
2.2 Create Space
- Navigate to
Global/Spaces
- 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.
2.3 Import Space Members
Import members from the global user pool to ensure team members have access and can collaborate.
- Locate the space you just added.
- In the corresponding Actions menu, find and click the Members button.
- Click on Import Members to proceed with the import.
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.
- Locate the user named Tom.
- In the corresponding Actions menu, click Edit.
- Change his permissions to Owner.
3. Create Server Infrastructure
3.1 Create Server Clusters
- Navigate to
Global/Server Clusters
- Create development cluster:
- Click "New"
- Fill in cluster details:
- Name: pro-example-python-server-cluster(dev)
- Select Environment: dev
- Select Status: Available
- Click "Create"
- Create production cluster:
- Click "New"
- Fill in cluster details:
- Name: pro-example-python-server-cluster(prod)
- Select Environment: prod
- Select Status: Available
- Click "Create"
3.2 Add Servers
-
Navigate to
Global/Servers
-
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"
- 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"
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
- Locate the left navigation and select
Space Resources
, then chooseServer Cluster
. - Switch to the space you created earlier,
python-example-space
. - 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.
4. Create Projects and Import Project Members
4.1 Development Project
- Download project template: celerbuild-example-python-dev.yaml
- Template source: celerbuild-example-python dev template (opens in a new tab)
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
- Navigate to
Projects/Projects
- Click "Import YAML"
- Upload the downloaded template
- 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)
- Click "Create Project"
Import Project Members
- In the newly created project, find
Members
under theActions
menu and click to import project members. - Click "Import Members" to add project members.
- 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
4.2 Production Project
Download Template
- Download project template: celerbuild-example-python-prod.yaml
- Template source: celerbuild-example-python prod template (opens in a new tab)
Import Template
The imported project name and server cluster need to be changed, and others need to be modified according to your own requirements
- Navigate to
Projects/Projects
- Click "Import YAML"
- Upload the downloaded template
- Configure production project:
- Project name: "pro-celerbuild-example-python-prod"
- Select cluster: "pro-example-python-server-cluster(prod)"
- Click "Create Project"
- Enable deployment approval requirement
Import Project Members
- In the newly created project, find
Members
under theActions
menu and click to import project members. - Click "Import Members" to add project members.
- 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
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)
- Create deployment application
- Execute deployment directly
- 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
- 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"
- Developer B (Bob) executes deployment:
Navigate to Operations/Tasks
- Find the deployment task
- Click "Deploy"
- Click "Start Deploy"
- Monitor deployment progress in Operation Logs
- 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
- 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
Note:
- Here we select v1.0.0 as an example
- The deployment process remains the same regardless of which tag version you select
- Developer A (Jerry) reviews and approves:
-
- After logging in, ensure the correct space is selected.
-
- Check the notification icon for new messages. You'll see a new ticket assigned to you; click "View Details".
-
- Click "Review", select "Approved", provide feedback, and finally click "Submit Review".
- Developer B (Bob) executes deployment:
-
- After logging in, ensure the correct space is selected.
-
- Check the notifications for new messages. You'll see your ticket has been reviewed and approved; click "View Details".
-
- In the ticket details, click the "Deploy" button.
-
- Navigate to the specific task page, click "Start Deployment" to begin the deployment.
-
- Monitor the logs and server status. If any issues arise, a prompt will provide guidance.
- 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.
- 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
- Developer A (Jerry) reviews and approves
- Developer B (Bob) executes deployment
- 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.
- 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
-
Developer A (Jerry) reviews and approves
-
Developer B (Bob) executes deployment
-
Verify upgrade:
curl http://server:8084/version
{"version":"1.0.1"}
3. Rollback to v1.0.0
- 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
- 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"
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
- 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
- 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! 🎉