Skip to content

Commit

Permalink
fix(ci): fix multiplatform build
Browse files Browse the repository at this point in the history
Signed-off-by: Raphanus Lo <[email protected]>
  • Loading branch information
COLDTURNIP committed Feb 14, 2025
1 parent c543bd7 commit 90810b6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

# For multi-platform support
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
Expand All @@ -83,4 +89,5 @@ jobs:
env:
REPO: docker.io/longhornio
TAG: ${{ needs.build.outputs.image_tag }}
TARGET_PLATFORMS: linux/amd64,linux/arm64
run: make workflow-image-build-push
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ARG https_proxy
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
ENV PATH /go/bin:$PATH
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_RUN_ARGS --privileged -v /dev:/host/dev -v /proc:/host/proc
ENV DAPPER_SOURCE /go/src/github.com/longhorn/longhorn-share-manager
Expand Down
20 changes: 18 additions & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ fi
cd $(dirname $0)/..

mkdir -p bin
archs=("amd64" "arm64")

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/longhorn-share-manager-$arch" -ldflags "$LINKFLAGS" $COVER $COVERPKG
CGO_ENABLED=0 GOARCH="${arch}" go build -o "bin/longhorn-share-manager-${arch}" -ldflags "${LINKFLAGS}" ${COVER} ${COVERPKG}
done
31 changes: 16 additions & 15 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ BUILDER_ARGS=()

BUILDX_ARGS=()

case $(uname -m) in
aarch64 | arm64)
BUILDERARCH=arm64
;;
x86_64)
BUILDERARCH=amd64
;;
*)
echo "$(uname -a): unsupported architecture"
exit 1
esac

if [[ ${TARGET_PLATFORMS} ]] ; then
IFS='/' read -r OS ARCH <<<"${TARGET_PLATFORMS}"
BUILDX_ARGS+=('--platform' "${TARGET_PLATFORMS}")
else
case $(uname -m) in
aarch64 | arm64)
ARCH=arm64
;;
x86_64)
ARCH=amd64
;;
*)
echo "$(uname -a): unsupported architecture"
exit 1
esac
BUILDX_ARGS+=('--platform' "linux/${ARCH}")
BUILDX_ARGS+=('--platform' "linux/${BUILDERARCH}")
fi

if [[ -z $TAG ]]; then
if API_VERSION=$(./bin/longhorn-share-manager-"${ARCH}" version --client-only | jq ".clientVersion.apiVersion"); then
if API_VERSION=$(./bin/longhorn-share-manager-"${BUILDERARCH}" version --client-only | jq ".clientVersion.apiVersion"); then
TAG="v${API_VERSION}_$(date -u +%Y%m%d)"
else
TAG="${VERSION}"
Expand All @@ -66,7 +67,7 @@ fi

[[ $IS_SECURE == 'true' ]] && BUILDX_ARGS+=('--sbom=true' '--attest' 'type=provenance,mode=max')

IMAGE_ARGS=(--build-arg ARCH="${ARCH}")
IMAGE_ARGS=()
[[ -n "${SRC_BRANCH}" ]] && IMAGE_ARGS+=(--build-arg SRC_BRANCH="${SRC_BRANCH}")
[[ -n "${SRC_TAG}" ]] && IMAGE_ARGS+=(--build-arg SRC_TAG="${SRC_TAG}")

Expand All @@ -91,5 +92,5 @@ echo "${BUILD_CMD[@]}" "${IMAGE_BUILD_CMD_ARGS[@]}"

echo "Built ${IMAGE}"

mkdir ./bin || true
mkdir -p ./bin
echo "${IMAGE}" > ./bin/latest_image

0 comments on commit 90810b6

Please sign in to comment.