# 数据快照备份服务 (2.0 算力挖矿系统 - standalone 模式)
# 使用方式: docker compose -f docker-compose.2.0.yml -f docker-compose.2.0-snapshot.yml --profile standalone up snapshot-service-2
#
# 纯新增 overlay，不修改任何现有服务配置

services:
  # 为 mining-admin-web 补充 snapshot-service 代理地址
  mining-admin-web:
    environment:
      - SNAPSHOT_SERVICE_URL=http://snapshot-service-2:3199

  snapshot-service-2:
    build:
      context: ./snapshot-service
      dockerfile: Dockerfile
    container_name: rwa-snapshot-service-2
    restart: unless-stopped
    ports:
      - "3199:3199"
    environment:
      - NODE_ENV=production
      - APP_PORT=3199
      - DATABASE_URL=file:/app/data/snapshot.db
      # PostgreSQL-2 (备份目标)
      - PG_HOST=postgres-2
      - PG_PORT=5432
      - PG_USER=${POSTGRES_USER:-rwa_user}
      - PG_PASSWORD=${POSTGRES_PASSWORD}
      # Redis-2 (备份目标)
      - REDIS_HOST=redis-2
      - REDIS_PORT=6379
      - REDIS_PASSWORD=${REDIS_PASSWORD:-}
      # MinIO (存储后端)
      - MINIO_ENDPOINT=${MINIO_ENDPOINT:-192.168.1.100}
      - MINIO_PORT=${MINIO_PORT:-9000}
      - MINIO_USE_SSL=${MINIO_USE_SSL:-false}
      - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}
      - MINIO_SECRET_KEY=${MINIO_SECRET_KEY}
      - MINIO_BACKUP_BUCKET=snapshots-2
      # 备份配置
      - SNAPSHOT_TEMP_DIR=/tmp/snapshots
      - SNAPSHOT_RETENTION_HOURS=72
      - AVAILABLE_TARGETS=POSTGRES,REDIS,UPLOADS
    volumes:
      - snapshot_2_data:/app/data
      - /tmp/rwa-snapshots-2:/tmp/snapshots
      - redis_2_data:/backup-source/redis:ro
      - mining-admin-uploads:/backup-source/uploads/mining-admin:ro
      - trading-uploads:/backup-source/uploads/trading:ro
    profiles:
      - standalone
    depends_on:
      postgres-2:
        condition: service_healthy
      redis-2:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3199/api/v1/health"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 30s
    networks:
      - rwa-2-network

volumes:
  snapshot_2_data:
