Dockerfile: fetch the geoip database in its own stage

Downloading inside the SDK stage put apt-get update on every cache miss;
observed as a >12-minute stall on the first build. A static curl image
removes apt entirely from this step and the download itself takes ~2s.

Also pins DBIP_VERSION to 2026-09: the 2026-04 file is gone from the
DB-IP CDN (404), which failed the build.
This commit is contained in:
Pavlo Ratushnyi
2026-10-01 09:49:32 +02:00
parent 565da4fab5
commit 3cede3c302
+13 -7
View File
@@ -51,12 +51,18 @@ RUN mkdir -p /publish/data /publish/geoip
# DBIP_VERSION is pinned, which means the database ages with the image. /healthz
# reports the loaded database's build date so a stale one is visible at runtime,
# not only at build time; bump this argument in CI on a schedule.
ARG DBIP_VERSION=2026-04
RUN apt-get update -qq && apt-get install -qq -y curl gzip > /dev/null && \
mkdir -p /publish/geoip && \
curl -fsSL "https://download.db-ip.com/free/dbip-city-lite-${DBIP_VERSION}.mmdb.gz" \
| gunzip > /publish/geoip/GeoLite2-Country.mmdb && \
ls -la /publish/geoip/GeoLite2-Country.mmdb
ARG DBIP_VERSION=2026-09
# Downloaded in its own stage with a static curl image: doing it in the SDK
# stage means apt-get update on every cache miss, and that is the slowest and
# least reproducible part of the build (observed: it stalls, the download
# itself takes two seconds). gunzip is part of curlimages/curl's busybox.
FROM curlimages/curl:8.10.1 AS geoip
ARG DBIP_VERSION
RUN mkdir -p /geoip && \
curl --fail --silent --show-error --location --retry 3 --retry-delay 2 \
"https://download.db-ip.com/free/dbip-city-lite-${DBIP_VERSION}.mmdb.gz" \
| gunzip > /geoip/GeoLite2-Country.mmdb && \
ls -la /geoip/GeoLite2-Country.mmdb
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-noble-chiseled AS runtime
@@ -64,7 +70,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}-noble-chiseled AS runtime
WORKDIR /app/api
COPY --from=build --chown=app:app /publish/api /app/api
COPY --from=build --chown=app:app /publish/data /app/data
COPY --from=build --chown=app:app /publish/geoip /app/geoip
COPY --from=geoip --chown=app:app /geoip /app/geoip
USER app:app