banatie-service/prod-env/README.md

192 lines
4.1 KiB
Markdown

# Production Environment
This directory contains the production Docker Compose configuration for running all Banatie services in containers.
## Services
- **API Service** (port 3000) - REST API for image generation
- **Landing Page** (port 3001) - Public website
- **PostgreSQL** (port 5460→5432) - Database
- **MinIO** (ports 9000-9001) - Object storage with S3 compatibility
## Quick Start
### 1. Setup Secrets
```bash
cp secrets.env.example secrets.env
# Edit secrets.env with real values
```
Required secrets:
- `GEMINI_API_KEY` - Your Google Gemini API key
### 2. Start Services
```bash
# From prod-env directory
docker compose up -d
```
### 3. Check Status
```bash
docker compose ps
docker compose logs -f app # API logs
docker compose logs -f landing # Landing logs
```
### 4. Stop Services
```bash
docker compose down
```
## Deployment to VPS
### Initial Setup
```bash
# On VPS
cd /path/to/banatie-service
git pull
cd prod-env
cp secrets.env.example secrets.env
# Edit secrets.env with production values
docker compose up -d --build
```
### Updates
```bash
# On VPS
cd /path/to/banatie-service/prod-env
git pull
docker compose up -d --build
```
## Environment Variables
Configuration is split into two files:
- **`.env`** - Base configuration (committed to git)
- Service endpoints (Docker internal: `postgres:5432`, `minio:9000`)
- Database credentials (development values)
- Storage configuration
- Application settings
- **`secrets.env`** - Sensitive secrets (NOT committed)
- API keys (Gemini)
- Production passwords (if different)
- Testing keys (optional)
## Port Mappings
| Service | Host Port | Container Port | Description |
|------------|-----------|----------------|-----------------------|
| API | 3000 | 3000 | REST API |
| Landing | 3001 | 3000 | Landing page |
| PostgreSQL | 5460 | 5432 | Database |
| MinIO API | 9000 | 9000 | S3-compatible storage |
| MinIO UI | 9001 | 9001 | Web console |
## Data Persistence
All data is stored in the parent `data/` directory:
```
../data/
├── postgres/ # Database files
├── storage/ # MinIO storage (4 drives for SNMD)
├── results/ # Generated images
└── uploads/ # Uploaded files
```
## Accessing Services
- **API**: http://localhost:3000
- **Landing**: http://localhost:3001
- **MinIO Console**: http://localhost:9001
- Username: `banatie_admin`
- Password: (from MINIO_ROOT_PASSWORD in .env)
## Database Access
Connect to PostgreSQL from host:
```bash
psql -h localhost -p 5460 -U banatie_user -d banatie_db
```
From another Docker container (same network):
```bash
psql -h postgres -p 5432 -U banatie_user -d banatie_db
```
## Troubleshooting
### Check service health
```bash
docker compose ps
```
### View logs
```bash
docker compose logs -f # All services
docker compose logs -f app # API only
docker compose logs -f postgres # Database only
```
### Restart specific service
```bash
docker compose restart app
```
### Rebuild after code changes
```bash
docker compose up -d --build
```
### Reset everything
```bash
docker compose down -v # ⚠️ This deletes volumes!
```
## Production Considerations
1. **Secrets Management**
- Never commit `secrets.env`
- Use strong passwords in production
- Rotate API keys regularly
2. **Database Backups**
- Set up automated backups of `data/postgres/`
- Test restore procedures
3. **Resource Limits**
- Add memory/CPU limits to docker-compose.yml if needed
- Monitor with `docker stats`
4. **SSL/TLS**
- Use reverse proxy (nginx/traefik) for HTTPS
- Enable MinIO SSL for production
5. **Monitoring**
- Set up health check endpoints
- Configure alerts for service failures
## Development vs Production
This configuration is for **production** (all services in Docker).
For **development** (local API, Docker infrastructure):
- Use `apps/api-service/docker-compose.yml`
- Run `pnpm dev` from api-service directory
- Connects to Docker services via `localhost:5460` and `localhost:9000`