From 6965874ec2b5b5ba33364d6aebb11ac228c47df8 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Sun, 23 Feb 2025 12:15:31 +0000 Subject: [PATCH] feat: add ARM64 cross-compilation support in Dockerfile --- Dockerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 132b17e6..6be9d1d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,17 @@ RUN go mod download COPY . . COPY --from=builder /web/build ./web/build -RUN go build -trimpath -ldflags "-s -w -X github.com/songquanpeng/one-api/common.Version=$(cat VERSION)" -o one-api +# For ARM64 builds, install and use the appropriate cross-compiler. +RUN if [ "$GOARCH" = "arm64" ]; then \ + apt-get update && apt-get install -y gcc-aarch64-linux-gnu; \ + fi + +# Use a single RUN command to conditionally set CC for ARM64. +RUN if [ "$GOARCH" = "arm64" ]; then \ + CC=aarch64-linux-gnu-gcc go build -trimpath -ldflags "-s -w -X github.com/songquanpeng/one-api/common.Version=$(cat VERSION)" -o one-api; \ + else \ + go build -trimpath -ldflags "-s -w -X github.com/songquanpeng/one-api/common.Version=$(cat VERSION)" -o one-api; \ + fi FROM debian:bullseye