From bbfbad2ca77da0f3f172f7d2c9d2e649bf6f8e29 Mon Sep 17 00:00:00 2001 From: NaeemDosh Date: Sat, 4 Jul 2026 02:39:43 +0500 Subject: [PATCH] Fix upstream build: swap Docker Hardened Images (dhi.io) for public node bases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- README.md | 9 ++++++- branding/apply-branding.mjs | 45 +++++++++++++++++++++++++++++++++++ branding/branding.config.json | 8 +++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 369b246..8266124 100644 --- a/README.md +++ b/README.md @@ -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`. --- diff --git a/branding/apply-branding.mjs b/branding/apply-branding.mjs index f7edc0f..f68ce5f 100644 --- a/branding/apply-branding.mjs +++ b/branding/apply-branding.mjs @@ -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; diff --git a/branding/branding.config.json b/branding/branding.config.json index c10ffbe..cd92c20 100644 --- a/branding/branding.config.json +++ b/branding/branding.config.json @@ -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": {