cosmo/docker-compose.yml

144 lines
4.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
- ./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: ${DATABASE_POOL_SIZE:-20}
DATABASE_MAX_OVERFLOW: ${DATABASE_MAX_OVERFLOW:-10}
# Redis
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_DB: 0
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
REDIS_MAX_CONNECTIONS: ${REDIS_MAX_CONNECTIONS:-50}
# Application
APP_NAME: "Cosmo - Deep Space Explorer"
API_PREFIX: /api
# 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}
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost}
# Cache
CACHE_TTL_DAYS: ${CACHE_TTL_DAYS:-3}
# Upload
UPLOAD_DIR: /app/upload
MAX_UPLOAD_SIZE: ${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
# 仓库内置资源(火箭模拟的昼/夜地球贴图、滴答音效)随 git 分发,
# 单独挂到 /app/upload/assets,免得每次升级都要往数据目录里拷一份。
- ./backend/upload/assets:/app/upload/assets:ro
- /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
# certbot 在宿主机上签发的证书,nginx 容器里要能读到(启用 443 时需要)
- /etc/letsencrypt:/etc/letsencrypt:ro
ports:
- "80:80"
- "443:443"
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