name: baron-sso

services:
  backend:
    image: ${BACKEND_IMAGE_NAME}:${IMAGE_TAG}
    container_name: baron_backend
    restart: unless-stopped
    env_file:
      - .env
    environment:
      - APP_ENV=${APP_ENV:-production}
      - APP_ENV=production
      - COOKIE_SECRET=${COOKIE_SECRET}
      - DB_HOST=postgres
      - CLICKHOUSE_HOST=clickhouse
      - CLICKHOUSE_PORT=${CLICKHOUSE_PORT_NATIVE:-9000}
      - CLICKHOUSE_USER=${CLICKHOUSE_USER:-baron}
      - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-password}
      - USERFRONT_URL=${USERFRONT_URL:-https://sso.hmac.kr}
      - SEED_TENANT_CSV_PATH=/app/seed-tenant.csv
    ports:
      - "${BACKEND_PORT:-3010}:3010"
    volumes:
      - ./adminfront/seed-tenant.csv:/app/seed-tenant.csv:ro
    depends_on:
      - infra_check
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3010/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s
    networks:
      - baron_net

  userfront:
    image: ${USERFRONT_IMAGE_NAME}:${IMAGE_TAG}
    container_name: baron_userfront
    restart: unless-stopped
    environment:
      - USERFRONT_URL=${USERFRONT_URL:-https://sso.hmac.kr}
      - BACKEND_URL=${USERFRONT_URL:-https://sso.hmac.kr}
    ports:
      - "${USERFRONT_PORT:-80}:80"
    depends_on:
      backend:
        condition: service_healthy
    networks:
      - baron_net

  infra_check:
    image: alpine
    command: ["echo", "Infrastructure assumed running"]
    networks:
      - baron_net

networks:
  baron_net:
    external: true
    name: baron_network
