From f2e575d98d3fb198c57bbcf938bccf097cc8cb74 Mon Sep 17 00:00:00 2001 From: Sh1n3zZ Date: Wed, 12 Feb 2025 18:07:43 +0800 Subject: [PATCH] fix: build error on arm64 --- Dockerfile | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d5441ce..1c7f5ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,12 +13,32 @@ ARG TARGETARCH ARG TARGETOS ENV GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on CGO_ENABLED=1 -# Install dependencies for cgo -RUN apk add --no-cache gcc musl-dev +# Install build dependencies and cross-compilation toolchain +RUN apk add --no-cache \ + gcc \ + musl-dev \ + g++ \ + make \ + linux-headers \ + wget \ + tar \ + && if [ "$TARGETARCH" = "arm64" ]; then \ + wget -q -O /tmp/cross.tgz https://musl.cc/aarch64-linux-musl-cross.tgz && \ + tar -xf /tmp/cross.tgz -C /usr/local && \ + rm /tmp/cross.tgz; \ + fi # Build backend -RUN go install && \ - go build . +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + CC=/usr/local/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc \ + CGO_ENABLED=1 \ + GOOS=linux \ + GOARCH=arm64 \ + go build -o chat -a -ldflags="-extldflags=-static" .; \ + else \ + go install && \ + go build .; \ + fi FROM node:18 AS frontend