From 891f52b0b8b56bc82b5d39699a0d01efa128e0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Mon, 1 Dec 2025 17:43:24 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Versionsanzeige=20im=20Footer=20-=20Git-?= =?UTF-8?q?Tags=20w=C3=A4hrend=20Docker-Build=20verf=C3=BCgbar=20machen=20?= =?UTF-8?q?und=20Fallbacks=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 6 +++--- Dockerfile | 6 ++++-- app/api/version/route.ts | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 3c8b2bc..75eb186 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,9 +14,9 @@ build .env.local .env*.local -# Git -.git -.gitignore +# Git (NICHT ausschließen - wird für Version-Extraktion benötigt!) +# .git wird benötigt für: git describe --tags --always +# .gitignore # IDE .vscode diff --git a/Dockerfile b/Dockerfile index 1210498..fe767d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,11 +23,13 @@ RUN apk add --no-cache git COPY --from=deps /app/node_modules ./node_modules COPY . . -# Extract version: use build arg if provided, otherwise get from git +# Extract version: use build arg if provided, otherwise get from git, fallback to package.json RUN if [ -n "$APP_VERSION" ]; then \ echo "$APP_VERSION" > /tmp/version.txt; \ else \ - git describe --tags --always 2>/dev/null > /tmp/version.txt || echo "unknown" > /tmp/version.txt; \ + (git describe --tags --always 2>/dev/null || \ + (grep -o '"version": "[^"]*"' package.json 2>/dev/null | cut -d'"' -f4 | sed 's/^/v/') || \ + echo "dev") > /tmp/version.txt; \ fi && \ echo "Building version: $(cat /tmp/version.txt)" diff --git a/app/api/version/route.ts b/app/api/version/route.ts index 3c7c710..0b4b00d 100644 --- a/app/api/version/route.ts +++ b/app/api/version/route.ts @@ -15,7 +15,7 @@ export async function GET() { for (const versionFilePath of versionPaths) { if (existsSync(versionFilePath)) { const version = readFileSync(versionFilePath, 'utf-8').trim(); - if (version && version !== 'unknown') { + if (version && version !== 'unknown' && version !== '') { return NextResponse.json({ version }); } } @@ -26,6 +26,19 @@ export async function GET() { return NextResponse.json({ version: process.env.APP_VERSION }); } + // Fallback: check package.json + try { + const packageJsonPath = join(process.cwd(), 'package.json'); + if (existsSync(packageJsonPath)) { + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); + if (packageJson.version) { + return NextResponse.json({ version: `v${packageJson.version}` }); + } + } + } catch { + // Ignore package.json read errors + } + // Fallback: try to get from git (local development) let version = 'dev';