Skip to content

build(smg): ship the DB-IP City Lite database in the Cap Web image - #22

Merged
hjescalona merged 1 commit into
smgfrom
internal/geoip-database
Nov 13, 2026
Merged

hjescalona merged 1 commit into
smgfrom
internal/geoip-database

Conversation

@hjescalona

Copy link
Copy Markdown

Why

#21 lets Cap Web look up view locations in a GeoIP .mmdb file. This puts that file in our image.

What

  • scripts/smg/lib/railway-dockerfile.ts: smgWebDockerfile() = railwayDockerfile() + withGeoIpDatabase(), which adds a geoip stage before runner:
    • Downloads DB-IP City Lite for the current month (dbip-city-lite-YYYY-MM.mmdb.gz), falling back to the previous month at the start of a month. ~60 MB download, 127 MB on disk.
    • ARG RAILWAY_GIT_COMMIT_SHA busts the build cache, so every deploy takes the latest monthly file instead of a cached one.
    • A failed download prints a warning in the build log and doesn't fail the build; views just keep no location until the next deploy.
  • The runner copies it to /app/geoip and sets CAP_GEOIP_DATABASE_PATH.
  • The generator throws if upstream's Dockerfile loses one of the two anchors (FROM base AS runner, USER nextjs), so a sync can't silently drop the stage.
  • smg/web.Dockerfile regenerated. SMG.md: ledger row for feat/self-hosted-geoip and a note with the data source and its CC BY 4.0 attribution.

Merge order doesn't matter: without #21 the variable is ignored, and without this PR #21 changes nothing.

Verified

  • bun test scripts/smg: 37 pass, including the new withGeoIpDatabase tests and the up-to-date check.
  • docker build --target geoip with the generated Dockerfile: downloads the 2026-11 file (GeoIP: DB-IP City Lite 2026-11 (commit test123)).
  • The 2026-10 and 2026-11 URLs both answer 200; busybox date computes the previous month in node:24.22.1-alpine.

Railway sends no location headers, so views need a GeoIP database to get a
country and city. The Railway Dockerfile generator now adds a geoip stage
that downloads the current month's DB-IP City Lite file (falling back to the
previous month) and sets CAP_GEOIP_DATABASE_PATH. RAILWAY_GIT_COMMIT_SHA
busts the build cache so every deploy takes the latest file. A failed
download leaves views without a location instead of failing the build.
@hjescalona
hjescalona merged commit 6136cb9 into smg Nov 13, 2026
6 checks passed
@hjescalona
hjescalona deleted the internal/geoip-database branch November 13, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant