88 lines
2.3 KiB
Markdown
88 lines
2.3 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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>`
|