services:
  # PostgreSQL 数据库服务
  qaup-postgres:
    image: m.daocloud.io/docker.io/postgis/postgis:17-3.5-alpine
    container_name: qaup-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: qaup
      POSTGRES_USER: qaup
      POSTGRES_PASSWORD: qaup123
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U qaup"]
      interval: 30s
      timeout: 10s
      retries: 5

  # Redis 缓存服务
  qaup-redis:
    image: m.daocloud.io/docker.io/library/redis:8.0-alpine
    container_name: qaup-redis
    restart: unless-stopped
    command: ["redis-server", "--maxmemory", "256mb", "--maxmemory-policy", "allkeys-lru"]
    volumes:
      - ./data/redis:/data
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3

  # QAUP 应用服务
  qaup-app:
    image: m.daocloud.io/docker.io/library/eclipse-temurin:17-jre
    container_name: qaup-app
    restart: unless-stopped
    environment:
      SPRING_PROFILES_ACTIVE: prod
      LOG_PATH: /app/logs
    volumes:
      - ./app.jar:/app/app.jar
      - ./config.yml:/app/config.yml
      - ./logs:/app/logs
    ports:
      - "8080:8080"
    depends_on:
      qaup-postgres:
        condition: service_healthy
      qaup-redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 120s
    command: ["java", "-jar", "/app/app.jar", "--spring.config.location=/app/config.yml"]

networks:
  default:
    name: qaup-network