refactor: derive git info inside Docker instead of --build-arg
All checks were successful
check / check (push) Successful in 45s
All checks were successful
check / check (push) Successful in 45s
- 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.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
.git
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
|
||||
@@ -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
|
||||
|
||||
5
Makefile
5
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..."
|
||||
|
||||
32
build.js
32
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,
|
||||
|
||||
Reference in New Issue
Block a user