From ea47dce337387e8518b5640b3a9587a3e707427a Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 26 May 2026 11:20:37 +0800 Subject: [PATCH] fix(compose): use env_file array form for builtin_models compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #1453 introduced the map form of env_file: env_file: - path: .env required: false which is only recognised by Docker Compose v2.24+ (Jan 2024). Older deploys would refuse to parse docker-compose.yml even when builtin_models YAML is not enabled — breaking the "no impact unless opted in" promise. Switch to the array form (`env_file: [.env]`) which has been supported since the earliest Compose schemas. The trade-off is that Compose now errors when .env is absent, so: - scripts/start_all.sh already calls check_env_file (cp .env.example .env if missing) before docker compose up; that path is unaffected. - The bare `make docker-run` / `make docker-restart` targets in the Makefile are taught the same fallback: touch / copy .env.example before invoking docker-compose, so fresh clones keep working. The docker-compose.yml comment block is updated to explain the version trade-off so future maintainers don't re-introduce the map form. --- Makefile | 6 ++++++ docker-compose.yml | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0378d244..73aeb6a5 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,12 @@ docker-build-frontend: docker-build-all: docker-build-app docker-build-docreader docker-build-frontend # Run Docker container (传统方式) +# Touch .env if missing — docker-compose.yml's `env_file: [.env]` is required +# for ${ENV} interpolation in builtin_models.yaml and would otherwise refuse +# to parse on fresh clones. `start-all` handles this via check_env_file; this +# direct path needs its own guard. docker-run: + @[ -f .env ] || ([ -f .env.example ] && cp .env.example .env || touch .env) docker-compose up # 使用新脚本启动所有服务 @@ -164,6 +169,7 @@ clean-images: # Restart Docker container (stop, start) docker-restart: + @[ -f .env ] || ([ -f .env.example ] && cp .env.example .env || touch .env) docker-compose stop -t 60 docker-compose up diff --git a/docker-compose.yml b/docker-compose.yml index 7c3b6834..ff04f0af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,13 +51,18 @@ services: timeout: 10s retries: 3 start_period: 60s - # Optional: source .env so deployment-specific vars (e.g. those referenced - # by config/builtin_models.yaml via ${ENV}) reach the app container without - # having to be listed individually under `environment:`. Falls back - # silently when .env is absent (e.g. fresh upstream clone). + # Source .env so deployment-specific variables (e.g. those referenced by + # config/builtin_models.yaml via ${ENV}, or any future feature) reach the + # app container without having to be enumerated under `environment:`. + # + # NOTE: the array form below is used instead of the map form + # (env_file: - path: .env, required: false) because the map syntax + # requires Docker Compose v2.24+ (Jan 2024) and would break parsing on + # older deploys. The trade-off is that Compose errors out if .env is + # absent — see scripts/start_all.sh for the pre-flight touch that keeps + # fresh clones working. env_file: - - path: .env - required: false + - .env environment: - LOG_LEVEL=${LOG_LEVEL:-} - COS_SECRET_ID=${COS_SECRET_ID:-}