-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable multi-platform support for operator image builds
These changes enable building and pushing container images for multiple platforms (amd64, s390x, arm64) from a single Dockerfile. Enhanced multi-platform support in the build process by adding a PLATFORMS argument in the Makefile for amd64, s390x, and arm64 architectures. Updated the docker-build-operator target to support builds with docker buildx and podman, and added new targets for creating Docker Buildx builders and pushing multi-platform images. Signed-off-by: Ashok Pariya <[email protected]>
- Loading branch information
1 parent
fca381a
commit a853967
Showing
4 changed files
with
147 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,6 @@ | |
_kubevirtci | ||
|
||
# No need for source code is already compiled | ||
pkg | ||
cmd | ||
tools | ||
vendor | ||
docs | ||
|
||
|
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
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,61 @@ | ||
#!/bin/bash | ||
|
||
check_buildx() { | ||
export DOCKER_CLI_EXPERIMENTAL=enabled | ||
|
||
# If there is no buildx let's install it | ||
if ! docker buildx > /dev/null 2>&1; then | ||
mkdir -p ~/.docker/cli-plugins | ||
curl -L https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64 --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})" | ||
|
||
# Check if the current builder has multi-architecture support and is not using the "docker" driver | ||
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 | ||
# If the builder does not exist, create a new one | ||
echo "Creating a new Docker Buildx builder: $builder_name" | ||
docker buildx create --driver-opt network=host --use --name "$builder_name" | ||
|
||
# Verify the new builder is set as active | ||
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 |