Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokpariya0 committed Dec 5, 2024
1 parent 8f57b9d commit b070bc8
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions hack/components/bump-linux-bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ echo 'Build container image with linux-bridge binaries'
LINUX_BRIDGE_TAR_CONTAINER_DIR=/usr/src/github.com/containernetworking/plugins/bin
LINUX_BRIDGE_IMAGE=quay.io/kubevirt/cni-default-plugins
LINUX_BRIDGE_IMAGE_TAGGED=${LINUX_BRIDGE_IMAGE}:${LINUX_BRIDGE_TAG}
ARCH=$(uname -m | sed 's/x86_64/amd64/')
PLATFORMS="linux/amd64,linux/s390x"
DOCKER_BUILDER="${DOCKER_BUILDER:-linux-bridge-docker-builder}"
# By default, the build will be based on the host architecture.
# To build for other platforms, you can:
# 1. Export all supported platforms: export PLATFORMS=all
# 2. Or specify specific platforms: export PLATFORMS=linux/amd64,linux/arm64
PLATFORM_LIST="linux/amd64,linux/s390x,linux/arm64"
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
[ -z "$PLATFORMS" ] && PLATFORMS="linux/${ARCH}"
[ "$PLATFORMS" == "all" ] && PLATFORMS="${PLATFORM_LIST}"
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"

create_dockerfile() {
Expand All @@ -46,7 +52,7 @@ RUN \
WORKDIR ${LINUX_BRIDGE_PATH}
RUN GOFLAGS=-mod=vendor ./build_linux.sh
FROM registry.access.redhat.com/ubi8/ubi-minimal AS final
FROM registry.access.redhat.com/ubi8/ubi-minimal
LABEL org.opencontainers.image.authors="[email protected]"
ENV SOURCE_DIR=${REMOTE_SOURCE_DIR}/app
RUN mkdir -p ${LINUX_BRIDGE_TAR_CONTAINER_DIR}
Expand All @@ -70,26 +76,35 @@ check_and_create_docker_builder() {
}

build_docker_image() {
docker buildx build --platform "${PLATFORMS}" --build-arg BUILD_ARCH="$ARCH" -t "${LINUX_BRIDGE_IMAGE_TAGGED}" . --push
docker buildx build --platform "${PLATFORMS}" -t "${LINUX_BRIDGE_IMAGE_TAGGED}" . --push
docker buildx rm "$DOCKER_BUILDER"
}

build_podman_image() {
podman manifest rm "${LINUX_BRIDGE_IMAGE_TAGGED}" || true
podman rmi "${LINUX_BRIDGE_IMAGE_TAGGED}" || true
podman manifest rm "${LINUX_BRIDGE_IMAGE_TAGGED}" 2>/dev/null || true
podman rmi "${LINUX_BRIDGE_IMAGE_TAGGED}" 2>/dev/null || true
podman manifest create "${LINUX_BRIDGE_IMAGE_TAGGED}"

for platform in "${PLATFORM_LIST[@]}"; do
podman build --no-cache --build-arg BUILD_ARCH="$ARCH" --platform "$platform" --manifest "${LINUX_BRIDGE_IMAGE_TAGGED}" .
podman build --platform "$platform" --manifest "${LINUX_BRIDGE_IMAGE_TAGGED}" .
done
}

push_image_to_kubevirt_repo() {
echo 'Push the image to KubeVirt repo'
if [ "${OCI_BIN}" == "podman" ]; then
if [ ! -z "${PUSH_IMAGES}" ]; then
podman manifest push "${LINUX_BRIDGE_IMAGE_TAGGED}"
fi
fi
}

modify_dockerfile_for_platform_and_architecture() {
local dockerfile="$1"
# Modify Dockerfile to set platform and architecture
sed -i 's|^FROM registry.access.redhat.com/ubi8/ubi-minimal AS builder$|FROM --platform=linux/${BUILD_ARCH} registry.access.redhat.com/ubi8/ubi-minimal AS builder|' "$dockerfile"
sed -i 's|^FROM registry.access.redhat.com/ubi8/ubi-minimal AS builder$|FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/ubi-minimal AS builder|' "$dockerfile"
sed -i 's|RUN GOFLAGS=-mod=vendor ./build_linux.sh|RUN GOFLAGS=-mod=vendor GOARCH=${TARGETARCH} GOOS=${TARGETOS} ./build_linux.sh|' "$dockerfile"
sed -i 's/^FROM registry.access.redhat.com\/ubi8\/ubi-minimal AS final$/FROM --platform=linux\/${TARGETARCH} registry.access.redhat.com\/ubi8\/ubi-minimal AS final/' "$dockerfile"
sed -i 's/^FROM registry.access.redhat.com\/ubi8\/ubi-minimal$/FROM --platform=linux\/${TARGETARCH} registry.access.redhat.com\/ubi8\/ubi-minimal AS final/' "$dockerfile"
}

(
Expand All @@ -102,22 +117,14 @@ modify_dockerfile_for_platform_and_architecture() {
build_docker_image
elif [[ "${OCI_BIN}" == "podman" ]]; then
build_podman_image
push_image_to_kubevirt_repo
else
echo "Invalid OCI_BIN value. It must be either 'docker' or 'podman'."
exit 1
fi
)
)

echo 'Push the image to KubeVirt repo'
(
if [ "${OCI_BIN}" == "podman" ]; then
if [ ! -z ${PUSH_IMAGES} ]; then
podman manifest push "${LINUX_BRIDGE_IMAGE_TAGGED}"
fi
fi
)

if [[ -n "$(docker-utils::check_image_exists "${LINUX_BRIDGE_IMAGE}" "${LINUX_BRIDGE_TAG}")" ]]; then
LINUX_BRIDGE_IMAGE_DIGEST="$(docker-utils::get_image_digest "${LINUX_BRIDGE_IMAGE_TAGGED}" "${LINUX_BRIDGE_IMAGE}")"
else
Expand Down

0 comments on commit b070bc8

Please sign in to comment.