Enhance Docker deployment: structured logging, health checks, resource limits, entrypoint script
- Add structured logging config with JSON/text format support - Create docker-entrypoint.sh with dependency health checks - Enhance /health endpoint with DB and Redis connectivity checks - Add resource limits (CPU/memory) for all services - Add network aliases for service discovery - Add container hostnames for better identification - Reduce health check timeout from 20s to 5s - Add build metadata labels to Dockerfile - Use ENTRYPOINT for dependency checking before app startup - Log rotation: 50m per file, 5 files max
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# MTG Online Backend - Docker Deployment
|
||||
|
||||
## Project Overview
|
||||
MTG Online backend REST API with FastAPI, SQLAlchemy, and Alembic migrations. Provides user authentication, deck management, card collection tracking, game rooms, and protocol message handling for MTG Online client compatibility.
|
||||
|
||||
## Docker Deployment Status
|
||||
|
||||
### Current State
|
||||
- **Docker Compose Stack**: Configured and tested
|
||||
- **Port Mapping**: 8990:8000 (backend exposed on host port 8990)
|
||||
- **Services**: 4 containers (backend, postgres, postgres_mtgdata, postgres_mirror, redis)
|
||||
- **Logging**: JSON file logging with rotation (10MB max, 3 files)
|
||||
|
||||
### Recent Fixes Applied
|
||||
1. **Database URL Fix**: Updated `.env` to use Docker service names instead of localhost
|
||||
- `postgres_mtgdata` for mtgdata database
|
||||
- `postgres` for mtgo_platform database
|
||||
- `postgres_mirror` for mtgo_mirror database
|
||||
|
||||
2. **Docker Build**: Successfully built backend image
|
||||
3. **Service Health**: All containers started and became healthy
|
||||
|
||||
### Known Issues
|
||||
- **Backend Connection Error**: Backend container couldn't connect to PostgreSQL due to localhost vs Docker service name mismatch
|
||||
- **Fix Applied**: Updated `.env` file with correct Docker service names
|
||||
- **Status**: Fix applied but NOT yet re-tested after restart
|
||||
|
||||
### Next Steps Required
|
||||
1. Restart Docker containers with updated `.env`
|
||||
2. Verify backend can connect to all three PostgreSQL databases
|
||||
3. Test health endpoint on port 8990
|
||||
4. Test authentication and CRUD operations
|
||||
5. Verify logging output
|
||||
|
||||
## Architecture
|
||||
- **Primary Database**: mtgo_platform (user data, decks, cards)
|
||||
- **MTG Data Database**: mtgdata (canonical card data)
|
||||
- **Mirror Database**: mtgo_mirror (fast deckbuilding queries)
|
||||
- **Cache**: Redis for session/cache management
|
||||
- **Async Driver**: asyncpg for async SQLAlchemy support
|
||||
|
||||
## Commands
|
||||
```bash
|
||||
# Start stack
|
||||
cd /home/wall-o/projects/mtgonline/backend
|
||||
docker compose up -d
|
||||
|
||||
# View logs
|
||||
docker compose logs -f backend
|
||||
docker compose logs -f postgres
|
||||
|
||||
# Stop stack
|
||||
docker compose down
|
||||
|
||||
# Rebuild after changes
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
## API Access
|
||||
- **Health Check**: http://localhost:8990/health
|
||||
- **API Docs**: http://localhost:8990/docs
|
||||
- **Backend Port**: 8990 (mapped to container port 8000)
|
||||
Reference in New Issue
Block a user