# Axiom — Bot + Dashboard (HexaHost) behind Traefik
#
# Prerequisites:
#   - External Docker network: traefik-network
#   - Traefik already running and attached to that network
#   - Copy .env.docker.example → .env and fill secrets
#
# Start:
#   docker compose up -d --build

name: axiom

services:
  bot:
    build:
      context: ./bot
      dockerfile: Dockerfile
    container_name: axiom-bot
    restart: unless-stopped
    env_file:
      - .env
    environment:
      API_ENABLED: "true"
      API_HOST: "0.0.0.0"
      API_PORT: "8000"
      TUNNEL_ENABLED: "false"
      CORS_ORIGINS: "https://bot.hexahost.de"
    volumes:
      - bot-db:/app/db
      - bot-jsondb:/app/jsondb
      - bot-logs:/app/logs
    networks:
      - traefik-network
      - axiom-internal
    healthcheck:
      test:
        [
          "CMD",
          "python",
          "-c",
          "import socket; s=socket.create_connection(('127.0.0.1',8000),5); s.close()",
        ]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 90s

  dashboard:
    build:
      context: ./dashboard
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_BRAND_NAME: ${NEXT_PUBLIC_BRAND_NAME:-Axiom}
        NEXT_PUBLIC_BRAND_NAME_WORD: ${NEXT_PUBLIC_BRAND_NAME_WORD:-AX}
        NEXT_PUBLIC_ADMIN_IDS: ${NEXT_PUBLIC_ADMIN_IDS:-}
    container_name: axiom-dashboard
    restart: unless-stopped
    depends_on:
      bot:
        condition: service_started
    env_file:
      - .env
    environment:
      # Server-side proxy → Bot API (Docker-intern, nicht öffentlich)
      DASHBOARD_API_URL: http://bot:8000/api/v1
      NEXTAUTH_URL: https://bot.hexahost.de/
      NEXT_PUBLIC_BRAND_NAME: ${NEXT_PUBLIC_BRAND_NAME:-Axiom}
      NEXT_PUBLIC_BRAND_NAME_WORD: ${NEXT_PUBLIC_BRAND_NAME_WORD:-AX}
      PORT: "3000"
      HOSTNAME: "0.0.0.0"
    networks:
      - traefik-network
      - axiom-internal
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik-network
      # HTTP → HTTPS redirect (optional, falls Entrypoint "web" existiert)
      - traefik.http.routers.axiom-dashboard-http.rule=Host(`bot.hexahost.de`)
      - traefik.http.routers.axiom-dashboard-http.entrypoints=web
      - traefik.http.routers.axiom-dashboard-http.middlewares=axiom-https-redirect
      - traefik.http.middlewares.axiom-https-redirect.redirectscheme.scheme=https
      - traefik.http.middlewares.axiom-https-redirect.redirectscheme.permanent=true
      # HTTPS
      - traefik.http.routers.axiom-dashboard.rule=Host(`bot.hexahost.de`)
      - traefik.http.routers.axiom-dashboard.entrypoints=websecure
      - traefik.http.routers.axiom-dashboard.tls=true
      - traefik.http.routers.axiom-dashboard.tls.certresolver=${TRAEFIK_CERT_RESOLVER:-letsencrypt}
      - traefik.http.services.axiom-dashboard.loadbalancer.server.port=3000

networks:
  traefik-network:
    external: true
  axiom-internal:
    driver: bridge

volumes:
  bot-db:
  bot-jsondb:
  bot-logs:
