From de120f7d6c2917d5b177da9cadbb00b9c840c4c7 Mon Sep 17 00:00:00 2001 From: Jason Tudisco Date: Wed, 27 May 2026 00:19:12 -0600 Subject: [PATCH] fix(kez-chat/web): pass build sha into Docker build via BUILD_SHA file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The footer was showing "dev" instead of the commit sha because vite runs inside the Docker build context, which doesn't have .git (only kez-chat/ gets copied in, not the parent .git/). git rev-parse failed in the try/catch and fell back to the "dev" sentinel. Fix: vite.config now resolves the sha from, in order: 1. process.env.BUILD_SHA — set by deploy script 2. ./BUILD_SHA file in web/ — set by deploy script 3. git rev-parse --short HEAD — local dev 4. "dev" — give up Deploy script writes the file before rsync; .gitignored so it doesn't accidentally get committed. Co-Authored-By: Claude Opus 4.7 --- kez-chat/web/.gitignore | 3 +++ kez-chat/web/vite.config.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/kez-chat/web/.gitignore b/kez-chat/web/.gitignore index c0e66cc..18f3293 100644 --- a/kez-chat/web/.gitignore +++ b/kez-chat/web/.gitignore @@ -3,3 +3,6 @@ dist/ .vite/ *.tsbuildinfo .DS_Store +# Written by the deploy script so the in-image build can stamp the real +# commit sha into the footer. Falls back to "dev" if missing. +BUILD_SHA diff --git a/kez-chat/web/vite.config.ts b/kez-chat/web/vite.config.ts index 7e9647d..bea44c2 100644 --- a/kez-chat/web/vite.config.ts +++ b/kez-chat/web/vite.config.ts @@ -1,4 +1,5 @@ import { execSync } from "node:child_process"; +import { existsSync, readFileSync } from "node:fs"; import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; import tailwindcss from "@tailwindcss/vite"; @@ -7,7 +8,18 @@ import { VitePWA } from "vite-plugin-pwa"; // Build-time identity: short git SHA + ISO date. Surfaced in the footer // as "kez-chat " so users can eyeball which build they're on (handy // when verifying that a deploy actually landed instead of being cached). +// +// Resolution order, so it works both locally (with .git) and in the +// Docker build on the remote (no .git copied): +// 1. process.env.BUILD_SHA — set by deploy script +// 2. ./BUILD_SHA file in this dir — set by deploy script +// 3. `git rev-parse --short HEAD` — local dev +// 4. "dev" — give up const BUILD_SHA = (() => { + if (process.env.BUILD_SHA) return process.env.BUILD_SHA.trim(); + if (existsSync("./BUILD_SHA")) { + return readFileSync("./BUILD_SHA", "utf-8").trim(); + } try { return execSync("git rev-parse --short HEAD").toString().trim(); } catch {