CodeTutor Deployment
Production deployment configuration using Docker Compose and Cloudflare Tunnel.
Architecture
Internet -> Cloudflare Tunnel -> nginx -> frontend (Next.js)
\-> backend (FastAPI)
\-> PostgreSQL
Prerequisites
- Docker and Docker Compose
- Cloudflare account with Zero Trust access
- External Docker network:
public-network
Create the external network if it doesn't exist:
docker network create public-network
Setup
1. Configure Environment
cp .env.example .env
Edit .env with:
POSTGRES_PASSWORD: Strong password for the databaseCLOUDFLARE_TUNNEL_TOKEN: Token from Cloudflare Zero Trust dashboard
2. Create Cloudflare Tunnel
- Go to Cloudflare Zero Trust Dashboard
- Navigate to Networks > Tunnels
- Create a new tunnel named
codetutor-demo - Add public hostname:
- Subdomain:
codetutor-demo - Domain:
kschappell.com - Service:
http://nginx:80
- Subdomain:
- Copy the tunnel token to your
.envfile
3. Deploy
docker compose up -d --build
4. Verify
- Check service health:
docker compose ps - View logs:
docker compose logs -f - Test endpoint:
curl https://codetutor-demo.kschappell.com/health
Database Management
Initial Setup
The database is automatically created on first run. To seed with initial data:
docker compose exec backend python -m alembic upgrade head
docker compose exec backend python -m scripts.seed_db
Backups
docker compose exec db pg_dump -U codetutor codetutor > backup.sql
Restore
docker compose exec -T db psql -U codetutor codetutor < backup.sql
Updating
git pull
docker compose up -d --build
Troubleshooting
Services not starting
Check logs for specific service:
docker compose logs backend
docker compose logs frontend
docker compose logs nginx
Database connection issues
Ensure the database is healthy:
docker compose ps db
docker compose logs db
Tunnel not connecting
Verify the tunnel token is correct and the tunnel is active in the Cloudflare dashboard.