fix(kez-chat/web): pass build sha into Docker build via BUILD_SHA file
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 <noreply@anthropic.com>
This commit is contained in:
parent
76fcaa1d3c
commit
de120f7d6c
3
kez-chat/web/.gitignore
vendored
3
kez-chat/web/.gitignore
vendored
@ -3,3 +3,6 @@ dist/
|
|||||||
.vite/
|
.vite/
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
.DS_Store
|
.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
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { execSync } from "node:child_process";
|
import { execSync } from "node:child_process";
|
||||||
|
import { existsSync, readFileSync } from "node:fs";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
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
|
// Build-time identity: short git SHA + ISO date. Surfaced in the footer
|
||||||
// as "kez-chat <sha>" so users can eyeball which build they're on (handy
|
// as "kez-chat <sha>" so users can eyeball which build they're on (handy
|
||||||
// when verifying that a deploy actually landed instead of being cached).
|
// 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 = (() => {
|
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 {
|
try {
|
||||||
return execSync("git rev-parse --short HEAD").toString().trim();
|
return execSync("git rev-parse --short HEAD").toString().trim();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user