services:

  # By default, Kong is used as the API gateway and its ports/env are reset
  # below so Caddy can terminate TLS in front of it.
  #
  # When running Envoy instead, e.g.:
  #   docker compose -f docker-compose.yml -f docker-compose.envoy.yml \
  #                  -f docker-compose.caddy.yml up -d
  # comment out the `kong:` block below and uncomment the `api-gw:` block
  # (and the matching `depends_on` entry further down) so Caddy sits in front
  # of Envoy rather than Kong.

  #api-gw:
  #  ports: !reset []

  kong:
    ports: !reset []
    environment:
      KONG_PORT_MAPS: "443:8000,443:8443"

  caddy:
    container_name: briven-caddy
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    depends_on:
      #api-gw:
      #  condition: service_healthy
      kong:
        condition: service_healthy
      studio:
        condition: service_healthy
    environment:
      PROXY_DOMAIN: ${PROXY_DOMAIN}
      PROXY_AUTH_USERNAME: ${DASHBOARD_USERNAME}
      PROXY_AUTH_PASSWORD: ${DASHBOARD_PASSWORD}
    command:
      - /bin/sh
      - -c
      - |
        PROXY_AUTH_PASSWORD=$$(caddy hash-password --plaintext "$$PROXY_AUTH_PASSWORD") && \
        caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
    volumes:
      - ./volumes/proxy/caddy:/etc/caddy
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
  caddy_config:
