diff --git a/website/Dockerfile b/website/Dockerfile index 6c209d2..c6ab7f8 100644 --- a/website/Dockerfile +++ b/website/Dockerfile @@ -15,10 +15,10 @@ COPY --from=build /src/target/release/chesspenguin-site /usr/local/bin/ COPY site ./site COPY static ./static COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh -RUN mkdir -p /app/data && chown site /app/data -USER site +RUN mkdir -p /app/data +# Starts as root only to take ownership of the mounted data/, then runs as "site". ENV PORT=8080 STATIC_DIR=/app/static SITE_DIR=/app/site DB_PATH=/app/data/downloads.sqlite \ GEOIP_DB=/app/data/dbip-city-ipv4.mmdb,/app/data/dbip-city-ipv6.mmdb EXPOSE 8080 -HEALTHCHECK --interval=60s --timeout=5s CMD curl -fsS http://127.0.0.1:8080/healthz || exit 1 +HEALTHCHECK --interval=60s --timeout=5s --start-period=10m CMD curl -fsS http://127.0.0.1:8080/healthz || exit 1 ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/website/docker/entrypoint.sh b/website/docker/entrypoint.sh index f76ced7..31b2c35 100755 --- a/website/docker/entrypoint.sh +++ b/website/docker/entrypoint.sh @@ -1,8 +1,14 @@ #!/bin/sh # Fetches the DB-IP Lite City geolocation databases (CC BY 4.0, MaxMind DB format, via the # ip-location-db package on unpkg) when they are missing or older than 35 days, then -# starts the server. Without them the site works and downloads are stored without a country. +# starts the server as the unprivileged user "site". Without them the site works and +# downloads are stored without a country. set -u +# A bind-mounted ./data is created by Docker as root: hand it to "site". +if [ "$(id -u)" = 0 ]; then + chown -R site /app/data + exec setpriv --reuid=site --regid=site --init-groups "$0" "$@" +fi base="${GEOIP_URL:-https://unpkg.com/@ip-location-db/dbip-city-mmdb}" for v in ipv4 ipv6; do f="/app/data/dbip-city-${v}.mmdb"