version: '3.8'

services:
  # PostgreSQL数据库服务
  postgres:
    image: postgres:15-alpine
    container_name: novalon-postgres
    environment:
      POSTGRES_DB: manage_system
      POSTGRES_USER: novalon
      POSTGRES_PASSWORD: novalon123
    ports:
      - "55432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U novalon -d manage_system"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - novalon-network

  # 后端API服务
  backend:
    build:
      context: ./novalon-manage-api
      dockerfile: Dockerfile
    container_name: novalon-backend
    environment:
      SPRING_PROFILES_ACTIVE: docker
      SPRING_R2DBC_URL: r2dbc:postgresql://postgres:5432/manage_system
      SPRING_R2DBC_USERNAME: novalon
      SPRING_R2DBC_PASSWORD: novalon123
    ports:
      - "8084:8084"
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8084/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - novalon-network

  # 前端Web服务
  frontend:
    build:
      context: ./novalon-manage-web
      dockerfile: Dockerfile
    container_name: novalon-frontend
    ports:
      - "3001:80"
    depends_on:
      backend:
        condition: service_healthy
    environment:
      - VITE_API_BASE_URL=http://backend:8084
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - novalon-network

volumes:
  postgres_data:
    driver: local

networks:
  novalon-network:
    driver: bridge