181 lines
4.4 KiB
YAML
181 lines
4.4 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
# Passport Service
|
|
passport-service:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
container_name: passport-service
|
|
restart: unless-stopped
|
|
ports:
|
|
- "12426:12426" # gRPC port
|
|
- "12425:12425" # HTTP Gateway port
|
|
environment:
|
|
- SERVICE_ENV=docker
|
|
- TZ=Asia/Shanghai
|
|
volumes:
|
|
- ./etc:/app/etc:ro
|
|
- ./logs:/app/logs
|
|
depends_on:
|
|
- postgres
|
|
- redis
|
|
- etcd
|
|
networks:
|
|
- passport-network
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:12425/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
# PostgreSQL Database
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
container_name: passport-postgres
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB: passport_db
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-passport_password}
|
|
TZ: Asia/Shanghai
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./scripts:/docker-entrypoint-initdb.d:ro
|
|
ports:
|
|
- "5432:5432"
|
|
networks:
|
|
- passport-network
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# Redis Cache
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: passport-redis
|
|
restart: unless-stopped
|
|
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-passport_redis_password}
|
|
environment:
|
|
TZ: Asia/Shanghai
|
|
volumes:
|
|
- redis_data:/data
|
|
ports:
|
|
- "6379:6379"
|
|
networks:
|
|
- passport-network
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 5
|
|
|
|
# Etcd Service Discovery
|
|
etcd:
|
|
image: quay.io/coreos/etcd:v3.5.9
|
|
container_name: passport-etcd
|
|
restart: unless-stopped
|
|
environment:
|
|
ETCD_NAME: etcd0
|
|
ETCD_DATA_DIR: /etcd-data
|
|
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
|
|
ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
|
|
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
|
|
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd:2380
|
|
ETCD_INITIAL_CLUSTER: etcd0=http://etcd:2380
|
|
ETCD_INITIAL_CLUSTER_TOKEN: etcd-cluster-1
|
|
ETCD_INITIAL_CLUSTER_STATE: new
|
|
ETCD_AUTO_COMPACTION_RETENTION: 1
|
|
TZ: Asia/Shanghai
|
|
volumes:
|
|
- etcd_data:/etcd-data
|
|
ports:
|
|
- "2379:2379"
|
|
- "2380:2380"
|
|
networks:
|
|
- passport-network
|
|
healthcheck:
|
|
test: ["CMD", "etcdctl", "endpoint", "health"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# Nginx Reverse Proxy (Optional)
|
|
nginx:
|
|
image: nginx:alpine
|
|
container_name: passport-nginx
|
|
restart: unless-stopped
|
|
ports:
|
|
- "80:80"
|
|
- "443:443"
|
|
volumes:
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./nginx/ssl:/etc/nginx/ssl:ro
|
|
depends_on:
|
|
- passport-service
|
|
networks:
|
|
- passport-network
|
|
profiles:
|
|
- with-nginx
|
|
|
|
# Prometheus Monitoring (Optional)
|
|
prometheus:
|
|
image: prom/prometheus:latest
|
|
container_name: passport-prometheus
|
|
restart: unless-stopped
|
|
ports:
|
|
- "9090:9090"
|
|
volumes:
|
|
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
|
- prometheus_data:/prometheus
|
|
command:
|
|
- '--config.file=/etc/prometheus/prometheus.yml'
|
|
- '--storage.tsdb.path=/prometheus'
|
|
- '--web.console.libraries=/etc/prometheus/console_libraries'
|
|
- '--web.console.templates=/etc/prometheus/consoles'
|
|
- '--storage.tsdb.retention.time=200h'
|
|
- '--web.enable-lifecycle'
|
|
networks:
|
|
- passport-network
|
|
profiles:
|
|
- with-monitoring
|
|
|
|
# Grafana Dashboard (Optional)
|
|
grafana:
|
|
image: grafana/grafana:latest
|
|
container_name: passport-grafana
|
|
restart: unless-stopped
|
|
ports:
|
|
- "3000:3000"
|
|
environment:
|
|
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin}
|
|
volumes:
|
|
- grafana_data:/var/lib/grafana
|
|
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
|
|
- ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources:ro
|
|
depends_on:
|
|
- prometheus
|
|
networks:
|
|
- passport-network
|
|
profiles:
|
|
- with-monitoring
|
|
|
|
volumes:
|
|
postgres_data:
|
|
driver: local
|
|
redis_data:
|
|
driver: local
|
|
etcd_data:
|
|
driver: local
|
|
prometheus_data:
|
|
driver: local
|
|
grafana_data:
|
|
driver: local
|
|
|
|
networks:
|
|
passport-network:
|
|
driver: bridge
|