From 3f7c4126787f320487fa63b9ed618dfda5c43855 Mon Sep 17 00:00:00 2001 From: Raphanus Lo Date: Fri, 14 Feb 2025 13:01:25 +0800 Subject: [PATCH] fix(ci): specify target machine architecture for binary build Signed-off-by: Raphanus Lo --- Dockerfile.dapper | 4 ++-- scripts/build | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 52170831..c6c7f661 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -6,7 +6,7 @@ ARG https_proxy ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} ENV DAPPER_DOCKER_SOCKET true -ENV DAPPER_ENV TAG REPO DRONE_REPO DRONE_PULL_REQUEST DRONE_COMMIT_REF +ENV DAPPER_ENV TAG REPO DRONE_REPO DRONE_PULL_REQUEST DRONE_COMMIT_REF ARCHS ENV DAPPER_OUTPUT bin coverage.out ENV DAPPER_SOURCE /go/src/github.com/longhorn/backing-image-manager @@ -31,4 +31,4 @@ RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/i ## Install Docker Buildx: The docker version in dapper is too old to have buildx. Install it manually. RUN curl -sSfLO https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} && \ chmod +x buildx-v0.13.1.linux-${ARCH} && \ - mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx \ No newline at end of file + mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx diff --git a/scripts/build b/scripts/build index 4a58819d..6c26de4e 100755 --- a/scripts/build +++ b/scripts/build @@ -20,7 +20,22 @@ cd $(dirname $0)/.. mkdir -p bin -archs=("amd64" "arm64") -for arch in "${archs[@]}"; do - CGO_ENABLED=0 GOARCH="$arch" go build -o "bin/backing-image-manager-$arch" -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" $COVER $COVERPKG +ARCHS=${ARCHS:-''} +if [[ -z "${ARCHS}" ]]; then + case $(uname -m) in + aarch64 | arm64) + ARCHS=(arm64) + ;; + x86_64) + ARCHS=(amd64) + ;; + *) + echo "$(uname -a): unsupported architecture" + exit 1 + esac +else + IFS=' ' read -r -a ARCHS <<<"${ARCHS}" +fi +for arch in "${ARCHS[@]}"; do + CGO_ENABLED=0 GOARCH="${arch}" go build -o "bin/backing-image-manager-${arch}" -ldflags "${LINKFLAGS} ${OTHER_LINKFLAGS}" ${COVER} ${COVERPKG} done