Something went wrong. Try again.
Simple forward/reverse geocoder for WhosOnFirst admin data
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859# Waldo, self-contained: the binary, a prebuilt world database and the DuckDB extensions it needs,# so the container starts in about a second, in ~250 MB, with no network access at startup.## make image (or: podman build --platform linux/amd64 --build-arg WOF_VERSION=<date> -t waldo .)## WOF_VERSION only busts the cache of the download stage: bump it (make image sets it to the data's# Last-Modified date) to fetch new WhosOnFirst data. A code change rebuilds the database from the# cached download.
ARG GO_VERSION=1.26
# 1. Compile. duckdb-go links DuckDB statically through cgo.FROM --platform=linux/amd64 golang:${GO_VERSION}-bookworm AS buildRUN apt-get update && apt-get install -y --no-install-recommends g++ && rm -rf /var/lib/apt/lists/*WORKDIR /srcCOPY go.mod go.sum ./RUN go mod downloadCOPY . .RUN CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o /out/waldo ./cmd/waldo
# 2. Download the world. A stage of its own, independent of the code, so a code change doesn't# fetch 5.9 GB again: only a new WOF_VERSION does. HTTP/1.1 (long HTTP/2 transfers from the WOF# host can break mid-stream), retrying on any error and resuming where a broken transfer stopped.FROM --platform=linux/amd64 golang:${GO_VERSION}-bookworm AS downloadARG WOF_URL=https://data.geocode.earth/wof/dist/parquet/whosonfirst-data-admin-latest.parquetARG WOF_VERSION=unknownRUN mkdir -p /wof \ && echo "WhosOnFirst ${WOF_VERSION}" \ && for i in 1 2 3 4 5; do \ curl -fSL --http1.1 --retry 5 --retry-all-errors --retry-delay 5 -C - -o /wof/world.parquet "$WOF_URL" -s -S && break; \ echo "download interrupted, resuming ($i)"; sleep 5; \ done \ && test -s /wof/world.parquet \ && echo "${WOF_VERSION}" > /wof/VERSION
# 3. Build the database with this code's loader. The parquet is mounted, not copied, so it never# becomes a layer. HOME is the runtime user's, so `waldo build` installs the spatial and h3# extensions where the runtime image looks for them.FROM build AS dataENV HOME=/home/nonrootRUN --mount=type=bind,from=download,source=/wof,target=/wof \ mkdir -p /data "$HOME" \ && /out/waldo build /wof/world.parquet /data/waldo.duckdb \ && cp /wof/VERSION /data/VERSION
# 4. Run. distroless/cc has glibc and libstdc++, which DuckDB needs, and nothing else.FROM --platform=linux/amd64 gcr.io/distroless/cc-debian12:nonrootARG WOF_VERSION=unknownLABEL org.opencontainers.image.title="waldo" \ org.opencontainers.image.description="Waldo geocoder with a prebuilt WhosOnFirst admin database" \ org.opencontainers.image.version="${WOF_VERSION}"COPY --from=build /out/waldo /usr/local/bin/waldoCOPY --from=data --chown=nonroot:nonroot /home/nonroot/.duckdb /home/nonroot/.duckdbCOPY --from=data --chown=nonroot:nonroot /data/waldo.duckdb /data/VERSION /data/ENV HOME=/home/nonrootEXPOSE 8999ENTRYPOINT ["/usr/local/bin/waldo"]CMD ["serve", "-port", "8999", "/data/waldo.duckdb"]