services:
  traefik:
    image: traefik:latest
    container_name: traefik-node${TRAEFIK_NODE_ID}
    network_mode: host
    extra_hosts:
      - "host.docker.internal:host-gateway"
    cpus: 1.0
    mem_limit: "1024m"
    mem_reservation: "128m"
    restart: always
    command:
      - "--api.dashboard=true"
      - "--api.insecure=true" 
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.useBindPortIP=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      # Variables for flexibility
      - "--providers.docker.network=${HOME_EXT_NETWORK},${DNS_EXT_NETWORK}"
      - "--providers.file.directory=/etc/traefik/dynamic"
      - "--providers.file.watch=true"
      ## DNS resolver
      - "--certificatesresolvers.dns_resolver.acme.dnschallenge=true"
      - "--certificatesresolvers.dns_resolver.acme.dnschallenge.provider=desec"
      - "--certificatesresolvers.dns_resolver.acme.dnschallenge.delaybeforecheck=90"
      - "--certificatesresolvers.dns_resolver.acme.dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53"
      - "--certificatesresolvers.dns_resolver.acme.email=${ACME_EMAIL}"
      - "--certificatesresolvers.dns_resolver.acme.storage=/letsencrypt/acme.json"
      ## HTTP Resolver
      - "--certificatesresolvers.http_resolver.acme.httpchallenge=true"
      - "--certificatesresolvers.http_resolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.http_resolver.acme.storage=/letsencrypt/acme.json"
      - "--certificatesresolvers.http_resolver.acme.email=${ACME_EMAIL}"
    environment:
      - DESEC_TOKEN=${DESEC_TOKEN}
      - DESEC_DOMAIN=${DESEC_DOMAIN}
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "/docker/traefik/letsencrypt:/letsencrypt"
      - "/docker/traefik/dynamic:/etc/traefik/dynamic"