Skip to content

fix(docker): 修复 arm64 镜像内置 x86-64 二进制导致 ARM 服务器无法运行#240

Merged
su-fen merged 1 commit into
mainfrom
fix/docker-arm64-image
Jul 23, 2026
Merged

fix(docker): 修复 arm64 镜像内置 x86-64 二进制导致 ARM 服务器无法运行#240
su-fen merged 1 commit into
mainfrom
fix/docker-arm64-image

Conversation

@su-fen

@su-fen su-fen commented Jul 23, 2026

Copy link
Copy Markdown
Member

问题

已发布的所有 gateway 镜像(v0.1.0 ~ v1.1.8)虽然 manifest 声明支持 linux/arm64,但 arm64 变体里装的实际是 x86-64 二进制,在 ARM 服务器上启动直接报 exec format error

验证方式:分别下载 GHCR 上 latest 两个平台变体的最后一层并提取 /usr/local/bin/liveagent-gateway:

  • amd64 变体:ELF 64-bit LSB executable, x86-64
  • arm64 变体:ELF 64-bit LSB executable, x86-64(与 amd64 变体 sha256 完全相同,BuildID 一致)

根因

Dockerfile 中重新声明 buildx 自动注入的平台参数时带了默认值:

ARG TARGETOS=linux
ARG TARGETARCH=amd64

stage 内带默认值的重声明会遮蔽 buildx 按平台注入的值,导致两条构建腿的 GOARCH 都被钉死为 amd64FROM 的平台解析本身是正常的(runtime 基础层两个变体各自正确),所以产出了"外壳 arm64、二进制 amd64"的镜像,docker manifest inspect 完全看不出异常。

修复

  1. Dockerfile:去掉 TARGETOS/TARGETARCH 的默认值,让 buildx 注入的按平台值生效;同时把 webui 和 Go 构建阶段钉到 --platform=$BUILDPLATFORM,改为原生交叉编译——此前 arm64 腿的 pnpm buildgo build 都跑在 QEMU 模拟下,纯浪费构建时间。本地 make gateway-docker-build(单平台 BuildKit 构建)行为不变,bare ARG 自动取宿主平台值。
  2. CI 防回归:发布后新增校验步骤,按平台拉取刚推送的 digest,提取镜像内二进制并断言 ELF 架构与声明一致,不一致直接 fail。这个问题静默存在了 37 个 tag 没被发现,值得一道硬闸。

按需求不处理旧镜像/旧 tag;下一次打 tag 发布即产出真正的双架构镜像(注意 workflow_dispatch 重发旧 tag 会 checkout 旧代码,不含本修复)。

验证

本机无 docker 后端,未做本地构建;修复采用 Docker 官方文档的标准交叉编译模式,发布时由新增的 CI 校验步骤兜底验证。

🤖 Generated with Claude Code

…ip arm64 binaries

Every published image (v0.1.0 through v1.1.8) advertised linux/arm64
but contained an x86-64 gateway binary — both platform variants were
byte-identical — so the container crashed with "exec format error" on
ARM hosts. Root cause: the Dockerfile redeclared TARGETOS/TARGETARCH
with default values, which shadow the per-platform values buildx
injects, pinning GOARCH=amd64 in both build legs.

Drop the defaults so buildx's values apply, pin the webui and Go build
stages to $BUILDPLATFORM to cross-compile natively instead of under
QEMU emulation, and add a post-push CI step that extracts the binary
from each platform variant and fails the workflow if its ELF
architecture does not match the advertised one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@su-fen
su-fen merged commit 4d07fec into main Jul 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant