Skip to content

Commit

Permalink
build: support aarch64/x86 build
Browse files Browse the repository at this point in the history
    - Also use buildx instead docker to build image

Signed-off-by: Vicente Cheng <[email protected]>
  • Loading branch information
Vicente-Cheng committed May 9, 2024
1 parent 924c2e1 commit c39d6e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ RUN zypper -n rm container-suseconnect && \
## install golangci
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1

## install controller-gen
# The docker version in dapper is too old to have buildx. Install it manually.
RUN curl -sSfL https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} -o 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

## install controller-gen
RUN go install sigs.k8s.io/controller-tools/cmd/[email protected]


# install openapi-gen
RUN go install k8s.io/code-generator/cmd/[email protected]

Expand Down
11 changes: 10 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ RUN zypper -n rm container-suseconnect && \
zypper -n install util-linux-systemd e2fsprogs iproute2 && \
zypper -n clean -a && rm -rf /tmp/* /var/tmp/* /usr/share/doc/packages/*

COPY bin/node-disk-manager /usr/bin/
ARG TARGETPLATFORM

RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH=${TARGETPLATFORM#linux/}

COPY bin/node-disk-manager-${ARCH} /usr/bin/node-disk-manager
CMD ["node-disk-manager"]
8 changes: 3 additions & 5 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ fi
LINKFLAGS="-X github.com/harvester/node-disk-manager/pkg/version.Version=$VERSION
-X github.com/harvester/node-disk-manager/pkg/version.GitCommit=$COMMIT $LINKFLAGS"

CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/node-disk-manager
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/node-disk-manager-darwin
GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/node-disk-manager-windows
fi
for arch in "amd64" "arm64"; do
GOARCH="$arch" CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/node-disk-manager-"$arch"
done
2 changes: 1 addition & 1 deletion scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ -e ${DOCKERFILE}.${ARCH} ]; then
DOCKERFILE=${DOCKERFILE}.${ARCH}
fi

docker build -f ${DOCKERFILE} -t ${IMAGE} .
buildx build --load -f ${DOCKERFILE} -t ${IMAGE} .
echo Built ${IMAGE}
if [[ -n ${BUILD_FOR_CI} ]]; then
docker push ${IMAGE}
Expand Down

0 comments on commit c39d6e4

Please sign in to comment.