Fix upstream build: swap Docker Hardened Images (dhi.io) for public node bases

Onyx's web Dockerfile now bases on Docker Hardened Images (dhi.io/node:24-debian13*),
which require a paid DHI subscription + `docker login dhi.io` — so `make build` fails
with a registry-login error for anyone without DHI access.

The apply overlay now rewrites those two FROM lines to the equivalent PUBLIC Docker
Hub node images (24-trixie / 24-trixie-slim, Debian 13 / glibc to match the DHI variant
the Dockerfile targets) and sets the runtime to the non-root `node` user, matching
upstream's posture — no docker login needed.

- branding.config.json: new build.baseImageReplacements map (config-driven)
- apply-branding.mjs: step 1b swaps DHI FROM lines (digest-stripped) + adds USER node;
  idempotent, no-op with a warning if the DHI bases are absent (safe across upstream changes)
- README: upgrade note #3 documenting the swap

Verified end-to-end: full web image builds on the public bases (no login), serves 200,
and runs correctly as the non-root node user.
This commit is contained in:
NaeemDosh 2026-07-04 02:39:43 +05:00 • committed by Naeem Dosh
parent 7a618d4a74
commit bbfbad2ca7
3 changed files with 61 additions and 1 deletions

View file

@ -177,12 +177,19 @@ make verify
```
Pin **`IMAGE_TAG`** in `.env` to the **same** release so the official backend/model
images match the web build you're compiling. Two things to watch after an upgrade:
images match the web build you're compiling. Three things to watch after an upgrade:
1. **Logo component paths** — if upstream moves the logo files, `make apply` prints a
`logo target missing` warning. Update the paths in `apply-branding.mjs → logoInstalls`.
2. **New unbranded strings** — if upstream adds new "Onyx" copy, the global word rule
catches it automatically; review `make verify` output and the apply summary.
3. **Base image / Docker Hardened Images** — Onyx's web `Dockerfile` bases on DHI
(`dhi.io/node:*`), which needs a paid Docker subscription + `docker login dhi.io`, so
`make build` fails with a registry-login error without it. `make apply` automatically
rewrites those `FROM` lines to the equivalent **public** Docker Hub `node` images and
sets the runtime to the non-root `node` user — no login required. If a future upstream
change renames the base and `make apply` warns *"no dhi.io base images ... nothing to
swap"*, update `branding.config.json → build.baseImageReplacements`.
---

View file

@ -91,6 +91,51 @@ if (existsSync(favSrc) && !DRY) {
ok("favicon: overwrote public/onyx.ico with branded icon");
}
// ── 1b. Dockerfile base images ──────────────────────────────────────────────
// Onyx's web Dockerfile bases on Docker Hardened Images (dhi.io/node:*), which need
// a paid DHI subscription + `docker login dhi.io`, so `make build` fails with a
// registry-login error for anyone without DHI access. Swap those FROM lines for the
// equivalent public Docker Hub node images (config → build.baseImageReplacements).
// No-op with a warning if the DHI bases are absent, so it stays safe if upstream
// reverts or renames — same maintenance model as the logo/notification patches.
step("1b Dockerfile base images");
{
const dfPath = path.join(WEB, "Dockerfile");
const repl = (CONFIG.build && CONFIG.build.baseImageReplacements) || {};
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
if (!existsSync(dfPath)) {
warn("Dockerfile not found — skipping base-image swap");
} else {
let df = await readFile(dfPath, "utf8");
let swapped = 0;
// Longest keys first so `...-dev` is handled before its `...debian13` prefix.
for (const from of Object.keys(repl).sort((a, b) => b.length - a.length)) {
// Only rewrite actual `FROM` lines; drop any pinned @sha256 digest since it
// won't match the public image.
const re = new RegExp("^(FROM\\s+)" + esc(from) + "(@sha256:[a-f0-9]+)?", "gm");
df = df.replace(re, (_m, p1) => { swapped++; return p1 + repl[from]; });
}
// The DHI runtime ran as the non-root `node` user (uid 1000); the public
// slim image defaults to root. Restore non-root by setting USER before the
// runtime CMD (idempotent). Only when we actually swapped to a public base.
let hardened = false;
if (swapped > 0 && !/^USER\s+node\b/m.test(df)) {
const cmdRe = /^CMD \["node", "server\.js"\]/m;
if (cmdRe.test(df)) {
df = df.replace(cmdRe, 'USER node\nCMD ["node", "server.js"]');
hardened = true;
}
}
if (swapped > 0) {
if (!DRY) await writeFile(dfPath, df);
ok(`swapped ${swapped} DHI base image(s) → public Docker Hub node (no docker login needed)` +
(hardened ? "; set runtime USER node (non-root)" : ""));
} else {
warn("no dhi.io base images in Dockerfile (already public / upstream changed) — nothing to swap");
}
}
}
// ── 2. Logo components ──────────────────────────────────────────────────────
step("2/4 Logo components");
const MARK_SRC = "/" + CONFIG.assets.mark.dest;

View file

@ -15,6 +15,14 @@
"webSrcRoot": "web"
},
"build": {
"$comment": "As of 2026-07, Onyx's web Dockerfile bases on Docker Hardened Images (dhi.io/node:*), a paid Docker offering that requires a DHI subscription + `docker login dhi.io` — so `make build` fails with a registry login error for anyone without DHI access. The apply step rewrites those FROM lines to the equivalent PUBLIC Docker Hub node images (Debian 13 / glibc, matching the DHI variant the Dockerfile targets), so the branded image builds with no login. Keys = the dhi.io image ref (the trailing @sha256 digest, if any, is stripped automatically); values = the public replacement. No-op (with a warning) if the DHI lines are absent, so this stays safe across upstream changes.",
"baseImageReplacements": {
"dhi.io/node:24-debian13-dev": "docker.io/library/node:24-trixie",
"dhi.io/node:24-debian13": "docker.io/library/node:24-trixie-slim"
}
},
"assets": {
"$comment": "Remote source URLs are fetched at apply time into onyx/web/public/branding/. If a fetch fails (e.g. offline), the apply script keeps any existing committed file in branding/assets/ as a fallback.",
"mark": {