134 lines
3.6 KiB
YAML
134 lines
3.6 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
# PostgreSQL Database
|
|
postgres:
|
|
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/postgres:15-alpine
|
|
container_name: cosmo_postgres
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB: ${DATABASE_NAME:-cosmo_db}
|
|
POSTGRES_USER: ${DATABASE_USER:-postgres}
|
|
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-postgres}
|
|
PGDATA: /var/lib/postgresql/data/pgdata
|
|
volumes:
|
|
- /opt/cosmo/data/postgres:/var/lib/postgresql/data
|
|
- ./backend/scripts/init_db.sql:/docker-entrypoint-initdb.d/init_db.sql:ro
|
|
ports:
|
|
- "5432:5432"
|
|
networks:
|
|
- cosmo-network
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER:-postgres} -d ${DATABASE_NAME:-cosmo_db}"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# Redis Cache
|
|
redis:
|
|
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:7-alpine
|
|
container_name: cosmo_redis
|
|
restart: unless-stopped
|
|
command: >
|
|
redis-server
|
|
--appendonly yes
|
|
--appendfsync everysec
|
|
--maxmemory 512mb
|
|
--maxmemory-policy allkeys-lru
|
|
volumes:
|
|
- /opt/cosmo/data/redis:/data
|
|
ports:
|
|
- "6379:6379"
|
|
networks:
|
|
- cosmo-network
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 3s
|
|
retries: 5
|
|
|
|
# Backend API (FastAPI)
|
|
backend:
|
|
build:
|
|
context: ./backend
|
|
dockerfile: Dockerfile
|
|
container_name: cosmo_backend
|
|
restart: unless-stopped
|
|
environment:
|
|
# Database
|
|
DATABASE_HOST: postgres
|
|
DATABASE_PORT: 5432
|
|
DATABASE_NAME: ${DATABASE_NAME:-cosmo_db}
|
|
DATABASE_USER: ${DATABASE_USER:-postgres}
|
|
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-postgres}
|
|
DATABASE_POOL_SIZE: 20
|
|
DATABASE_MAX_OVERFLOW: 10
|
|
# Redis
|
|
REDIS_HOST: redis
|
|
REDIS_PORT: 6379
|
|
REDIS_DB: 0
|
|
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
|
|
REDIS_MAX_CONNECTIONS: 50
|
|
# Application
|
|
APP_NAME: "Cosmo - Deep Space Explorer"
|
|
API_PREFIX: /api
|
|
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost}
|
|
# Cache
|
|
CACHE_TTL_DAYS: 3
|
|
# Upload
|
|
UPLOAD_DIR: /app/upload
|
|
MAX_UPLOAD_SIZE: 10485760
|
|
# Proxy (for accessing NASA JPL Horizons API)
|
|
HTTP_PROXY: ${HTTP_PROXY:-}
|
|
HTTPS_PROXY: ${HTTPS_PROXY:-}
|
|
volumes:
|
|
- /opt/cosmo/data/upload:/app/upload
|
|
- /opt/cosmo/data/logs/backend:/app/logs
|
|
ports:
|
|
- "8000:8000"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
networks:
|
|
- cosmo-network
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
# Frontend (Nginx + Static Files)
|
|
frontend:
|
|
build:
|
|
context: ./frontend
|
|
dockerfile: Dockerfile
|
|
args:
|
|
# Don't set VITE_API_BASE_URL to use relative path /api (recommended)
|
|
# This allows the frontend to work with any domain/IP
|
|
VITE_API_BASE_URL: ${VITE_API_BASE_URL:-}
|
|
container_name: cosmo_frontend
|
|
restart: unless-stopped
|
|
volumes:
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
ports:
|
|
- "80:80"
|
|
depends_on:
|
|
- backend
|
|
networks:
|
|
- cosmo-network
|
|
healthcheck:
|
|
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
|
|
networks:
|
|
cosmo-network:
|
|
driver: bridge
|
|
|
|
# Note: Volumes are mapped to host paths as specified
|
|
# Ensure /opt/cosmo/data directory exists with proper permissions
|