# Dashboard Services
# SABLIER SESSION DURATION: Set to 5m for testing. Increase to 30m for production in config-templates/traefik/dynamic/sablier.yml
# RESTART POLICY GUIDE:
# - unless-stopped: Core infrastructure services that should always run
# - no: Services with Sablier lazy loading (start on-demand)
# - See individual service comments for specific reasoning

services:
  # Homepage - Default Application Dashboard
  homepage:
    image: ghcr.io/gethomepage/homepage:latest
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
          pids: 512
        reservations:
          cpus: '0.25'
          memory: 128M
    container_name: homepage
    restart: unless-stopped    # change to 'no' to enable Sablier lazy loading
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '3003:3000'
    volumes:
      - ./homepage:/app/config
      - /var/run/docker.sock:/var/run/docker.sock # For Docker integration do not mount RO
      - ${STACKS_DIR}:${STACKS_DIR} # To discover other stacks
    environment:
      - PUID=${PUID}  # Must be set to the docker user ID
      - PGID=${PGID}  # Must be set to the docker group ID
      - TZ=${TZ}
      - HOMEPAGE_ALLOWED_HOSTS=${HOMEPAGE_ALLOWED_HOSTS}
    labels:
      # TRAEFIK CONFIGURATION
      # ==========================================
      # Service metadata
      - 'homelab.category=dashboard'
      - 'homelab.description=Application dashboard'
      # Traefik reverse proxy (comment/uncomment to disable/enable)
      # IMPORTANT: On REMOTE SERVERS (where Traefik runs elsewhere):
      #   - COMMENT OUT all traefik.* labels below (don't delete them)
      #   - Routes are configured via external YAML files on the core server
      #   - This prevents conflicts between Docker labels and file provider
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      - 'traefik.http.routers.homepage.rule=Host(`homepage.${DOMAIN}`)'
      - 'traefik.http.routers.homepage.entrypoints=websecure'
      - 'traefik.http.routers.homepage.tls=true'
      - 'traefik.http.routers.homepage.middlewares=authelia@docker'
      - 'traefik.http.services.homepage.loadbalancer.server.port=3000'
      # Sablier lazy loading (disabled by default - uncomment to enable)
      # - 'sablier.enable=true'
      # - 'sablier.group=jasper-homarr'
      # - 'sablier.start-on-demand=true'

  # Homarr - Modern dashboard
  # Uses Sablier lazy loading - starts on-demand, stops after 5min inactivity
  homarr:
    image:  ghcr.io/homarr-labs/homarr:latest
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
          pids: 512
        reservations:
          cpus: '0.25'
          memory: 128M
    container_name: homarr
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '7575:7575'
    volumes:
      - ./homarr/config:/app/config/configs
      - ./homarr/data:/data
      - ./homarr/icons:/app/public/icons
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - TZ=${TZ}
      - SECRET_ENCRYPTION_KEY=8830c9434b05ebfe3e31340c685fea63446ab3f635c4fad68370006949ed30df
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:7575/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    labels:
      # TRAEFIK CONFIGURATION
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=dashboard'
      - 'homelab.description=Modern homelab dashboard'
      - 'traefik.enable=true'
      # Router configuration
      - 'traefik.http.routers.homarr.rule=Host(`homarr.${DOMAIN}`)'
      - 'traefik.http.routers.homarr.entrypoints=websecure'
      - 'traefik.http.routers.homarr.tls=true'
      - 'traefik.http.routers.homarr.middlewares=authelia@docker'
      # Service configuration
      - 'traefik.http.services.homarr.loadbalancer.server.port=7575'
      # Sablier configuration
      - 'sablier.enable=true'
      - 'sablier.group=jasper-homarr'
      - 'sablier.start-on-demand=true'

# DOCKGE URL CONFIGURATION
x-dockge:
  urls:
    # Proxied URLs (through Traefik)
    - https://homepage.${DOMAIN}
    - https://192.168.4.4:3003
    - https://homarr.${DOMAIN}
    - https://192.168.4.4:7575

networks:
  homelab-network:
    external: true
  traefik-network:
    external: true
