Skip to content

Commit

Permalink
fix(ci): specify target machine architecture for binary build
Browse files Browse the repository at this point in the history
Signed-off-by: Raphanus Lo <yunchang.lo@suse.com>
  • Loading branch information
COLDTURNIP committed Feb 14, 2025
1 parent 4555c06 commit 3f7c412
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx
21 changes: 18 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3f7c412

Please sign in to comment.