Deployment
MailAfrica Agent can be deployed using Docker, systemd, or run directly on a VPS.
Docker (Recommended)
Build and Run
git clone https://github.com/cameltech/MailAfrica-Agent.git
cd MailAfrica-Agent
# Create .env with your credentials
cp .env.example .env
nano .env
# Build and start
docker compose up -d --buildDocker Compose Configuration
The docker-compose.yml defines a single service:
services:
agent:
build: .
ports:
- "8097:8000"
volumes:
- agent-data:/app/data
env_file:
- .env
restart: unless-stopped- Port 8097 maps to container port 8000
- Named volume
agent-datapersists the SQLite database - env_file loads your
.envcredentials
Dockerfile
Multi-stage build:
- Builder stage — Python 3.11-slim, installs uv, copies dependency files, installs deps
- Runtime stage — Python 3.11-slim, copies installed deps and source code
This keeps the final image small and secure.
Managing the Container
# View logs
docker compose logs -f agent
# Restart
docker compose restart agent
# Stop
docker compose down
# Rebuild after code changes
docker compose up -d --buildsystemd
For non-Docker deployments, use the provided systemd unit file.
Install
# Create service user
sudo useradd -r -s /bin/false mailafrica
# Clone the repo
sudo -u mailafrica git clone https://github.com/cameltech/MailAfrica-Agent.git /opt/mailafrica-agent
# Install dependencies
cd /opt/mailafrica-agent
sudo -u mailafrica uv sync
# Copy and edit environment
sudo -u mailafrica cp .env.example .env
sudo -u mailafrica nano .env
# Install systemd unit
sudo cp deploy/mailafrica-agent-webhook.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now mailafrica-agent-webhookUnit File
The systemd unit (deploy/mailafrica-agent-webhook.service) includes:
- Runs as
mailafricauser - Loads
.envviaEnvironmentFile - Restarts on failure with 5s delay
- Hardened with
NoNewPrivileges,ProtectSystem=full
Managing the Service
# Status
sudo systemctl status mailafrica-agent-webhook
# Restart
sudo systemctl restart mailafrica-agent-webhook
# View logs
sudo journalctl -u mailafrica-agent-webhook -fGitHub Actions CI/CD
The repo includes a GitHub Actions workflow (.github/workflows/deploy.yml) that:
- Triggers on push to
main - SSHes to the VPS using a deploy key
- Runs
deploy.shwhich:- Does
git pull --ff-only - Rebuilds Docker Compose (or restarts systemd)
- Does
Setup
- Add a repository secret
VPS_SSH_KEYwith your private SSH key - Add a repository secret
VPS_HOSTwith your server address - The workflow handles the rest on every push to
main
VPS Provisioning
For a fresh Ubuntu VPS, run the provisioning script:
bash deploy/setup_vps.shThis installs Docker, creates the mailafrica user, clones the repo, and sets up the service.
Production Checklist
- Set strong, unique values for all API keys
- Use HTTPS (reverse proxy with nginx/caddy)
- Configure firewall to only allow ports 80/443
- Set up log rotation
- Monitor disk space (SQLite database grows with conversations)
- Back up
agent.dbregularly - Set
AGENT_WEBHOOK_SECRETto a secure random string
Reverse Proxy (nginx)
server {
listen 443 ssl http2;
server_name agent.mailafrica.online;
ssl_certificate /etc/letsencrypt/live/agent.mailafrica.online/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/agent.mailafrica.online/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8097;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Health Check
Verify the deployment is working:
curl https://agent.mailafrica.online/health
# {"status": "ok"}Or use the MCP check command:
uv run mailafrica-agent check