-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from ashokpariya0/add-multiplatform-support
Add multi-platform support for macvtap cni image builds.
- Loading branch information
Showing
6 changed files
with
137 additions
and
8 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
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,12 +1,20 @@ | ||
# Multi-stage dockerfile building a container image with both binaries included | ||
|
||
FROM quay.io/projectquay/golang:1.20 as builder | ||
FROM --platform=$BUILDPLATFORM quay.io/projectquay/golang:1.20 AS builder | ||
ENV GOPATH=/go | ||
WORKDIR /go/src/github.com/kubevirt/macvtap-cni | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ENV TARGETOS=${TARGETOS:-linux} | ||
ENV TARGETARCH=${TARGETARCH:-amd64} | ||
|
||
ENV GOOS=${TARGETOS} | ||
ENV GOARCH=${TARGETARCH} | ||
|
||
COPY . . | ||
RUN GOOS=linux CGO_ENABLED=0 go build -o /macvtap-deviceplugin github.com/kubevirt/macvtap-cni/cmd/deviceplugin | ||
RUN GOOS=linux CGO_ENABLED=0 go build -o /macvtap-cni github.com/kubevirt/macvtap-cni/cmd/cni | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi-minimal | ||
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi8/ubi-minimal | ||
COPY --from=builder /macvtap-deviceplugin /macvtap-deviceplugin | ||
COPY --from=builder /macvtap-cni /macvtap-cni |
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,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$PLATFORMS" ] || [ -z "$MACVTAP_IMAGE_TAGGED" ]; then | ||
echo "Error: PLATFORMS, and MACVTAP_IMAGE_TAGGED must be set." | ||
exit 1 | ||
fi | ||
|
||
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS" | ||
|
||
BUILD_ARGS="-f cmd/Dockerfile -t $MACVTAP_IMAGE_TAGGED . --push" | ||
|
||
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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$PLATFORMS" ] || [ -z "$MACVTAP_IMAGE_TAGGED" ]; then | ||
echo "Error: PLATFORMS, and MACVTAP_IMAGE_TAGGED must be set." | ||
exit 1 | ||
fi | ||
|
||
IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS" | ||
|
||
podman manifest rm "${MACVTAP_IMAGE_TAGGED}" 2>/dev/null || true | ||
podman manifest rm "${MARKER_IMAGE_GIT_TAGGED}" 2>/dev/null || true | ||
podman rmi "${MACVTAP_IMAGE_TAGGED}" 2>/dev/null || true | ||
podman rmi "${MARKER_IMAGE_GIT_TAGGED}" 2>/dev/null || true | ||
|
||
podman manifest create "${MACVTAP_IMAGE_TAGGED}" | ||
|
||
for platform in "${PLATFORM_LIST[@]}"; do | ||
podman build \ | ||
--platform "$platform" \ | ||
--manifest "${MACVTAP_IMAGE_TAGGED}" \ | ||
-f cmd/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,56 @@ | ||
#!/usr/bin/env 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 |