name: proxy-v0.0.1

services:
  proxy:
    image: caddy:2
    restart: always
    command: ["caddy", "run", "--config", "/etc/caddy/caddy.json", "--resume"]
    ports: ["80:80", "443:443", "2019:2019"]
    labels:
      logging.service: proxy
    configs:
      - source: caddy_config
        target: /etc/caddy/caddy.json
    volumes:
      - caddy_data:/data
    networks: [edge]
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:2019/config/"]
      interval: 10s
      timeout: 3s
      retries: 5
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "5"

volumes:
  caddy_data:

networks:
  edge:
    name: edge
    driver: bridge

configs:
  caddy_config:
    content: |
      {
          "admin": { "listen": ":2019" },
          "apps": {
            "http": {
              "servers": {
                "srv0": {
                  "listen": [":80"],
                  "routes": [
                    {
                      "match": [{ "path": ["/healthz"] }],
                      "handle": [{ "handler": "static_response", "body": "ok" }]
                    },
                    {
                      "handle": [
                        {
                          "handler": "reverse_proxy",
                          "upstreams": [{ "dial": "nonexistant:8080" }]
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
      }
