Skip to content

Commit b070bc8

Browse files
committed
address review comments
1 parent 8f57b9d commit b070bc8

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

hack/components/bump-linux-bridge.sh

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ echo 'Build container image with linux-bridge binaries'
2727
LINUX_BRIDGE_TAR_CONTAINER_DIR=/usr/src/github.com/containernetworking/plugins/bin
2828
LINUX_BRIDGE_IMAGE=quay.io/kubevirt/cni-default-plugins
2929
LINUX_BRIDGE_IMAGE_TAGGED=${LINUX_BRIDGE_IMAGE}:${LINUX_BRIDGE_TAG}
30-
ARCH=$(uname -m | sed 's/x86_64/amd64/')
31-
PLATFORMS="linux/amd64,linux/s390x"
3230
DOCKER_BUILDER="${DOCKER_BUILDER:-linux-bridge-docker-builder}"
31+
# By default, the build will be based on the host architecture.
32+
# To build for other platforms, you can:
33+
# 1. Export all supported platforms: export PLATFORMS=all
34+
# 2. Or specify specific platforms: export PLATFORMS=linux/amd64,linux/arm64
35+
PLATFORM_LIST="linux/amd64,linux/s390x,linux/arm64"
36+
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
37+
[ -z "$PLATFORMS" ] && PLATFORMS="linux/${ARCH}"
38+
[ "$PLATFORMS" == "all" ] && PLATFORMS="${PLATFORM_LIST}"
3339
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS"
3440

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

7278
build_docker_image() {
73-
docker buildx build --platform "${PLATFORMS}" --build-arg BUILD_ARCH="$ARCH" -t "${LINUX_BRIDGE_IMAGE_TAGGED}" . --push
79+
docker buildx build --platform "${PLATFORMS}" -t "${LINUX_BRIDGE_IMAGE_TAGGED}" . --push
7480
docker buildx rm "$DOCKER_BUILDER"
7581
}
7682

7783
build_podman_image() {
78-
podman manifest rm "${LINUX_BRIDGE_IMAGE_TAGGED}" || true
79-
podman rmi "${LINUX_BRIDGE_IMAGE_TAGGED}" || true
84+
podman manifest rm "${LINUX_BRIDGE_IMAGE_TAGGED}" 2>/dev/null || true
85+
podman rmi "${LINUX_BRIDGE_IMAGE_TAGGED}" 2>/dev/null || true
8086
podman manifest create "${LINUX_BRIDGE_IMAGE_TAGGED}"
8187

8288
for platform in "${PLATFORM_LIST[@]}"; do
83-
podman build --no-cache --build-arg BUILD_ARCH="$ARCH" --platform "$platform" --manifest "${LINUX_BRIDGE_IMAGE_TAGGED}" .
89+
podman build --platform "$platform" --manifest "${LINUX_BRIDGE_IMAGE_TAGGED}" .
8490
done
8591
}
8692

93+
push_image_to_kubevirt_repo() {
94+
echo 'Push the image to KubeVirt repo'
95+
if [ "${OCI_BIN}" == "podman" ]; then
96+
if [ ! -z "${PUSH_IMAGES}" ]; then
97+
podman manifest push "${LINUX_BRIDGE_IMAGE_TAGGED}"
98+
fi
99+
fi
100+
}
101+
87102
modify_dockerfile_for_platform_and_architecture() {
88103
local dockerfile="$1"
89104
# Modify Dockerfile to set platform and architecture
90-
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"
105+
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"
91106
sed -i 's|RUN GOFLAGS=-mod=vendor ./build_linux.sh|RUN GOFLAGS=-mod=vendor GOARCH=${TARGETARCH} GOOS=${TARGETOS} ./build_linux.sh|' "$dockerfile"
92-
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"
107+
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"
93108
}
94109

95110
(
@@ -102,22 +117,14 @@ modify_dockerfile_for_platform_and_architecture() {
102117
build_docker_image
103118
elif [[ "${OCI_BIN}" == "podman" ]]; then
104119
build_podman_image
120+
push_image_to_kubevirt_repo
105121
else
106122
echo "Invalid OCI_BIN value. It must be either 'docker' or 'podman'."
107123
exit 1
108124
fi
109125
)
110126
)
111127

112-
echo 'Push the image to KubeVirt repo'
113-
(
114-
if [ "${OCI_BIN}" == "podman" ]; then
115-
if [ ! -z ${PUSH_IMAGES} ]; then
116-
podman manifest push "${LINUX_BRIDGE_IMAGE_TAGGED}"
117-
fi
118-
fi
119-
)
120-
121128
if [[ -n "$(docker-utils::check_image_exists "${LINUX_BRIDGE_IMAGE}" "${LINUX_BRIDGE_TAG}")" ]]; then
122129
LINUX_BRIDGE_IMAGE_DIGEST="$(docker-utils::get_image_digest "${LINUX_BRIDGE_IMAGE_TAGGED}" "${LINUX_BRIDGE_IMAGE}")"
123130
else

0 commit comments

Comments
 (0)