Files
planet/scripts/lib/docker-proxy.zsh
rayd1o 83a10a6c34
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.6
2026-09-16 21:05:40 +08:00

51 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env zsh
prepare_docker_build_proxy() {
# 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"
{
if ! "$python_bin" "$helper" plan > "$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 <<< "$status_text"
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 [ "$connected" -ne 1 ]; then
log_error "PLANET_PROXY_NO_ROUTE"
return 1
fi
if [ "$mode" = proxy ]; then
log_note "Docker 构建使用已验证可用的主机代理"
else
log_note "未发现可用主机代理Docker 构建使用直连"
fi
} always {
rm -f -- "$plan_file" "$error_file"
}
}