Files
codetutor/deploy
Kai Chappell 238a8d6258
Some checks failed
CI / Backend (push) Successful in 15s
CI / Frontend (push) Successful in 49s
CI / Docker Build (push) Failing after 4m13s
use central cloudflared tunnel
2025-09-14 20:33:15 +01:00
..
2025-09-12 14:57:04 +01:00
2025-09-12 14:57:04 +01:00
2025-09-12 14:57:04 +01:00

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 database
  • CLOUDFLARE_TUNNEL_TOKEN: Token from Cloudflare Zero Trust dashboard

2. Create Cloudflare Tunnel

  1. Go to Cloudflare Zero Trust Dashboard
  2. Navigate to Networks > Tunnels
  3. Create a new tunnel named codetutor-demo
  4. Add public hostname:
    • Subdomain: codetutor-demo
    • Domain: kschappell.com
    • Service: http://nginx:80
  5. Copy the tunnel token to your .env file

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.