services:
  architools:
    build:
      context: .
      args:
        - NEXT_PUBLIC_STORAGE_ADAPTER=${NEXT_PUBLIC_STORAGE_ADAPTER:-database}
        - NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME:-ArchiTools}
        - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-https://tools.beletage.ro}
        - NEXT_PUBLIC_MARTIN_URL=${NEXT_PUBLIC_MARTIN_URL}
        - NEXT_PUBLIC_PMTILES_URL=${NEXT_PUBLIC_PMTILES_URL}
        # Inject git SHA + build timestamp; deploy via:
        # GIT_COMMIT=$(git rev-parse HEAD) BUILD_TIME=$(date -u +%FT%TZ) docker compose build
        - GIT_COMMIT=${GIT_COMMIT:-unknown}
        - BUILD_TIME=${BUILD_TIME:-unknown}
    container_name: architools
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      # Infisical runtime bootstrap (all app secrets fetched from /architools at boot via docker-entrypoint.sh)
      - INFISICAL_CLIENT_ID=${INFISICAL_CLIENT_ID}
      - INFISICAL_CLIENT_SECRET=${INFISICAL_CLIENT_SECRET}
      - NODE_ENV=${NODE_ENV:-production}
      - PORT=3000
      - HOSTNAME=0.0.0.0
    depends_on:
      dwg2dxf:
        condition: service_healthy
    volumes:
      # SMB share for ManicTime Tags.txt (mount on host: //time/tags → /mnt/manictime)
      - /mnt/manictime:/mnt/manictime
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

  dwg2dxf:
    build:
      context: ./dwg2dxf-api
    container_name: dwg2dxf
    restart: unless-stopped
    healthcheck:
      test:
        [
          "CMD",
          "python3",
          "-c",
          "import urllib.request; urllib.request.urlopen('http://localhost:5001/health')",
        ]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s

  martin:
    build:
      context: .
      dockerfile: martin.Dockerfile
    container_name: martin
    restart: unless-stopped
    # No host port — only accessible via tile-cache nginx proxy
    command: ["--config", "/config/martin.yaml"]
    environment:
      - DATABASE_URL=${DATABASE_URL}

  tile-cache:
    build:
      context: .
      dockerfile: tile-cache.Dockerfile
    container_name: tile-cache
    restart: unless-stopped
    ports:
      - "3010:80"
    depends_on:
      - martin
    volumes:
      - tile-cache-data:/var/cache/nginx/tiles

  tippecanoe:
    build:
      context: .
      dockerfile: tippecanoe.Dockerfile
    container_name: tippecanoe
    profiles: ["tools"]
    environment:
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASS}
      - MINIO_ENDPOINT=${MINIO_ENDPOINT}
      - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}
      - MINIO_SECRET_KEY=${MINIO_SECRET_KEY}

volumes:
  tile-cache-data:
