version: '3.1'

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: always
    ports:
      - "443:443"
      - "127.0.0.1:8080:8080"
    expose:
      - "8082"
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--api.dashboard=true"
      - "--log.level=DEBUG"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.websecure.address=:443"
      - "--entryPoints.metrics.address=:8082"
      - "--metrics.prometheus.entryPoint=metrics"
      - "--certificatesresolvers.myresolver.acme.tlschallenge=true"
      # TESTING
      # - "--certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
      - "--certificatesresolvers.myresolver.acme.email=$MAIL"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    volumes:
      - "./traefik/letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    labels:
      - "traefik.enable=true"

  haproxy:
    build: haproxy
    volumes:
      - ./haproxy:/usr/local/etc/haproxy
    expose:
      - "8404"
      - "80"
    ports:
      - "127.0.0.1:80:80"
    restart: always
    labels:
      - "prometheus-scrape.enabled=true"
      - "prometheus-scrape.port=8404"
      - "prometheus-scrape.job_name=haproxy"
      - "prometheus-scrape.metrics_path=/metrics"

  pocket:    
    build: pokt
    ports:
      - "127.0.0.1:8081:8081"
      - "26657:26656"
    expose:
      - 26656
      - 26660
      - 8081
      - 8083
    environment:
      - POCKET_CORE_KEY=$POCKET_CORE_KEY
      - POCKET_CORE_PASSPHRASE=$POCKET_CORE_PASSPHRASE
      - POCKET_SNAPSHOT=$POCKET_SNAPSHOT
    volumes:
      - pocket:/home/app/.pocket/data
      - pocket-addrbook:/home/app/.pocket/addrbook
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.pocket.loadbalancer.server.port=8081"
      - "traefik.http.routers.pocket.entrypoints=websecure"
      - "traefik.http.routers.pocket.tls.certresolver=myresolver"
      - "traefik.http.routers.pocket.rule=Host(`$DOMAIN`) && Path(`/v1`, `/v1/client/{dispatch|relay|challenge|sim}`)"
      - "prometheus-scrape.enabled=true"
      - "prometheus-scrape.port=8083"
      - "prometheus-scrape.job_name=pocket"

### VOLUMES
volumes:
  pocket:
  pocket-addrbook: