cosmo/docker-compose.yml

147 lines
4.6 KiB
YAML
Raw Normal View History

2025-12-02 13:25:28 +00:00
version: '3.8'
services:
# PostgreSQL Database
postgres:
2025-12-02 13:45:25 +00:00
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/postgres:15-alpine
2025-12-02 13:25:28 +00:00
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
2026-09-20 05:48:43 +00:00
- ./scripts/init_db.sql:/docker-entrypoint-initdb.d/init_db.sql:ro
2025-12-02 13:25:28 +00:00
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:
2025-12-02 13:45:25 +00:00
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:7-alpine
2025-12-02 13:25:28 +00:00
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}
2026-10-07 16:07:59 +00:00
DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-20}
DATABASE_MAX_OVERFLOW: ${DATABASE_MAX_OVERFLOW:-10}
2025-12-02 13:25:28 +00:00
# Redis
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_DB: 0
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
2026-10-07 16:07:59 +00:00
REDIS_MAX_CONNECTIONS: ${REDIS_MAX_CONNECTIONS:-50}
2025-12-02 13:25:28 +00:00
# Application
APP_NAME: "Cosmo - Deep Space Explorer"
API_PREFIX: /api
2026-10-07 16:07:59 +00:00
# backend/.env is excluded by backend/.dockerignore, so this has to come from here.
# Without it the app silently signs every token with the hard-coded dev default,
# which lets anyone forge user / terminal tokens. Fail fast instead of guessing.
JWT_SECRET_KEY: ${JWT_SECRET_KEY:?JWT_SECRET_KEY is required, set it in .env}
2025-12-02 13:25:28 +00:00
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost}
# Cache
2026-10-07 16:07:59 +00:00
CACHE_TTL_DAYS: ${CACHE_TTL_DAYS:-3}
2025-12-02 13:25:28 +00:00
# Upload
UPLOAD_DIR: /app/upload
2026-10-07 16:07:59 +00:00
MAX_UPLOAD_SIZE: ${MAX_UPLOAD_SIZE:-10485760}
2025-12-03 05:48:38 +00:00
# Proxy (for accessing NASA JPL Horizons API)
HTTP_PROXY: ${HTTP_PROXY:-}
HTTPS_PROXY: ${HTTPS_PROXY:-}
# 火箭发射事件数据源(The Space Devs Launch Library 2)
# 匿名也能同步,注册令牌后速率限制更宽松
LAUNCH_LIBRARY_TOKEN: ${LAUNCH_LIBRARY_TOKEN:-}
2025-12-02 13:25:28 +00:00
volumes:
- /opt/cosmo/data/upload:/app/upload
# 仓库内置资源(火箭模拟的昼/夜地球贴图、滴答音效)随 git 分发,
# 单独挂到 /app/upload/assets,免得每次升级都要往数据目录里拷一份。
- ./backend/upload/assets:/app/upload/assets:ro
2025-12-02 13:25:28 +00:00
- /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:
2025-12-02 16:07:29 +00:00
# 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:-}
2025-12-02 13:25:28 +00:00
container_name: cosmo_frontend
restart: unless-stopped
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
2026-10-07 16:07:59 +00:00
# certbot 在宿主机上签发的证书,nginx 容器里要能读到(启用 443 时需要)
- /etc/letsencrypt:/etc/letsencrypt:ro
2025-12-02 13:25:28 +00:00
ports:
- "80:80"
2026-10-07 16:07:59 +00:00
- "443:443"
2025-12-02 13:25:28 +00:00
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