Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): specify target machine architecture for binary build #525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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