fix(deploy): 按服务读取镜像定义避免依赖镜像误判

This commit is contained in:
2026-10-14 11:24:13 +08:00
parent 9a801ea3d5
commit bf0ac6db54
4 changed files with 77 additions and 7 deletions
+13 -2
View File
@@ -58,11 +58,22 @@ apply_application_versions() {
}
verify_application_version_images() {
local file="$1" compose="$2" service key option image version actual
local file="$1" compose="$2" service key option image version actual configuration
while read -r service key option image; do
application_selected "$service" || continue
version="$(read_env_value "$file" "$key")"
actual="$(sudo $compose config --images "$service")" || return 1
# --images SERVICE includes dependency images on Compose 5. Read the
# selected service from normalized config instead of comparing the list.
configuration="$(sudo $compose config --format json "$service")" || return 1
actual="$(printf '%s' "$configuration" | python3 -c '
import json, sys
try:
image = json.load(sys.stdin)["services"][sys.argv[1]]["image"]
if not isinstance(image, str): raise ValueError()
print(image)
except (ValueError, KeyError, TypeError):
raise SystemExit("无法读取应用的有效镜像定义;尚未拉取或重建服务")
' "$service")" || return 1
if [ "$actual" != "$image:$version" ]; then
echo "❌ $service 的有效镜像未使用 .env 中的固定版本 $key=$version;请通过部署仓库的受控迁移恢复镜像定义,尚未拉取或重建服务" >&2
return 1