Files
planet/scripts/lib/docker-proxy.zsh
linkong 60eefb19c9
Some checks are pending
ci / backend (push) Waiting to run
ci / frontend (push) Waiting to run
ci / delivery (push) Blocked by required conditions
release / images (push) Waiting to run
release: bump version to 0.74.7
2026-09-17 17:30:54 +08:00

53 lines
2.0 KiB
Bash

#!/usr/bin/env zsh
prepare_docker_build_proxy() {
DOCKER_BUILD_USE_MIRROR=0
# Desktop and remote/rootless daemons are managed in their own environment.
docker_uses_local_engine || return 0
docker_desktop_present && return 0
local python_bin="$(command -v python3)"
local helper="$SCRIPT_DIR/scripts/docker_proxy.py"
local plan_file error_file
local mode changed connected status_text
if [ -z "$python_bin" ] || ! plan_file="$(mktemp "$PLANET_STATE_DIR/docker-proxy.XXXXXX")"; then
log_error "Docker 构建代理检测失败"
return 1
fi
error_file="${plan_file}.error"
chmod 600 "$plan_file"
: > "$error_file"
chmod 600 "$error_file"
{
set_wait_detail "检查镜像源的代理、直连与备用路径"
if ! "$python_bin" "$helper" plan "${1:-auto}" > "$plan_file" 2> "$error_file"; then
log_error "Docker 构建代理检测失败" "$error_file"
return 1
fi
if ! status_text="$("$python_bin" "$helper" status < "$plan_file" 2> "$error_file")"; then
log_error "Docker 构建代理检测失败" "$error_file"
return 1
fi
read -r mode changed connected DOCKER_BUILD_USE_MIRROR <<< "$status_text"
if [ "$connected" -ne 1 ]; then
log_error "PLANET_PROXY_NO_ROUTE"
return 1
fi
if [ "$changed" -eq 1 ]; then
docker_require_sudo || return 1
log_note "更新 Docker 构建代理配置,重启后恢复原先运行的容器"
if ! docker_as_root "$python_bin" "$helper" apply < "$plan_file" 2> "$error_file"; then
log_error "Docker 构建代理更新失败" "$error_file"
return 1
fi
fi
if [ "$mode" = proxy ]; then
set_wait_detail "Docker 使用已验证可用的主机代理"
else
set_wait_detail "Docker 使用已验证可用的直连路径"
fi
} always {
rm -f -- "$plan_file" "$error_file"
}
}