-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multi platform support #444
Merged
kubevirt-bot
merged 2 commits into
k8snetworkplumbingwg:main
from
ashokpariya0:add-multi-platform-support
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
ARG BUILD_ARCH=amd64 | ||
FROM --platform=linux/${BUILD_ARCH} quay.io/centos/centos:stream9 AS builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ENV TARGETOS=${TARGETOS:-linux} | ||
ENV TARGETARCH=${TARGETARCH:-amd64} | ||
|
||
ARG BUILDOS | ||
ARG BUILDARCH | ||
ENV BUILDOS=${BUILDOS:-linux} | ||
ENV BUILDARCH=${BUILDARCH:-amd64} | ||
|
||
WORKDIR /go/src/kubemacpool | ||
RUN dnf install -y wget && dnf clean all | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN GO_VERSION=$(sed -En 's/^go +(.*)$/\1/p' go.mod) && \ | ||
wget -q https://dl.google.com/go/go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz && \ | ||
tar -C /usr/local -xzf go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz && \ | ||
rm go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz | ||
|
||
ENV PATH=$PATH:/usr/local/go/bin | ||
RUN go mod download | ||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o build/_output/bin/manager github.com/k8snetworkplumbingwg/kubemacpool/cmd/manager | ||
|
||
# Copy the controller-manager into a thin image | ||
FROM registry.access.redhat.com/ubi9/ubi-minimal | ||
COPY _output/bin/manager / | ||
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi9/ubi-minimal | ||
COPY --from=builder /go/src/kubemacpool/build/_output/bin/manager / | ||
ENTRYPOINT ["/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$ARCH" ] || [ -z "$PLATFORMS" ] || [ -z "$KUBEMACPOOL_IMAGE_TAGGED" ] || [ -z "$KUBEMACPOOL_IMAGE_GIT_TAGGED" ] || [ -z "$DOCKER_BUILDER" ] || [ -z "$REGISTRY" ]; then | ||
echo "Error: ARCH, PLATFORMS, KUBEMACPOOL_IMAGE_TAGGED, KUBEMACPOOL_IMAGE_GIT_TAGGED and DOCKER_BUILDER must be set." | ||
exit 1 | ||
fi | ||
|
||
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS" | ||
|
||
if [[ "${REGISTRY}" == localhost* || "${REGISTRY}" == 127.0.0.1* ]]; then | ||
echo "Local registry detected (${REGISTRY}). Skipping $KUBEMACPOOL_IMAGE_GIT_TAGGED handling."; | ||
BUILD_ARGS="--build-arg BUILD_ARCH=$ARCH -f build/Dockerfile -t $KUBEMACPOOL_IMAGE_TAGGED . --push" | ||
else | ||
if skopeo inspect docker://${KUBEMACPOOL_IMAGE_GIT_TAGGED} >/dev/null 2>&1; then | ||
echo "Tag '${KUBEMACPOOL_IMAGE_GIT_TAGGED}' already exists in the registry. Skipping tagging with ${KUBEMACPOOL_IMAGE_GIT_TAGGED}." | ||
BUILD_ARGS="--build-arg BUILD_ARCH=$ARCH -f build/Dockerfile -t $KUBEMACPOOL_IMAGE_TAGGED . --push" | ||
else | ||
BUILD_ARGS="--build-arg BUILD_ARCH=$ARCH -f build/Dockerfile -t $KUBEMACPOOL_IMAGE_TAGGED -t $KUBEMACPOOL_IMAGE_GIT_TAGGED . --push" | ||
fi | ||
fi | ||
|
||
if [ ${#PLATFORM_LIST[@]} -eq 1 ]; then | ||
docker build --platform "$PLATFORMS" $BUILD_ARGS | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$ARCH" ] || [ -z "$PLATFORMS" ] || [ -z "$KUBEMACPOOL_IMAGE_TAGGED" ] || [ -z "$KUBEMACPOOL_IMAGE_GIT_TAGGED" ]; then | ||
echo "Error: ARCH, PLATFORMS, KUBEMACPOOL_IMAGE_TAGGED, and KUBEMACPOOL_IMAGE_GIT_TAGGED must be set." | ||
exit 1 | ||
fi | ||
|
||
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS" | ||
|
||
# Remove any existing manifest and image | ||
podman manifest rm "${KUBEMACPOOL_IMAGE_TAGGED}" 2>/dev/null || true | ||
podman manifest rm "${KUBEMACPOOL_IMAGE_GIT_TAGGED}" 2>/dev/null || true | ||
RamLavi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
podman rmi "${KUBEMACPOOL_IMAGE_TAGGED}" 2>/dev/null || true | ||
podman rmi "${KUBEMACPOOL_IMAGE_GIT_TAGGED}" 2>/dev/null || true | ||
podman rmi $(podman images --filter "dangling=true" -q) 2>/dev/null || true | ||
|
||
podman manifest create "${KUBEMACPOOL_IMAGE_TAGGED}" | ||
|
||
for platform in "${PLATFORM_LIST[@]}"; do | ||
podman build \ | ||
--build-arg BUILD_ARCH="$ARCH" \ | ||
--platform "$platform" \ | ||
--manifest "${KUBEMACPOOL_IMAGE_TAGGED}" \ | ||
-f build/Dockerfile . | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
ARCH=$1 | ||
PLATFORMS=$2 | ||
KUBEMACPOOL_IMAGE_TAGGED=$3 | ||
KUBEMACPOOL_IMAGE_GIT_TAGGED=$4 | ||
DOCKER_BUILDER=$5 | ||
OCI_BIN=$6 | ||
REGISTRY=$7 | ||
|
||
if [ "$OCI_BIN" == "podman" ]; then | ||
ARCH=$ARCH PLATFORMS=$PLATFORMS KUBEMACPOOL_IMAGE_TAGGED=$KUBEMACPOOL_IMAGE_TAGGED KUBEMACPOOL_IMAGE_GIT_TAGGED=$KUBEMACPOOL_IMAGE_GIT_TAGGED ./hack/build-kubemacpool-podman.sh | ||
elif [ "$OCI_BIN" == "docker" ]; then | ||
ARCH=$ARCH PLATFORMS=$PLATFORMS KUBEMACPOOL_IMAGE_TAGGED=$KUBEMACPOOL_IMAGE_TAGGED KUBEMACPOOL_IMAGE_GIT_TAGGED=$KUBEMACPOOL_IMAGE_GIT_TAGGED DOCKER_BUILDER=$DOCKER_BUILDER REGISTRY=$REGISTRY ./hack/build-kubemacpool-docker.sh | ||
else | ||
echo "Unsupported OCI_BIN value: $OCI_BIN" | ||
exit 1 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
check_buildx() { | ||
export DOCKER_CLI_EXPERIMENTAL=enabled | ||
|
||
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) | ||
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 | ||
} | ||
|
||
create_or_use_buildx_builder() { | ||
local builder_name=$1 | ||
if [ -z "$builder_name" ]; then | ||
echo "Error: Builder name is required." | ||
exit 1 | ||
fi | ||
|
||
check_buildx | ||
|
||
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}" && \ | ||
grep -q "linux/arm64" <<<"${current_builder}" && \ | ||
grep -q "linux/s390x" <<<"${current_builder}"; then | ||
echo "The current builder already has multi-architecture support (amd64, arm64, s390x)." | ||
echo "Skipping setup as the builder is already configured correctly." | ||
exit 0 | ||
fi | ||
|
||
# Check if the builder already exists by parsing the output of `docker buildx ls` | ||
# We check if the builder_name appears in the list of active builders | ||
existing_builder=$(docker buildx ls | grep -w "$builder_name" | awk '{print $1}') | ||
|
||
if [ -n "$existing_builder" ]; then | ||
echo "Builder '$builder_name' already exists." | ||
echo "Using existing builder '$builder_name'." | ||
docker buildx use "$builder_name" | ||
else | ||
echo "Creating a new Docker Buildx builder: $builder_name" | ||
docker buildx create --driver-opt network=host --use --name "$builder_name" | ||
echo "The new builder '$builder_name' has been created and set as active." | ||
fi | ||
} | ||
|
||
if [ $# -eq 1 ]; then | ||
create_or_use_buildx_builder "$1" | ||
else | ||
echo "Usage: $0 <builder_name>" | ||
echo "Example: $0 mybuilder" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a PR that set platforms=all on the release right ? (unless there is already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oshoval I don't see any post-submit Prow jobs that handle the release for the macpool CNI image.
@RamLavi Could you please let me know how the image is being built and pushed to quay.io?
Also, please note that we need to set PLATFORMS=all before running make build to ensure the image is built with multi-platform support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github/ci/prow-deploy/files/jobs/k8snetworkplumbingwg/kubemacpool/kubemacpool-postsubmits.yaml ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks! I found it here: kubemacpool-postsubmits.yaml.
I’ll go ahead and submit the PR for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, PR link: kubevirt/project-infra#3855