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
This commit is contained in:
2
build.sh
2
build.sh
@@ -222,7 +222,7 @@ bundle_release() {
|
|||||||
docker build -f docker/backend.Dockerfile -t "${backend_tag}" .
|
docker build -f docker/backend.Dockerfile -t "${backend_tag}" .
|
||||||
|
|
||||||
echo "[bundle] Building frontend image ${frontend_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}..."
|
echo "[bundle] Building agent image ${agent_tag}..."
|
||||||
docker build -f docker/Dockerfile.agent -t "${agent_tag}" .
|
docker build -f docker/Dockerfile.agent -t "${agent_tag}" .
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
# ── Stage 1: Build Frontend ────────────────────────────────
|
# ── Stage 1: Build Frontend ────────────────────────────────
|
||||||
FROM node:20-alpine AS frontend-builder
|
FROM node:20-alpine AS frontend-builder
|
||||||
|
ARG APP_VERSION=0.0.0
|
||||||
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
|
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
# #endregion docker.frontend.Dockerfile
|
# #endregion docker.frontend.Dockerfile
|
||||||
|
|
||||||
FROM node:20-alpine AS build
|
FROM node:20-alpine AS build
|
||||||
|
ARG APP_VERSION=0.0.0
|
||||||
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import { defineConfig } from 'vite';
|
|||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
const APP_VERSION = (() => {
|
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 {
|
try {
|
||||||
return execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim();
|
return execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user