From 4a6fe8db586ee9f4baf38e829ee7dc254574bc09 Mon Sep 17 00:00:00 2001 From: busya Date: Thu, 18 Jun 2026 18:37:11 +0300 Subject: [PATCH] fix(version): inject APP_VERSION via Docker build-arg instead of git describe In Docker builds, .git directory is not available in the container, so git describe --tags fails and fallback is '0.0.0'. Now: - build.sh passes --build-arg APP_VERSION=${tag} to frontend build - Dockerfile accepts ARG APP_VERSION and sets ENV - vite.config.js checks process.env.APP_VERSION first, then git describe --- build.sh | 2 +- docker/all-in-one.Dockerfile | 2 ++ docker/frontend.Dockerfile | 2 ++ frontend/vite.config.js | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 91f25de6..12041c19 100755 --- a/build.sh +++ b/build.sh @@ -222,7 +222,7 @@ bundle_release() { docker build -f docker/backend.Dockerfile -t "${backend_tag}" . echo "[bundle] Building frontend image ${frontend_tag}..." - docker build -f docker/frontend.Dockerfile -t "${frontend_tag}" . + docker build --build-arg "APP_VERSION=${tag}" -f docker/frontend.Dockerfile -t "${frontend_tag}" . echo "[bundle] Building agent image ${agent_tag}..." docker build -f docker/Dockerfile.agent -t "${agent_tag}" . diff --git a/docker/all-in-one.Dockerfile b/docker/all-in-one.Dockerfile index 034b7c9a..d8bcf403 100644 --- a/docker/all-in-one.Dockerfile +++ b/docker/all-in-one.Dockerfile @@ -11,6 +11,8 @@ # ── Stage 1: Build Frontend ──────────────────────────────── FROM node:20-alpine AS frontend-builder +ARG APP_VERSION=0.0.0 +ENV APP_VERSION=${APP_VERSION} WORKDIR /app/frontend diff --git a/docker/frontend.Dockerfile b/docker/frontend.Dockerfile index aa6f85d9..7f79b2a9 100644 --- a/docker/frontend.Dockerfile +++ b/docker/frontend.Dockerfile @@ -10,6 +10,8 @@ # #endregion docker.frontend.Dockerfile FROM node:20-alpine AS build +ARG APP_VERSION=0.0.0 +ENV APP_VERSION=${APP_VERSION} WORKDIR /app/frontend COPY frontend/package*.json ./ diff --git a/frontend/vite.config.js b/frontend/vite.config.js index f7704ec3..0324fc2f 100755 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -3,6 +3,11 @@ import { defineConfig } from 'vite'; import { execSync } from 'child_process'; const APP_VERSION = (() => { + // 1. Use APP_VERSION env var (passed via Docker --build-arg or .env) + if (process.env.APP_VERSION && process.env.APP_VERSION !== '0.0.0') { + return process.env.APP_VERSION; + } + // 2. Fall back to latest git tag (works in local dev with .git) try { return execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim(); } catch {