version: '3.1'

services:

  traefik:
    image: traefik:latest
    container_name: traefik
    restart: always
    ports:
      - "443:443"
      - "127.0.0.1:8080:8080"
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--api.dashboard=true"
      - "--log.level=DEBUG"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.websecure.address=:443"
      - "--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"

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

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

### MONITORING
### WIREGUARD
  wireguard:
    image: lscr.io/linuxserver/wireguard
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=$PUID
      - PGID=$PGID
    volumes:
      - ./wireguard/config/wg0.conf:/config/wg0.conf
      - /lib/modules:/lib/modules
    # Expose prometheus port
    expose:
      - 9090
    ports:
      - $SERVERPORT:$SERVERPORT/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

  prometheus:
    image: prom/prometheus:v2.30.3
    container_name: prometheus
    volumes:
      - ./prometheus:/etc/prometheus
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped
    network_mode: "service:wireguard"
    labels:
      org.label-schema.group: "monitoring"
    depends_on:
      - wireguard

  nodeexporter:
    image: prom/node-exporter:v1.2.2
    container_name: nodeexporter
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
    restart: unless-stopped
    expose:
      - 9100
    labels:
      org.label-schema.group: "monitoring"

  cadvisor:
    image: gcr.io/cadvisor/cadvisor:v0.42.0
    container_name: cadvisor
    privileged: true
    devices:
      - /dev/kmsg:/dev/kmsg
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker:/var/lib/docker:ro
      #- /cgroup:/cgroup:ro #doesn't work on MacOS only for Linux
    restart: unless-stopped
    expose:
      - 8080
    labels:
      org.label-schema.group: "monitoring"

### VOLUMES
volumes:
  pocket-testnet:
  pocket-mainnet:
  pocket-mainnet-config:
  prometheus_data:

