Dockerize backend, frontend, and database into separate containers
- backend/Dockerfile: multi-stage Python build (builder + slim runtime) - frontend/Dockerfile: multi-stage Node build + nginx:alpine serving - frontend/nginx.conf: SPA routing + /api/ reverse proxy to backend - docker-compose.yml: production compose with health checks and proper dependency ordering - docker-compose.dev.yml: dev overrides with hot reload via volume mounts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,35 +15,51 @@ A fullstack SaaS web application built with FastAPI, React, and PostgreSQL.
|
||||
- User registration and login (JWT auth)
|
||||
- Protected dashboard route
|
||||
- `/api/users/me` — authenticated user info
|
||||
- Vite dev server proxies `/api` to FastAPI — no CORS issues in development
|
||||
- 3 separate Docker containers: `db` (PostgreSQL), `backend` (FastAPI), `frontend` (nginx)
|
||||
|
||||
## Containers
|
||||
|
||||
| Container | Image | Port | Description |
|
||||
|---|---|---|---|
|
||||
| `db` | postgres:16-alpine | 5432 | PostgreSQL database |
|
||||
| `backend` | custom (python:3.12-slim) | 8000 | FastAPI management API |
|
||||
| `frontend` | custom (nginx:alpine) | 80 | React UI served by nginx |
|
||||
|
||||
The frontend nginx container proxies `/api/*` to the backend container internally — no CORS headers needed in production.
|
||||
|
||||
## Installation
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.11+
|
||||
- Node.js 18+
|
||||
- PostgreSQL 16 (or Docker)
|
||||
- Docker + Docker Compose
|
||||
|
||||
### Option A — Docker (recommended)
|
||||
### Production
|
||||
|
||||
```bash
|
||||
git clone <repo>
|
||||
cd destroying_sap
|
||||
cp .env.example backend/.env
|
||||
docker compose up --build
|
||||
cp .env.example backend/.env # edit SECRET_KEY at minimum
|
||||
docker compose up --build -d
|
||||
```
|
||||
|
||||
- Frontend: http://localhost:5173
|
||||
- Backend / API docs: http://localhost:8000/docs
|
||||
- Frontend: http://localhost
|
||||
- API docs: http://localhost:8000/docs
|
||||
|
||||
### Option B — Local
|
||||
### Development (hot reload)
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
|
||||
```
|
||||
|
||||
- Frontend (Vite): http://localhost:5173
|
||||
- Backend (uvicorn --reload): http://localhost:8000
|
||||
|
||||
### Local (no Docker)
|
||||
|
||||
**1. Start PostgreSQL**
|
||||
|
||||
```bash
|
||||
docker compose up db -d
|
||||
# or use a local PostgreSQL instance and update backend/.env
|
||||
```
|
||||
|
||||
**2. Backend**
|
||||
@@ -52,7 +68,7 @@ docker compose up db -d
|
||||
cd backend
|
||||
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
||||
pip install -e ".[dev]"
|
||||
cp ../.env.example .env # edit DATABASE_URL and SECRET_KEY as needed
|
||||
cp ../.env.example .env
|
||||
alembic upgrade head
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
@@ -60,9 +76,7 @@ uvicorn app.main:app --reload
|
||||
**3. Frontend**
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
npm run dev
|
||||
cd frontend && npm install && npm run dev
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Reference in New Issue
Block a user