ShieldGate sử dụng Docker Compose để quản lý infrastructure với các service chính:
- PostgreSQL: Database chính cho lưu trữ dữ liệu
- Redis: Cache và session storage
- Auth Server: OAuth 2.0 Authorization Server
- Nginx: Reverse proxy và load balancer (production)
- Prometheus: Monitoring và metrics (optional)
- Grafana: Dashboard và visualization (optional)
# Clone repository và setup
git clone <repository-url>
cd shieldgate
# Setup development environment (tự động tạo .env, SSL certs, etc.)
make setup
# Hoặc chạy manual
chmod +x scripts/setup.sh
./scripts/setup.sh# Start tất cả services
make start
# Hoặc start development mode
make start-dev
# Start với monitoring
make start-monitoring# Check health
make health
# View logs
make logs
# Test OAuth flow
make test-oauth# Database
POSTGRES_DB=authdb
POSTGRES_USER=authuser
POSTGRES_PASSWORD=generated_secure_password
POSTGRES_PORT=5432
# Redis
REDIS_PASSWORD=generated_redis_password
REDIS_PORT=6379
# Server
SERVER_URL=http://localhost:8080
SERVER_PORT=8080
GIN_MODE=debug
# JWT (auto-generated 64-char secret)
JWT_SECRET=generated_jwt_secret
# Security
BCRYPT_COST=12
ACCESS_TOKEN_DURATION=3600
REFRESH_TOKEN_DURATION=2592000
# Logging
LOG_LEVEL=debug
LOG_FORMAT=text# Override for production
GIN_MODE=release
LOG_LEVEL=warn
LOG_FORMAT=json
SERVER_URL=https://auth.yourdomain.com
# Use strong passwords
POSTGRES_PASSWORD=your_production_password
REDIS_PASSWORD=your_production_redis_password
JWT_SECRET=your_production_jwt_secret_64_chars_minimum- Image:
postgres:15-alpine - Port: 5432
- Features:
- Automatic initialization với schema
- Performance tuning cho production
- Health checks
- Backup support
- Image:
redis:7-alpine - Port: 6379
- Features:
- Persistent storage với AOF
- Memory optimization
- Password protection
- Rate limiting support
- Build: Multi-stage Dockerfile
- Port: 8080
- Features:
- OAuth 2.0 & OpenID Connect
- Multi-tenant support
- JWT token management
- Health checks
- Image:
nginx:alpine - Ports: 80, 443
- Features:
- SSL/TLS termination
- Rate limiting
- Security headers
- Load balancing
- Image:
prom/prometheus:latest - Port: 9090
- Features:
- Metrics collection
- Alerting rules
- Data retention
- Image:
grafana/grafana:latest - Port: 3000
- Features:
- Pre-configured dashboards
- Prometheus integration
- User management
# Start development environment
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
# Features:
# - Hot reload
# - Debug mode
# - Exposed ports
# - Development tools# Start production environment
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Features:
# - Resource limits
# - Replicas
# - Optimized configuration
# - Security hardening# Start with monitoring
docker-compose --profile monitoring up -d
# Includes:
# - Prometheus
# - Grafana
# - Metrics collectionDatabase được tự động khởi tạo với:
-
Schema Creation (
scripts/init-db.sql):- Tables: tenants, users, clients, authorization_codes, access_tokens, refresh_tokens
- Constraints và relationships
- Default data cho development
-
Performance Indexes (
scripts/create-indexes.sql):- Optimized indexes cho multi-tenant queries
- Composite indexes cho common patterns
- Partial indexes cho cleanup operations
Development environment bao gồm:
- Default Tenant:
localhostdomain - Admin User:
admin@localhost/admin123 - Dev Client:
shieldgate-dev-client(confidential) - SPA Client:
shieldgate-spa-client(public)
# Auto-generated trong setup script
openssl req -x509 -newkey rsa:4096 -keyout config/ssl/key.pem -out config/ssl/cert.pem -days 365 -nodes# Sử dụng certbot hoặc cloud provider SSL
# Update nginx.conf với proper certificatesNginx được cấu hình với security headers:
- HSTS
- X-Frame-Options
- X-Content-Type-Options
- CSP (Content Security Policy)
- Referrer Policy
- OAuth endpoints: 10 requests/minute
- API endpoints: 100 requests/minute
- Redis-based: Distributed rate limiting
Tất cả services có health checks:
# Check all services
make health
# Individual checks
curl http://localhost:8080/health
docker-compose exec postgres pg_isready
docker-compose exec redis redis-cli ping- Format: JSON (production), Text (development)
- Levels: ERROR, WARN, INFO, DEBUG
- Fields: request_id, tenant_id, user_id, client_id
# View logs
make logs
make logs-auth
# Follow specific service
docker-compose logs -f auth-serverAvailable metrics:
- HTTP request duration và count
- OAuth token generation
- Database connection pool
- Redis operations
- System resources
Pre-configured dashboards:
- Application performance
- OAuth flow metrics
- Database performance
- System resources
# Create backup
make backup
# Includes:
# - Database dump (compressed)
# - Configuration files
# - SSL certificates# List available backups
./scripts/restore.sh
# Restore database
make restore-db BACKUP_FILE=backups/database_backup_20240122_120000.sql.gz
# Restore configuration
make restore-config BACKUP_FILE=backups/config_backup_20240122_120000.tar.gz- Frequency: Daily automated backups
- Retention: 7 days local, longer in cloud storage
- Verification: Automatic backup validation
- Recovery: Tested restore procedures
Production settings:
max_connections = 200
shared_buffers = 256MB
effective_cache_size = 1GB
maintenance_work_mem = 64MB
checkpoint_completion_target = 0.9
wal_buffers = 16MBmaxmemory 256mb
maxmemory-policy allkeys-lru
appendonly yes
appendfsync everysec- Connection pooling
- Query optimization
- Caching strategies
- Resource limits
# Quick start
make quick-start
# Manual steps
make setup
make start
make health# Build production image
make build-prod
# Deploy with production config
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d# With CI/CD pipeline
make deploy-prod
# Manual deployment
docker-compose -f docker-compose.prod.yml up -d --scale auth-server=3# Check database status
docker-compose exec postgres pg_isready
# Check logs
docker-compose logs postgres
# Restart database
docker-compose restart postgres# Check logs
make logs-auth
# Verify environment
make env-validate
# Check health
curl http://localhost:8080/health# Check Redis
docker-compose exec redis redis-cli ping
# Check password
docker-compose exec redis redis-cli -a $REDIS_PASSWORD ping# Start in debug mode
GIN_MODE=debug LOG_LEVEL=debug make start-dev
# Access container shell
make shell
# Check configuration
docker-compose config-
Daily:
- Check service health
- Review logs for errors
- Monitor resource usage
-
Weekly:
- Create backups
- Update dependencies
- Review security logs
-
Monthly:
- Update base images
- Review performance metrics
- Test disaster recovery
# Update images
docker-compose pull
# Rebuild application
make build
# Rolling update
docker-compose up -d --no-deps auth-server- Documentation: Check this file và README.md
- Logs:
make logsđể xem chi tiết - Health Checks:
make healthđể verify services - Configuration:
make env-validateđể check config
# Quick reference
make help
# Service status
make status
# Generate new secrets
make generate-secret
# Test OAuth flow
make test-oauthNote: Infrastructure này được thiết kế để scale từ development đến production với minimal changes. Tất cả configurations đều được externalized qua environment variables và có thể customize theo needs cụ thể.