A Django-based deployment orchestration system that replaces Docker containers with Python virtual environments, designed to run multiple Python applications on a single server efficiently.
Install PyDeployer on a fresh Ubuntu LTS server with a single command:
curl -fsSL https://raw.githubusercontent.com/unomena/pydeployer/main/install.sh | sudo bashThis will:
- Install all system dependencies (PostgreSQL, Nginx, Supervisor, Redis)
- Create deployment user and directory structure
- Configure database and services
- Deploy PyDeployer itself
- Create admin user (admin/admin123)
- Start all services
After installation, access PyDeployer at: http://YOUR_SERVER_IP/
If you prefer to clone and install manually:
# Clone the repository
git clone https://github.com/unomena/pydeployer.git
cd pydeployer
# One command to rule them all
make quickstart
# Create your admin user
make create-superuser
# Start PyDeployer
make start
# Register your first project
make register-project NAME=my-app [email protected]:my-org/my-app.git PORT=8100
# Deploy it!
make deploy PROJECT=my-app ENV=prod
# Access admin at http://localhost:8000/adminThat's it! You're deployed! π
- Self-Managing: PyDeployer can deploy and manage itself
- Multi-Environment Support: QA, Staging, and Production environments
- Zero-Downtime Deployments: Graceful service reloads with rollback capability
- GitLab Integration: Webhook support for automated deployments
- REST API: Full API for deployment automation
- Django Admin: Web interface for monitoring and management
- Health Checks: Automatic service health monitoring
- Resource Management: CPU and memory limits per service
- Supervisor Integration: Process management and auto-restart
- Nginx Integration: Automatic reverse proxy configuration
PyDeployer manages deployments by:
- Creating isolated Python virtual environments for each project/environment
- Using Supervisor to manage processes
- Configuring Nginx as a reverse proxy
- Tracking deployments in PostgreSQL
- Providing REST API and Django Admin interfaces
The Makefile provides automated installation commands that handle all setup steps. You can use make quickstart for a complete automated setup, or follow the manual steps below.
- Ubuntu LTS (20.04 or 22.04 recommended)
- sudo access
- Git
- 16GB RAM, 4 CPUs (recommended for production)
The easiest way to install PyDeployer is using the included Makefile:
# Complete automated setup
make quickstart
# This will:
# 1. Install all system dependencies (Python 3.11, Nginx, Supervisor, Redis)
# 2. Install and configure PostgreSQL
# 3. Create deployment user and directory structure in /srv/deployments
# 4. Install PyDeployer
# 5. Initialize the database
# 6. Register PyDeployer for self-management- Install system dependencies:
sudo apt-get update
sudo apt-get install -y python3.11 python3.11-venv python3-pip git nginx supervisor postgresql-client redis-server- Create deployment user:
sudo useradd -m -s /bin/bash deploy
sudo mkdir -p /opt/deployments/{apps,repos,nginx/sites,supervisor/conf.d}
sudo chown -R deploy:deploy /opt/deployments- Setup PostgreSQL database:
CREATE DATABASE pydeployer;
CREATE USER deployer WITH PASSWORD 'your-password';
GRANT ALL PRIVILEGES ON DATABASE pydeployer TO deployer;- Clone and setup PyDeployer:
sudo su - deploy
cd /opt/deployments/apps
git clone https://gitlab.com/unomena/pydeployer.git pydeployer/releases/initial
cd pydeployer
python3.11 -m venv envs/prod
source envs/prod/bin/activate
pip install -r releases/initial/requirements.txt- Configure environment:
cd releases/initial
cp .env.example .env
# Edit .env with your configuration
nano .env- Initialize database:
export DATABASE_URL="postgresql://deployer:password@localhost/pydeployer"
cd src
python manage.py migrate
python manage.py createsuperuser
python manage.py collectstatic --noinput- Register PyDeployer for self-management:
python manage.py register_self- Start PyDeployer:
gunicorn --bind 127.0.0.1:8000 --workers=2 --threads=4 pydeployer.wsgiDeploy a project:
cd /opt/deployments/apps/pydeployer/releases/current/src
python manage.py deploy <project_name> --env=<environment>
python manage.py deploy uno-admin --env=prodRollback deployment:
cd /opt/deployments/apps/pydeployer/releases/current/src
python manage.py rollback <project_name> --env=<environment>
python manage.py rollback uno-admin --env=prodRegister new project:
cd /opt/deployments/apps/pydeployer/releases/current/src
python manage.py register_project <name> --repo=<git_url> --port-start=<port>
python manage.py register_project my-app [email protected]:company/my-app.git --port-start=8100The Makefile provides convenient commands for all PyDeployer operations. All commands can be viewed with make help.
| Command | Description |
|---|---|
make quickstart |
Complete automated setup from scratch |
make install-postgres |
Install PostgreSQL (latest stable) |
make setup-database |
Create PyDeployer database and user |
make install-system-deps |
Install all system dependencies |
make create-deployment-user |
Create deploy user and /srv/deployments structure |
make install-pydeployer |
Install PyDeployer to /srv/deployments |
make configure-pydeployer |
Configure environment variables |
make init-database |
Initialize database with migrations |
make create-superuser |
Create Django admin user |
make register-self |
Register PyDeployer to manage itself |
| Command | Description | Example |
|---|---|---|
make deploy |
Deploy a project | make deploy PROJECT=my-app ENV=prod |
make rollback |
Rollback deployment | make rollback PROJECT=my-app ENV=prod |
make register-project |
Register new project | make register-project NAME=my-app REPO=git@... PORT=8100 |
make list-projects |
List all registered projects | make list-projects |
make list-deployments |
Show recent deployments | make list-deployments |
| Command | Description |
|---|---|
make start |
Start PyDeployer service |
make stop |
Stop PyDeployer service |
make restart |
Restart PyDeployer service |
make status |
Check all services status |
make logs |
View PyDeployer logs (tail -f) |
| Command | Description |
|---|---|
make shell |
Open Django shell |
make dbshell |
Open PostgreSQL shell |
make migrate |
Apply database migrations |
make makemigrations |
Create new migrations |
make test |
Run test suite |
make collectstatic |
Collect static files |
make clean |
Clean temporary files |
First Time Setup:
make quickstart
make create-superuser
make startRegister and Deploy a Project:
# Register the project
make register-project NAME=uno-admin [email protected]:unomena/uno-admin.git PORT=8100
# Deploy to QA
make deploy PROJECT=uno-admin ENV=qa
# Deploy to Production
make deploy PROJECT=uno-admin ENV=prod
# If something goes wrong, rollback
make rollback PROJECT=uno-admin ENV=prodDaily Operations:
# Check status
make status
# View recent deployments
make list-deployments
# Watch logs
make logs
# Restart if needed
make restartGet authentication token:
curl -X POST http://localhost:8000/api/auth/token/ \
-d "username=admin&password=password"Deploy via API:
curl -X POST http://localhost:8000/api/deploy/ \
-H "Authorization: Token <your-token>" \
-H "Content-Type: application/json" \
-d '{
"project": "uno-admin",
"environment": "prod",
"commit_sha": "abc123"
}'Check status:
curl http://localhost:8000/api/status/ \
-H "Authorization: Token <your-token>"Each project needs deployment configuration files:
deploy-prod.yaml:
name: my-app
environment: production
python_version: "3.11"
requirements: requirements.txt
services:
- name: web
type: django
command: gunicorn --bind 127.0.0.1:${PORT} --workers=2 project.wsgi
enabled: true
health_check:
endpoint: /health/
interval: 30
resources:
max_memory: 2048
max_cpu: 1.0
- name: worker
type: celery
command: celery -A project worker --concurrency=2 -Q ${QUEUE_NAME}
enabled: true
env_vars:
DJANGO_SETTINGS_MODULE: project.settings_production
DATABASE_URL: ${SECRET_DATABASE_URL}
REDIS_URL: ${SECRET_REDIS_URL}
hooks:
pre_deploy:
- python manage.py migrate --noinput
- python manage.py collectstatic --noinput
post_deploy:
- python manage.py check --deployAdd to your .gitlab-ci.yml:
deploy:
stage: deploy
script:
- |
curl -X POST https://deploy.company.com/webhook/gitlab/ \
-H "X-Gitlab-Token: $WEBHOOK_TOKEN" \
-H "Content-Type: application/json" \
-d "$CI_WEBHOOK_PAYLOAD"
only:
- mainAccess the Django admin at http://localhost:8000/admin/ to:
- View and manage projects
- Monitor deployments
- Check service health
- View logs
- Manage environments and secrets
The Makefile sets up the following directory structure in /srv/deployments (note: changed from /opt/deployments for better compliance with Linux FHS):
/srv/deployments/
βββ apps/ # Application deployments
β βββ pydeployer/
β β βββ envs/ # Virtual environments
β β β βββ prod/
β β βββ releases/ # Versioned releases
β β β βββ 20240102-1234/
β β β βββ current -> 20240102-1234/
β β βββ logs/
β βββ my-app/
β βββ envs/
β βββ releases/
β βββ logs/
βββ repos/ # Git repository cache
βββ nginx/
β βββ sites/ # Nginx configurations
βββ supervisor/
βββ conf.d/ # Supervisor configurations
- All secrets are encrypted in the database
- Services run as non-privileged user
- Applications bind to localhost only
- Nginx handles SSL termination
- Webhook tokens for authentication
- Token-based API authentication
PyDeployer provides:
- Health check endpoints for each service
- Deployment history and logs
- Service status monitoring
- Resource usage tracking
- Automatic restart on failure
Check all services:
make statusView logs:
make logsIf PostgreSQL installation fails:
# Check Ubuntu version
lsb_release -a
# Manually run the install script
bash scripts/install_postgres.sh
# Or install PostgreSQL manually
sudo apt-get install postgresql postgresql-contribIf deployment fails:
# Check project registration
make list-projects
# Check recent deployments
make list-deployments
# View detailed logs
make logs
# Try manual deployment
make shell
# Then in shell:
from deployer.executor import DeploymentExecutor
executor = DeploymentExecutor()
executor.deploy('project-name', 'qa')Permission issues:
# Ensure deploy user owns directories
sudo chown -R deploy:deploy /srv/deployments
# Check deploy user exists
id deployCheck service status:
supervisorctl statusView deployment logs:
tail -f /srv/deployments/apps/<project>/logs/<environment>/*.logManual rollback:
cd /srv/deployments/apps/<project>/releases/<environment>
rm current
ln -s <previous-version> current
supervisorctl restart <project>-<environment>-*- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
[Your License]
For issues and questions, please contact the development team or create an issue in the repository.