version: "3.4"
x-logging: &logging
  logging:
    driver: json-file
    options:
      max-size: 10m
      max-file: "3"

services:
  traefik:
    image: traefik-aws
    build:
      context: ./contrib/traefik-haproxy/traefik
    restart: ${RESTART}
    command:
#      - --log.level=DEBUG
#      - --accesslog=true
#      - --accesslog.format=json
#      - --accesslog.fields.defaultmode=keep
#      - --accesslog.fields.headers.defaultmode=keep
#      - --certificatesResolvers.letsencrypt.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --certificatesresolvers.letsencrypt.acme.dnschallenge=true
      - --certificatesresolvers.letsencrypt.acme.dnschallenge.provider=route53
      - --certificatesresolvers.letsencrypt.acme.email=${ACME_EMAIL}
      - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
      - --entrypoints.web.address=:${TRAEFIK_WEB_HTTP_PORT}
      - --entrypoints.web.http.redirections.entrypoint.to=websecure
      - --entrypoints.web.http.redirections.entrypoint.scheme=https
      - --entrypoints.websecure.address=:${TRAEFIK_WEB_PORT}
    ports:
      - ${TRAEFIK_WEB_PORT}:${TRAEFIK_WEB_PORT}/tcp
      - ${TRAEFIK_WEB_HTTP_PORT}:${TRAEFIK_WEB_HTTP_PORT}/tcp
    environment:
      - AWS_PROFILE=${AWS_PROFILE}
      - AWS_HOSTED_ZONE_ID=${AWS_HOSTED_ZONE_ID}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - certs:/letsencrypt
      - ~/.aws:/root/.aws:ro
      - /etc/localtime:/etc/localtime:ro
    <<: *logging
  l2geth-replica:
    labels:
      - traefik.enable=true
      - traefik.http.routers.l2geth.service=l2geth
      - traefik.http.routers.l2geth.entrypoints=websecure
      - traefik.http.routers.l2geth.rule=Host(`${L2GETH_HOST}.${DOMAIN}`)
      - traefik.http.routers.l2geth.tls.certresolver=letsencrypt
      - traefik.http.routers.l2gethlb.service=l2geth
      - traefik.http.routers.l2gethlb.entrypoints=websecure
      - traefik.http.routers.l2gethlb.rule=Host(`${L2GETH_LB}.${DOMAIN}`)
      - traefik.http.routers.l2gethlb.tls.certresolver=letsencrypt
      - traefik.http.services.l2geth.loadbalancer.server.port=8545
      - traefik.http.routers.l2gethws.service=l2gethws
      - traefik.http.routers.l2gethws.entrypoints=websecure
      - traefik.http.routers.l2gethws.rule=Host(`${L2GETH_WS_HOST}.${DOMAIN}`)
      - traefik.http.routers.l2gethws.tls.certresolver=letsencrypt
      - traefik.http.routers.l2gethwslb.service=l2gethws
      - traefik.http.routers.l2gethwslb.entrypoints=websecure
      - traefik.http.routers.l2gethwslb.rule=Host(`${L2GETH_WS_LB}.${DOMAIN}`)
      - traefik.http.routers.l2gethwslb.tls.certresolver=letsencrypt
      - traefik.http.services.l2gethws.loadbalancer.server.port=8546
  replica-healthcheck:
    labels:
      - traefik.enable=true
      - traefik.http.routers.l2gethhealth.service=l2gethhealth
      - traefik.http.routers.l2gethhealth.entrypoints=websecure
      - traefik.http.routers.l2gethhealth.rule=Host(`${L2GETH_HEALTH_HOST}.${DOMAIN}`)
      - traefik.http.routers.l2gethhealth.tls.certresolver=letsencrypt
      - traefik.http.services.l2gethhealth.loadbalancer.server.port=3000
volumes:
  certs:
