From ce413cf6bc9c60d271417d0ab00be60e58f9cdc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Tue, 25 Nov 2025 09:41:50 +0100 Subject: [PATCH] feat: Implement Docker version reporting by extracting git tag to an environment variable for API consumption. --- Dockerfile | 10 ++++++++++ app/api/version/route.ts | 5 +++++ scripts/docker-entrypoint.sh | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/Dockerfile b/Dockerfile index f84a1c5..e90cfe2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,16 @@ RUN npm ci # Rebuild the source code only when needed FROM base AS builder WORKDIR /app + +# Install git to extract version information +RUN apk add --no-cache git + COPY --from=deps /app/node_modules ./node_modules COPY . . +# Extract version from git +RUN git describe --tags --always 2>/dev/null > /tmp/version.txt || echo "unknown" > /tmp/version.txt + # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry during the build. @@ -53,6 +60,9 @@ COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules # Create uploads directory and set permissions RUN mkdir -p public/uploads/covers && chown -R nextjs:nodejs public/uploads +# Copy version file from builder +COPY --from=builder /tmp/version.txt /app/version.txt + USER nextjs EXPOSE 3000 diff --git a/app/api/version/route.ts b/app/api/version/route.ts index e96baa4..2f39f9b 100644 --- a/app/api/version/route.ts +++ b/app/api/version/route.ts @@ -3,6 +3,11 @@ import { execSync } from 'child_process'; export async function GET() { try { + // First check if version is set via environment variable (Docker build) + if (process.env.APP_VERSION) { + return NextResponse.json({ version: process.env.APP_VERSION }); + } + // Try to get the git tag/version let version = 'dev'; diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 6c45d9f..fc2e0d9 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -1,6 +1,12 @@ #!/bin/sh set -e +# Export version if available +if [ -f /app/version.txt ]; then + export APP_VERSION=$(cat /app/version.txt) + echo "App version: $APP_VERSION" +fi + echo "Starting deployment..." # Run migrations