Skip to content

Commit

Permalink
Improve multi-architecture build support and error handling
Browse files Browse the repository at this point in the history
Updated PLATFORMS to automatically include all supported platforms when export PLATFORMS=all is used.
Removed --no-cache to improve build time by leveraging cached layers during the build process.
Enhanced error handling for expected failures.
Added auto-detection of architecture for Docker buildx installation to support multiple platforms.

Signed-off-by: Ashok Pariya [email protected]
  • Loading branch information
ashokpariya0 committed Dec 2, 2024
1 parent a943400 commit 81732b6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ OPERATOR_IMAGE ?= cluster-network-addons-operator
REGISTRY_IMAGE ?= cluster-network-addons-registry
export OCI_BIN ?= $(shell if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi)
TLS_SETTING := $(if $(filter $(OCI_BIN),podman),--tls-verify=false,)
PLATFORM_LIST ?= linux/amd64,linux/s390x,linux/arm64
ARCH := $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
PLATFORMS ?= linux/${ARCH}
PLATFORMS := $(if $(filter all,$(PLATFORMS)),$(PLATFORM_LIST),$(PLATFORMS))
# Set the platforms for building a multi-platform supported image.
# Example:
# PLATFORMS ?= linux/amd64,linux/arm64,linux/s390x
# Alternatively, you can export the PLATFORMS variable like this:
# export PLATFORMS=linux/arm64,linux/s390x,linux/amd64
# or export PLATFORMS=all to automatically include all supported platforms.
DOCKER_BUILDER ?= cnao-docker-builder
OPERATOR_IMAGE_TAGGED := $(IMAGE_REGISTRY)/$(OPERATOR_IMAGE):$(IMAGE_TAG)

Expand Down
1 change: 1 addition & 0 deletions hack/build-operator-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ if [ ${#PLATFORM_LIST[@]} -eq 1 ]; then
else
./hack/init-buildx.sh "$DOCKER_BUILDER"
docker buildx build --platform "$PLATFORMS" $BUILD_ARGS
docker buildx rm "$DOCKER_BUILDER" 2>/dev/null || echo "Builder ${DOCKER_BUILDER} not found or already removed, skipping."
fi
5 changes: 2 additions & 3 deletions hack/build-operator-podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ fi
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"

# Remove any existing manifest and image
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" || true
podman rmi "${OPERATOR_IMAGE_TAGGED}" || true
podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null
podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null

podman manifest create "${OPERATOR_IMAGE_TAGGED}"

for platform in "${PLATFORM_LIST[@]}"; do
podman build \
--no-cache \
--build-arg BUILD_ARCH="$ARCH" \
--platform "$platform" \
--manifest "${OPERATOR_IMAGE_TAGGED}" \
Expand Down
5 changes: 3 additions & 2 deletions hack/init-buildx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ check_buildx() {
if ! docker buildx > /dev/null 2>&1; then
mkdir -p ~/.docker/cli-plugins
BUILDX_VERSION=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | jq -r .tag_name)
curl -L https://github.com/docker/buildx/releases/download/"${BUILDX_VERSION}"/buildx-"${BUILDX_VERSION}".linux-amd64 --output ~/.docker/cli-plugins/docker-buildx
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -L https://github.com/docker/buildx/releases/download/"${BUILDX_VERSION}"/buildx-"${BUILDX_VERSION}".linux-"${ARCH}" --output ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
fi
}
Expand All @@ -20,7 +21,7 @@ create_or_use_buildx_builder() {

check_buildx

current_builder="$(docker buildx inspect "${builder_name}")"
current_builder="$(docker buildx inspect "${builder_name}" 2>/dev/null)" || echo "Builder '${builder_name}' not found"

if ! grep -q "^Driver: docker$" <<<"${current_builder}" && \
grep -q "linux/amd64" <<<"${current_builder}" && \
Expand Down

0 comments on commit 81732b6

Please sign in to comment.