Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(build): inject version metadata into compose-built app images (#4123)
DerrickLinus6520c19ffd3b
diff --git a/.env.example b/.env.exampleindex 9d88d1ecb..59f56c4b3 100644--- a/.env.example+++ b/.env.example@@ -36,6 +36,13 @@ WEKNORA_VERSION=latestAPK_MIRROR_ARG=mirrors.tencent.com# 构建 app 镜像时是否链接 anydoc 进程内解析引擎(默认 1)。设 0 可跳过 Rust 工具链、缩短构建时间,引擎在设置页显示为不可用。# WITH_ANYDOC=1+# 从源码构建 app 镜像时注入「系统信息」页的应用版本元数据。start_all.sh --no-pull+# 会从 git 与 VERSION 文件自动填充;直接 docker compose build 时可自行导出,未导出时+# version 回退读源码中的 VERSION 文件,commit / 构建时间 / Go 版本显示 unknown。+# VERSION_ARG=+# COMMIT_ID_ARG=+# BUILD_TIME_ARG=+# GO_VERSION_ARG=# docreader 镜像构建时 apt 镜像源(留空用默认源)。# APT_MIRROR=# docreader 镜像构建时 Playwright 浏览器制品源(留空用官方 CDN)。diff --git a/Makefile b/Makefileindex 69c328ad9..286bf2d2e 100644--- a/Makefile+++ b/Makefile@@ -281,8 +281,10 @@ deps:# google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn for qdrant milvus proto conflict# GO_BUILD_TAGS adds optional build tags, e.g. GO_BUILD_TAGS=anydoc to link the# in-process office document parser (run `make anydoc-lib` first).+# When .git is absent (e.g. inside a docker build), fall back to the VERSION+# file so compose-built images still report the base version.build-prod:- VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "$${VERSION:-unknown}"); \+ VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "$${VERSION:-$$(cat VERSION 2>/dev/null || echo unknown)}"); \COMMIT_ID=$${COMMIT_ID:-unknown}; \CGO_ENABLED=1 \CGO_CFLAGS="-Wno-deprecated-declarations" \diff --git a/docker-compose.yml b/docker-compose.ymlindex fd60ce9f6..69c2a3084 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -41,6 +41,14 @@ services:args:- APK_MIRROR_ARG=${APK_MIRROR_ARG:-}- WITH_ANYDOC=${WITH_ANYDOC:-1}+ # Build metadata shown on the system-info page. start_all.sh injects+ # these from git and the VERSION file; with a plain `docker compose+ # build` leave them unset (version falls back to the VERSION file,+ # the rest to "unknown").+ - VERSION_ARG=${VERSION_ARG:-}+ - COMMIT_ID_ARG=${COMMIT_ID_ARG:-}+ - BUILD_TIME_ARG=${BUILD_TIME_ARG:-}+ - GO_VERSION_ARG=${GO_VERSION_ARG:-}container_name: WeKnora-appports:- "${APP_PORT:-8080}:8080"diff --git a/scripts/start_all.sh b/scripts/start_all.shindex c9edb9f60..935a1209d 100755--- a/scripts/start_all.sh+++ b/scripts/start_all.sh@@ -58,18 +58,21 @@ log_success() {printf "%b\n" "${GREEN}[SUCCESS]${NC} $1"}-# Inject git short hash into the frontend image when composing from source.-# docker-compose.yml interpolates VITE_FRONTEND_COMMIT; the build context is-# frontend/ (no .git), so Vite cannot discover the commit on its own.-export_frontend_build_args() {- if [ -n "${VITE_FRONTEND_COMMIT:-}" ]; then- export VITE_FRONTEND_COMMIT- return 0- fi+# Inject build metadata into source-built images. docker-compose.yml+# interpolates VITE_FRONTEND_COMMIT (frontend) and VERSION_ARG / COMMIT_ID_ARG /+# BUILD_TIME_ARG / GO_VERSION_ARG (app); the build contexts contain no .git, so+# the images cannot discover these values on their own.+export_build_args() {# shellcheck source=/dev/nulleval "$("$PROJECT_ROOT/scripts/get_version.sh" env)"- export VITE_FRONTEND_COMMIT="${COMMIT_ID:-unknown}"- log_info "VITE_FRONTEND_COMMIT=${VITE_FRONTEND_COMMIT}"+ if [ -z "${VITE_FRONTEND_COMMIT:-}" ]; then+ export VITE_FRONTEND_COMMIT="${COMMIT_ID:-unknown}"+ fi+ export VERSION_ARG="${VERSION_ARG:-${VERSION:-unknown}}"+ export COMMIT_ID_ARG="${COMMIT_ID_ARG:-${COMMIT_ID:-unknown}}"+ export BUILD_TIME_ARG="${BUILD_TIME_ARG:-${BUILD_TIME:-unknown}}"+ export GO_VERSION_ARG="${GO_VERSION_ARG:-${GO_VERSION:-unknown}}"+ log_info "VITE_FRONTEND_COMMIT=${VITE_FRONTEND_COMMIT} VERSION_ARG=${VERSION_ARG} COMMIT_ID_ARG=${COMMIT_ID_ARG} BUILD_TIME_ARG=${BUILD_TIME_ARG}"}# 选择可用的 Docker Compose 命令(优先 docker compose,其次 docker-compose)@@ -372,7 +375,7 @@ start_docker() {# 进入项目根目录再执行docker-compose命令cd "$PROJECT_ROOT"- export_frontend_build_args+ export_build_args# 启动基本服务log_info "启动核心服务容器..."@@ -516,7 +519,7 @@ restart_container() {# 进入项目根目录再执行docker-compose命令cd "$PROJECT_ROOT"- export_frontend_build_args+ export_build_args# 检查容器是否存在if ! "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD ps --services | grep -q "^$container_name$"; thendiff --git a/website-docs/01-getting-started/04-configuration.md b/website-docs/01-getting-started/04-configuration.mdindex 749c13e09..1fdba0320 100644--- a/website-docs/01-getting-started/04-configuration.md+++ b/website-docs/01-getting-started/04-configuration.md@@ -263,11 +263,13 @@ AWS S3 的 `S3_ACCESS_KEY` / `S3_SECRET_KEY` 可以**同时留空**,此时走### 镜像构建参数(从源码构建时)-以下变量只在 `docker compose build` / `make docker-build-frontend` 构建 frontend 镜像时使用,拉取官方镜像部署时无需设置。其他构建参数(Go 代理、apt 镜像源等)见 `.env.example` A1 节。+以下变量只在 `docker compose build` / `make docker-build-frontend` 从源码构建 frontend / app 镜像时使用,拉取官方镜像部署时无需设置。其他构建参数(Go 代理、apt 镜像源等)见 `.env.example` A1 节。| 名称 | 默认值 | 说明 || --- | --- | --- || `VITE_FRONTEND_COMMIT` | unknown | 写入「系统信息」页的前端短 commit。`make docker-build-frontend` 与 `start_all.sh --no-pull` 会从 git 自动填充;直接 `docker compose build` 时需自行导出 |+| `VERSION_ARG` | 空(构建时回退读 `VERSION` 文件) | 写入「系统信息」页的应用版本号。`start_all.sh --no-pull` 会自动填充;直接 `docker compose build` 时可自行导出 |+| `COMMIT_ID_ARG` / `BUILD_TIME_ARG` / `GO_VERSION_ARG` | 空(unknown) | 写入「系统信息」页的应用 commit / 构建时间 / Go 版本。`start_all.sh --no-pull` 会从 git 自动填充 || `NPM_REGISTRY` | 空(默认源) | 构建阶段使用的 npm registry,国内可设 `https://registry.npmmirror.com` || `NODE_MAX_OLD_SPACE_SIZE` | 4096 | Vite 构建的 Node 堆上限(MB),Docker Desktop 内存较小时可降到 2048 |