From 5d0ad18e3fea191e91dc4bc02a5323ed22adcc78 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 1 Mar 2026 13:05:55 -0800 Subject: [PATCH] refactor: derive git info inside Docker instead of --build-arg - Remove .git from .dockerignore so it's available in Docker build context - Install git in Docker image (apt-get) - Remove ARG/ENV GIT_COMMIT_SHORT/FULL from Dockerfile - Remove --build-arg from Makefile docker target - Simplify build.js to use git CLI directly (no env var indirection) build.js already had fallback logic to shell out to git; now that .git is present in the build context, it works directly without needing values passed in from outside Docker. --- .dockerignore | 1 - Dockerfile | 7 +------ Makefile | 5 +---- build.js | 32 ++++++++++++++------------------ 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/.dockerignore b/.dockerignore index 7452cbb..da592f8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -.git node_modules .DS_Store dist diff --git a/Dockerfile b/Dockerfile index b2cf0b6..bb7d041 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # node:22-slim (22.x LTS), 2026-02-24 FROM node@sha256:5373f1906319b3a1f291da5d102f4ce5c77ccbe29eb637f072b6c7b70443fc36 -RUN apt-get update && apt-get install -y --no-install-recommends make && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y --no-install-recommends make git && rm -rf /var/lib/apt/lists/* RUN corepack enable && corepack prepare yarn@1.22.22 --activate WORKDIR /app @@ -11,10 +11,5 @@ RUN yarn install --frozen-lockfile COPY . . -ARG GIT_COMMIT_SHORT=unknown -ARG GIT_COMMIT_FULL=unknown -ENV GIT_COMMIT_SHORT=${GIT_COMMIT_SHORT} -ENV GIT_COMMIT_FULL=${GIT_COMMIT_FULL} - RUN make check RUN make build diff --git a/Makefile b/Makefile index 4d596a1..ff9ffe8 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,7 @@ dev: @yarn run build --watch 2>&1 docker: - @docker build \ - --build-arg GIT_COMMIT_SHORT=$$(git rev-parse --short HEAD 2>/dev/null || echo unknown) \ - --build-arg GIT_COMMIT_FULL=$$(git rev-parse HEAD 2>/dev/null || echo unknown) \ - -t autistmask . + @docker build -t autistmask . hooks: @echo "Installing pre-commit hook..." diff --git a/build.js b/build.js index 4fd43d3..54c1179 100644 --- a/build.js +++ b/build.js @@ -15,25 +15,21 @@ function getBuildInfo() { const pkg = JSON.parse( fs.readFileSync(path.join(__dirname, "package.json"), "utf8"), ); - let commitHash = process.env.GIT_COMMIT_SHORT || "unknown"; - if (commitHash === "unknown") { - try { - commitHash = execSync("git rev-parse --short HEAD", { - encoding: "utf8", - }).trim(); - } catch (_) { - // not a git repo or git not available - } + let commitHash = "unknown"; + try { + commitHash = execSync("git rev-parse --short HEAD", { + encoding: "utf8", + }).trim(); + } catch (_) { + // not a git repo or git not available } - let commitHashFull = process.env.GIT_COMMIT_FULL || "unknown"; - if (commitHashFull === "unknown") { - try { - commitHashFull = execSync("git rev-parse HEAD", { - encoding: "utf8", - }).trim(); - } catch (_) { - // not a git repo or git not available - } + let commitHashFull = "unknown"; + try { + commitHashFull = execSync("git rev-parse HEAD", { + encoding: "utf8", + }).trim(); + } catch (_) { + // not a git repo or git not available } return { version: pkg.version,