Files
full-stack-fastapi/deployment.md
魏风 cdd15ffe3a
All checks were successful
Deploy to Production / deploy (push) Successful in 38s
chore: remove traefik/copier setup and simplify compose workflow
2026-03-25 11:01:59 +08:00

2.3 KiB

FastAPI Project - Deployment

You can deploy this project with Docker Compose and put it behind an external reverse proxy (for example OpenResty/Nginx).

This repository uses an external reverse proxy setup and keeps Compose deployment focused on app services.

Preparation

  • Have a remote server ready.
  • Configure DNS records to point your domain to that server.
  • Install Docker Engine on the server.
  • Configure OpenResty (or your reverse proxy) to forward traffic:
    • frontend domain/path -> frontend container port
    • API domain/path -> backend container port

Environment Variables

Create .env.production based on .env.production.example and fill in real values.

Minimum required values:

  • DOMAIN
  • FRONTEND_HOST
  • ENVIRONMENT=production
  • SECRET_KEY
  • FIRST_SUPERUSER
  • FIRST_SUPERUSER_PASSWORD
  • POSTGRES_SERVER
  • POSTGRES_PORT
  • POSTGRES_DB
  • POSTGRES_USER
  • POSTGRES_PASSWORD

Optional values:

  • SMTP_* and EMAILS_FROM_EMAIL
  • SENTRY_DSN
  • MQTT_* pipeline settings
  • DOCKER_IMAGE_BACKEND
  • DOCKER_IMAGE_FRONTEND

Deploy with Docker Compose

cd /path/to/project

docker compose --env-file .env.production -f compose.prod.yml build

docker compose --env-file .env.production -f compose.prod.yml up -d

To update after code changes:

docker compose --env-file .env.production -f compose.prod.yml down --remove-orphans
docker compose --env-file .env.production -f compose.prod.yml up -d --build

Verify

docker compose --env-file .env.production -f compose.prod.yml ps
docker compose --env-file .env.production -f compose.prod.yml logs backend --tail 100
docker compose --env-file .env.production -f compose.prod.yml logs frontend --tail 100

Backend health check endpoint:

  • http://<backend-host>:18000/api/v1/utils/health-check/ (or your internal mapped port)

CI/CD

The Gitea workflow at .gitea/workflows/deploy.yml deploys using:

docker compose --env-file .env.production -f compose.prod.yml ...

So production deploys are isolated from local development overrides.

URLs

Replace with your real domains configured in OpenResty:

  • Frontend: https://<your-frontend-domain>
  • Backend API docs: https://<your-api-domain>/docs
  • Backend API base URL: https://<your-api-domain>