69 lines
3.4 KiB
Bash
69 lines
3.4 KiB
Bash
#!/bin/bash
|
|
# 仅规划/持久化已选应用的固定版本;由 update.sh 调用,不编辑 Compose。
|
|
APPLICATION_VERSION_MAP='easyai-server SERVER_VERSION UPDATE_SERVER_VERSION registry.cn-shanghai.aliyuncs.com/comfy-ai/comfy-server
|
|
easyai-web WEB_VERSION UPDATE_WEB_VERSION registry.cn-shanghai.aliyuncs.com/comfy-ai/one-ai
|
|
ws-gateway WS_GATEWAY_VERSION UPDATE_GATEWAY_VERSION registry.cn-shanghai.aliyuncs.com/easyaigc/wsgateway
|
|
model-conversion-worker MODEL_CONVERSION_WORKER_VERSION UPDATE_WORKER_VERSION registry.cn-shanghai.aliyuncs.com/easyaigc/model-conversion-worker
|
|
easyai-updater UPDATER_VERSION UPDATE_UPDATER_VERSION registry.cn-shanghai.aliyuncs.com/easyaigc/easyai-updater
|
|
easyai-asg ASG_VERSION UPDATE_ASG_VERSION registry.cn-shanghai.aliyuncs.com/easyaigc/agent-governance
|
|
agent-memory AMS_VERSION UPDATE_AMS_VERSION registry.cn-shanghai.aliyuncs.com/easyaigc/agent-memory'
|
|
|
|
application_selected() {
|
|
[ -z "${UPDATE_SERVICES:-}" ] || [[ " ${UPDATE_SERVICES} " == *" $1 "* ]]
|
|
}
|
|
|
|
init_deployment_release_source() {
|
|
local file="$1" mode
|
|
if [ "${UPDATE_MANIFEST_SOURCE+x}" = x ]; then
|
|
mode="$(printf '%s' "${UPDATE_MANIFEST_SOURCE:-remote}" | tr '[:upper:]' '[:lower:]')"
|
|
write_env_value "$file" UPDATE_MANIFEST_SOURCE "$mode"
|
|
fi
|
|
if [ "${UPDATE_MANIFEST_URL+x}" = x ]; then write_env_value "$file" UPDATE_MANIFEST_URL "$UPDATE_MANIFEST_URL"; fi
|
|
}
|
|
|
|
plan_application_versions() {
|
|
local file="$1" plan entry resolver_root
|
|
resolver_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
APPLICATION_VERSION_WRITES=()
|
|
plan="$(python3 "$resolver_root/scripts/resolve-deployment-release.py" --root "$resolver_root" --env-file "$file")" || return 1
|
|
while IFS= read -r entry; do
|
|
[ -z "$entry" ] || APPLICATION_VERSION_WRITES+=("$entry")
|
|
done <<< "$plan"
|
|
}
|
|
|
|
apply_application_versions() {
|
|
local file="$1" entry temporary
|
|
temporary="$(mktemp "${file}.versions.XXXXXX")"
|
|
cp "$file" "$temporary"
|
|
chmod 600 "$temporary"
|
|
for entry in "${APPLICATION_VERSION_WRITES[@]}"; do
|
|
write_env_value "$temporary" "${entry%%=*}" "${entry#*=}"
|
|
done
|
|
mv "$temporary" "$file"
|
|
for entry in "${APPLICATION_VERSION_WRITES[@]}"; do echo "📌 已持久化应用版本: $entry"; done
|
|
}
|
|
|
|
verify_application_version_images() {
|
|
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")"
|
|
# --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
|
|
fi
|
|
done <<< "$APPLICATION_VERSION_MAP"
|
|
}
|