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
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
dist
|
dist
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# node:22-slim (22.x LTS), 2026-02-24
|
# node:22-slim (22.x LTS), 2026-02-24
|
||||||
FROM node@sha256:5373f1906319b3a1f291da5d102f4ce5c77ccbe29eb637f072b6c7b70443fc36
|
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
|
RUN corepack enable && corepack prepare yarn@1.22.22 --activate
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -11,10 +11,5 @@ RUN yarn install --frozen-lockfile
|
|||||||
|
|
||||||
COPY . .
|
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 check
|
||||||
RUN make build
|
RUN make build
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -33,10 +33,7 @@ dev:
|
|||||||
@yarn run build --watch 2>&1
|
@yarn run build --watch 2>&1
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
@docker build \
|
@docker build -t autistmask .
|
||||||
--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 .
|
|
||||||
|
|
||||||
hooks:
|
hooks:
|
||||||
@echo "Installing pre-commit hook..."
|
@echo "Installing pre-commit hook..."
|
||||||
|
|||||||
8
build.js
8
build.js
@@ -15,8 +15,7 @@ function getBuildInfo() {
|
|||||||
const pkg = JSON.parse(
|
const pkg = JSON.parse(
|
||||||
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
|
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
|
||||||
);
|
);
|
||||||
let commitHash = process.env.GIT_COMMIT_SHORT || "unknown";
|
let commitHash = "unknown";
|
||||||
if (commitHash === "unknown") {
|
|
||||||
try {
|
try {
|
||||||
commitHash = execSync("git rev-parse --short HEAD", {
|
commitHash = execSync("git rev-parse --short HEAD", {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
@@ -24,9 +23,7 @@ function getBuildInfo() {
|
|||||||
} catch (_) {
|
} catch (_) {
|
||||||
// not a git repo or git not available
|
// not a git repo or git not available
|
||||||
}
|
}
|
||||||
}
|
let commitHashFull = "unknown";
|
||||||
let commitHashFull = process.env.GIT_COMMIT_FULL || "unknown";
|
|
||||||
if (commitHashFull === "unknown") {
|
|
||||||
try {
|
try {
|
||||||
commitHashFull = execSync("git rev-parse HEAD", {
|
commitHashFull = execSync("git rev-parse HEAD", {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
@@ -34,7 +31,6 @@ function getBuildInfo() {
|
|||||||
} catch (_) {
|
} catch (_) {
|
||||||
// not a git repo or git not available
|
// not a git repo or git not available
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
version: pkg.version,
|
version: pkg.version,
|
||||||
license: pkg.license,
|
license: pkg.license,
|
||||||
|
|||||||
Reference in New Issue
Block a user