Skip to content

Commit

Permalink
Merge pull request #423 from ericpromislow/move-cross-arch-fix-to-v4
Browse files Browse the repository at this point in the history
Bring the 3.0 CROSS_ARCH changes into v4.0
  • Loading branch information
ericpromislow authored Feb 28, 2024
2 parents a0d8d1e + f879b6a commit 604b5ef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 4 additions & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ If you want to interact with the Minio deployed in the cluster, you can use the

### Building on Different Architectures

Currently we only support building this chart for amd64 nodes. The binary built by `make build` is set to build for amd64 and we have also included a flag for users running different architectures when trying to package the code into a docker image. Setting `USE_DOCKER_BUILDX=1` will force the package script to use docker buildx, setting the target platform to build for amd64. If you do not have `docker-buildx` installed please reference [this page](https://docs.docker.com/buildx/working-with-buildx/).
Currently, we only support building this chart fully for `amd64` nodes. The binary and image building scripts will build "arch native" by default.
So when building on `amd64` the resulting binary and image will both be `amd64` - same for `arm64`. This is how the drone builds operate.

We have also included a flag for users running different architectures when trying to package the code into an `amd64` docker image. Building the binary with `CROSS_ARCH=true` set will cause it to build `amd64` and `arm64` binaries, and then setting `USE_DOCKER_BUILDX=1` will force the package script to use docker buildx, setting the container's target platform to build for `amd64`. If you do not have `docker-buildx` installed please reference [this page](https://docs.docker.com/buildx/working-with-buildx/).


### Developer Uninstallation
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN if [ "${ARCH}" != "s390x" ]; then \
chmod +x /usr/local/bin/mc; \
fi

ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS USE_DOCKER_BUILDX
ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS CROSS_ARCH USE_DOCKER_BUILDX
ENV DAPPER_SOURCE /go/src/github.com/rancher/backup-restore-operator/
ENV DAPPER_OUTPUT ./bin ./dist
ENV GOCACHE /root/.cache/go-build
Expand Down
29 changes: 25 additions & 4 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,29 @@ if [ "$(uname)" = "Linux" ]; then
fi
LINKFLAGS="-X main.Version=$VERSION"
LINKFLAGS="-X main.GitCommit=$COMMIT $LINKFLAGS"
CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/backup-restore-operator
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/backup-restore-operator-darwin
GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/backup-restore-operator-windows


ARCHES=( "$ARCH" )
# Set CROSS_ARCH to build for the other architecture
if [ "$CROSS_ARCH" == "true" ]; then
case "$ARCH" in
amd64) XARCH=arm64 ;;
arm64) XARCH=amd64 ;;
*) echo "Unsupported ARCH of $ARCH" 1>&2 ; exit 1
esac
ARCHES+=( "$XARCH" )
fi

for A in "${ARCHES[@]}" ; do
GOARCH="$A" CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o "bin/backup-restore-operator-$A"
# Set CROSS to build for other OS'es
if [ "$CROSS" = "true" ]; then
for OS in darwin windows ; do
GOARCH="$A" GOOS=$OS go build -ldflags "$LINKFLAGS" -o "bin/backup-restore-operator-$OS-$A"
done
fi
done

cd bin
ln -sf "./backup-restore-operator-$ARCH" "./backup-restore-operator"
cd ..
6 changes: 5 additions & 1 deletion scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ source $(dirname $0)/version
cd $(dirname $0)/..

mkdir -p dist/artifacts
cp bin/backup-restore-operator dist/artifacts/backup-restore-operator${SUFFIX}
if [ "$CROSS_ARCH" != "true" ]; then
cp bin/backup-restore-operator dist/artifacts/backup-restore-operator${SUFFIX}
else
cp bin/backup-restore-operator${SUFFIX} dist/artifacts/
fi

IMAGE=${REPO}/backup-restore-operator:${TAG}
DOCKERFILE=package/Dockerfile
Expand Down

0 comments on commit 604b5ef

Please sign in to comment.