services:
  caddy-prod-b:
    image: caddy:2-alpine
    container_name: caddy-prod-b
    restart: unless-stopped
    environment:
      BASE_DOMAIN: ${BASE_DOMAIN}
      FRONTEND_UPSTREAM: frontend-prod-b:3000
      BACKEND_UPSTREAM: backend-prod-b:8081
      FINE_TUNE_UPSTREAM: fine-tune-helper-prod-b:4310
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile.prod-b:/etc/caddy/Caddyfile:ro
      - BoostAI_caddy_data_prod_b:/data
      - BoostAI_caddy_config_prod_b:/config
    depends_on:
      backend-prod-b:
        condition: service_healthy
      frontend-prod-b:
        condition: service_started
      fine-tune-helper-prod-b:
        condition: service_healthy

  backend-prod-b:
    image: boost-ai/demo-backend-prod-b:${PROD_B_TAG:-latest}
    container_name: backend-prod-b
    restart: unless-stopped
    env_file:
      - ${PROD_B_ENV_FILE:-.env.prod-b}
    environment:
      GO_ENV: production
      BACKEND_INTERNAL_PORT: 8081
      ALLOWED_ORIGINS: http://${BASE_DOMAIN},https://${BASE_DOMAIN}
      DATABASE_URL: postgres://boostai:${POSTGRES_PASSWORD}@postgres-prod-b:5432/boostai?sslmode=disable
      JWT_SECRET: ${JWT_SECRET}
      SESSION_COOKIE_NAME: ${SESSION_COOKIE_NAME:-boostai_session}
    depends_on:
      postgres-prod-b:
        condition: service_healthy
    expose:
      - "8081"
    volumes:
      - ./Mock-Data:/app/Mock-Data:ro
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8081/health"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 15s

  frontend-prod-b:
    image: boost-ai/demo-frontend-prod-b:${PROD_B_TAG:-latest}
    container_name: frontend-prod-b
    restart: unless-stopped
    environment:
      NODE_ENV: production
      HOST: 0.0.0.0
      PORT: 3000
      NITRO_HOST: 0.0.0.0
      NITRO_PORT: 3000
      ALLOWED_HOSTS: ${BASE_DOMAIN}
      __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS: ${BASE_DOMAIN}
    expose:
      - "3000"

  fine-tune-helper-prod-b:
    image: node:22-alpine
    container_name: fine-tune-helper-prod-b
    restart: unless-stopped
    working_dir: /app
    command: sh -lc "npm ci && npm run start"
    env_file:
      - ${PROD_B_ENV_FILE:-.env.prod-b}
    environment:
      PORT: 4310
      HOST: 0.0.0.0
      FINE_TUNE_AI_ENDPOINT: ${FINE_TUNE_AI_ENDPOINT}
      FINE_TUNE_AI_API_KEY: ${FINE_TUNE_AI_API_KEY}
      FINE_TUNE_AI_MODEL: ${FINE_TUNE_AI_MODEL}
      FINE_TUNE_BACKEND_URL: ${FINE_TUNE_BACKEND_URL}
      FINE_TUNE_BACKEND_TOKEN: ${FINE_TUNE_BACKEND_TOKEN}
    expose:
      - "4310"
    volumes:
      - ./FineTune:/app
      - BoostAI_fine_tune_node_modules_prod_b:/app/node_modules
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:4310/health"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 15s

  postgres-prod-b:
    image: postgres:16-alpine
    container_name: postgres-prod-b
    restart: unless-stopped
    environment:
      POSTGRES_DB: boostai
      POSTGRES_USER: boostai
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - BoostAI_postgres_prod_b_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U boostai -d boostai"]
      interval: 5s
      timeout: 5s
      retries: 10

volumes:
  BoostAI_postgres_prod_b_data:
  BoostAI_caddy_data_prod_b:
  BoostAI_caddy_config_prod_b:
  BoostAI_fine_tune_node_modules_prod_b:
