🐛 fix(docker_runner): validate act_runner binary arch

This commit is contained in:
csh
2026-05-22 11:58:01 +08:00
parent 0579c2dc97
commit e5db752c55
3 changed files with 166 additions and 2 deletions
+4
View File
@@ -119,6 +119,10 @@ echo ""
if curl -L "$DOWNLOAD_URL" -o "$INSTALL_PATH"; then
chmod +x "$INSTALL_PATH"
if declare -F validate_binary_arch_or_fail >/dev/null 2>&1; then
validate_binary_arch_or_fail "$INSTALL_PATH" "$RUNNER_ARCH"
fi
# 同时创建软链接到系统路径
ln -sf "$INSTALL_PATH" "$SYSTEM_PATH"
+86 -2
View File
@@ -88,6 +88,73 @@ detect_runner_arch() {
esac
}
detect_binary_arch_from_file() {
local binary_path=$1
local magic=""
local low_byte=""
local high_byte=""
local machine_hex=""
if [ ! -f "${binary_path}" ]; then
echo "unknown"
return 0
fi
magic=$(od -An -t x1 -N 4 "${binary_path}" 2>/dev/null | tr -d ' \n')
if [ "${magic}" != "7f454c46" ]; then
echo "unknown"
return 0
fi
read -r low_byte high_byte <<<"$(od -An -t x1 -j 18 -N 2 "${binary_path}" 2>/dev/null)"
if [ -z "${low_byte:-}" ] || [ -z "${high_byte:-}" ]; then
echo "unknown"
return 0
fi
machine_hex="${high_byte}${low_byte}"
case "${machine_hex}" in
003e)
echo "amd64"
;;
00b7)
echo "arm64"
;;
0028)
echo "arm-7"
;;
*)
echo "unknown"
;;
esac
}
binary_arch_matches_target() {
local binary_path=$1
local expected_arch=$2
local detected_arch=""
detected_arch=$(detect_binary_arch_from_file "${binary_path}")
[ "${detected_arch}" = "${expected_arch}" ]
}
validate_binary_arch_or_fail() {
local binary_path=$1
local expected_arch=$2
local detected_arch=""
detected_arch=$(detect_binary_arch_from_file "${binary_path}")
if [ "${detected_arch}" = "unknown" ]; then
fail "Unable to detect downloaded binary architecture: ${binary_path}"
fi
if [ "${detected_arch}" != "${expected_arch}" ]; then
fail "Downloaded binary architecture mismatch: expected ${expected_arch}, got ${detected_arch}"
fi
}
get_installed_version() {
local output=""
@@ -102,6 +169,16 @@ get_installed_version() {
fi
}
get_installed_binary_arch() {
if [ -x "${INSTALL_PATH}" ]; then
detect_binary_arch_from_file "${INSTALL_PATH}"
elif command -v act_runner >/dev/null 2>&1; then
detect_binary_arch_from_file "$(command -v act_runner)"
else
echo "unknown"
fi
}
list_registered_runners() {
local runner_dir
@@ -154,6 +231,7 @@ download_and_install() {
log "Downloading ${url}"
curl -fL "${url}" -o "${tmp_path}"
chmod +x "${tmp_path}"
validate_binary_arch_or_fail "${tmp_path}" "${arch}"
downloaded_version=$("${tmp_path}" --version 2>/dev/null | extract_version_number)
if [ "${downloaded_version}" != "${version}" ]; then
@@ -205,6 +283,7 @@ main() {
local target_arch=""
local auto_confirm="false"
local current_version=""
local current_arch="unknown"
local runner_names=()
while [ $# -gt 0 ]; do
@@ -252,13 +331,18 @@ main() {
target_arch=$(detect_runner_arch)
fi
if [ -n "${current_version}" ] && [ "${current_version}" = "${target_version}" ]; then
log "act_runner is already at the latest version: ${current_version}"
current_arch=$(get_installed_binary_arch || true)
if [ -n "${current_version}" ] && \
[ "${current_version}" = "${target_version}" ] && \
[ "${current_arch}" = "${target_arch}" ]; then
log "act_runner is already at the requested version and architecture: ${current_version} (${current_arch})"
exit 0
fi
log "Upgrade summary:"
log " Current version: ${current_version:-not installed}"
log " Current arch: ${current_arch:-unknown}"
log " Target version: ${target_version}"
log " Architecture: ${target_arch}"
log " Install path: ${INSTALL_PATH}"