diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..75cdd43 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,17 @@ +{ + # to use handle_path for prefixes, pmtiles_proxy must have a defined + # position in the ordering of handlers. + order pmtiles_proxy before reverse_proxy + email ${MAPS_EMAIL} +} + +${MAPS_DOMAIN} { + handle_path /tiles/* { + pmtiles_proxy { + bucket ${MAPS_PMTILES_LOCATION} + cache_size 19000 + # used to embed a tiles URL in TileJSON. + public_url https://${MAPS_DOMAIN}/tiles + } + } +} diff --git a/Dockerfile b/Dockerfile index 5205705..bd19832 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,13 @@ RUN xcaddy build --with github.com/caddy-dns/cloudflare --with github.com/protom FROM caddy:2.8.4 +# Install envsubst +RUN apk update && apk add gettext && rm -rf /var/cache/apk/* + COPY --from=builder /usr/bin/caddy /usr/bin/caddy +COPY Caddyfile /etc/caddy/Caddyfile.template +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..495a5fe --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +# Debug: print environment variables +echo "Environment variables:" +echo "MAPS_DOMAIN=${MAPS_DOMAIN}" +echo "MAPS_PMTILES_LOCATION=${MAPS_PMTILES_LOCATION}" +echo "MAPS_EMAIL=${MAPS_EMAIL}" + +# Replace environment variables in Caddyfile +export MAPS_DOMAIN +export MAPS_PMTILES_LOCATION +export MAPS_EMAIL +envsubst '${MAPS_DOMAIN} ${MAPS_PMTILES_LOCATION} ${MAPS_EMAIL}' < /etc/caddy/Caddyfile.template > /etc/caddy/Caddyfile + +echo "Caddyfile:" +cat /etc/caddy/Caddyfile + +# Execute Caddy +exec /usr/bin/caddy run --config /etc/caddy/Caddyfile