fix: pass git commit hash to Docker build via build-arg
This commit is contained in:
+3
-5
@@ -4,7 +4,7 @@
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
# Install dependencies
|
||||
RUN apk add --no-cache python3 make g++ git
|
||||
RUN apk add --no-cache python3 make g++
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
@@ -18,15 +18,13 @@ RUN npm ci
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Get git commit hash
|
||||
RUN GIT_COMMIT_HASH=$(git rev-parse --short HEAD) && echo "GIT_COMMIT_HASH=$GIT_COMMIT_HASH" > .env
|
||||
|
||||
# Generate Prisma client (with dummy PostgreSQL DATABASE_URL for build-time generation)
|
||||
# Note: A dummy URL is used since the real database is not available during build
|
||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
|
||||
|
||||
# Build the application (with dummy DATABASE_URL for static page generation and git commit)
|
||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$(git rev-parse --short HEAD) npm run build
|
||||
ARG GIT_COMMIT=unknown
|
||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$GIT_COMMIT npm run build
|
||||
|
||||
# Stage 2: Runner
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
@@ -85,11 +85,11 @@ seed:
|
||||
# Build the Docker image (standard build)
|
||||
docker-build:
|
||||
@echo "Building Docker image {{PROJECT}}:{{IMAGE_TAG}}..."
|
||||
docker build -t {{PROJECT}}:{{IMAGE_TAG}} .
|
||||
docker build --build-arg GIT_COMMIT={{GIT_COMMIT}} -t {{PROJECT}}:{{IMAGE_TAG}} .
|
||||
|
||||
docker-build-commit:
|
||||
@echo "Building Docker image {{PROJECT}}:{{IMAGE_TAG_COMMIT}}..."
|
||||
docker build -t {{PROJECT}}:{{IMAGE_TAG_COMMIT}} .
|
||||
docker build --build-arg GIT_COMMIT={{GIT_COMMIT}} -t {{PROJECT}}:{{IMAGE_TAG_COMMIT}} .
|
||||
|
||||
# Build and tag with both latest and commit hash
|
||||
docker-build-full: docker-build docker-build-commit
|
||||
@@ -99,6 +99,7 @@ docker-build-full: docker-build docker-build-commit
|
||||
docker-rebuild-fast:
|
||||
@echo "Fast rebuilding Docker image {{PROJECT}}:{{IMAGE_TAG}}..."
|
||||
DOCKER_BUILDKIT=1 docker build \
|
||||
--build-arg GIT_COMMIT={{GIT_COMMIT}} \
|
||||
--cache-from={{PROJECT}}:{{IMAGE_TAG}} \
|
||||
-t {{PROJECT}}:{{IMAGE_TAG}} \
|
||||
-t {{PROJECT}}:{{IMAGE_TAG_COMMIT}} \
|
||||
|
||||
Reference in New Issue
Block a user