Skip to content

Commit

Permalink
Add mutli arch build and manifest for the operator repo
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed May 31, 2024
1 parent 8c60b32 commit 605f65a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
9 changes: 6 additions & 3 deletions Containerfile.bpfman-agent
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Build the manager binary
FROM golang:1.21 as bpfman-agent-build
ARG TARGETPLATFORM=linux/amd64
ARG BUILDPLATFORM=linux/amd64
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.21 as bpfman-agent-build
ARG TARGETOS
ARG TARGETARCH
ARG TARGETPLATFORM
ARG TARGETARCH=amd64

WORKDIR /usr/src/bpfman-operator

Expand All @@ -28,7 +31,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod ven

# Use the fedora minimal image to reduce the size of the final image but still
# be able to easily install extra packages.
FROM quay.io/fedora/fedora-minimal
FROM --platform=$TARGETPLATFORM quay.io/fedora/fedora-minimal
ARG DNF_CMD="microdnf"

# The full fedora image can be used for debugging purposes. To use it, comment
Expand Down
9 changes: 6 additions & 3 deletions Containerfile.bpfman-operator
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Build the manager binary
FROM golang:1.21 as bpfman-operator-build
ARG TARGETPLATFORM=linux/amd64
ARG BUILDPLATFORM=linux/amd64
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.21 as bpfman-operator-build
ARG TARGETOS
ARG TARGETARCH
ARG TARGETPLATFORM
ARG TARGETARCH=amd64

WORKDIR /usr/src/bpfman-operator

Expand Down Expand Up @@ -32,7 +35,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod ven
# The full fedora image can be used for debugging purposes, but you may need to
# change "microdnf" to "dnf" below to install extra packages.
# FROM fedora:38
FROM quay.io/fedora/fedora-minimal
FROM --platform=$TARGETPLATFORM quay.io/fedora/fedora-minimal
ARG TARGETARCH
WORKDIR /
COPY --from=bpfman-operator-build /usr/src/bpfman-operator/config/bpfman-deployment/daemonset.yaml ./config/bpfman-deployment/daemonset.yaml
Expand Down
52 changes: 45 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.4.1
MULTIARCH_TARGETS ?= amd64

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -71,6 +72,23 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Image building tool (docker / podman)
# Image building tool (docker / podman) - docker is preferred in CI
OCI_BIN_PATH := $(shell which docker 2>/dev/null || which podman)
OCI_BIN ?= $(shell basename ${OCI_BIN_PATH})

# build a single arch target provided as argument
define build_target
echo 'building $(1) for arch $(2)'; \
DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --load --build-arg TARGETPLATFORM=linux/$(2) --build-arg TARGETARCH=$(2) --build-arg BUILDPLATFORM=linux/amd64 -t $(1)-$(2) -f $(3) .;
endef

# push a single arch target image
define push_target
echo 'pushing image $(1)-$(2)'; \
DOCKER_BUILDKIT=1 $(OCI_BIN) push $(1)-$(2);
endef

.PHONY: all
all: build

Expand Down Expand Up @@ -297,15 +315,35 @@ build: fmt ## Build bpfman-operator and bpfman-agent binaries.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: build-images
build-images: ## Build bpfman, bpfman-agent, and bpfman-operator images.
docker build -t ${BPFMAN_OPERATOR_IMG} -f Containerfile.bpfman-operator ./
docker build -t ${BPFMAN_AGENT_IMG} -f Containerfile.bpfman-agent ./
build-images: ## Build bpfman-agent, and bpfman-operator images.
trap 'exit' INT; \
$(foreach target,$(MULTIARCH_TARGETS),$(call build_target,${BPFMAN_OPERATOR_IMG},$(target),Containerfile.bpfman-operator)) \
$(foreach target,$(MULTIARCH_TARGETS),$(call build_target,${BPFMAN_AGENT_IMG},$(target),Containerfile.bpfman-agent))

.PHONY: push-images
push-images: ## Push bpfman, bpfman-agent, bpfman-operator images.
docker push ${BPFMAN_OPERATOR_IMG}
docker push ${BPFMAN_AGENT_IMG}
docker push ${BPFMAN_IMG}
push-images: ## Push bpfman-agent, bpfman-operator images.
trap 'exit' INT; \
$(foreach target,$(MULTIARCH_TARGETS),$(call push_target,${BPFMAN_OPERATOR_IMG},$(target))) \
$(foreach target,$(MULTIARCH_TARGETS),$(call push_target,${BPFMAN_AGENT_IMG},$(target)))

.PHONY: manifest-build
manifest-build: ## Build MULTIARCH_TARGETS manifest for bpfman-operator and bpfman-agent.
echo 'building manifest for $(BPFMAN_OPERATOR_IMG) and $(BPFMAN_AGENT_IMG)'
DOCKER_BUILDKIT=1 $(OCI_BIN) rmi ${BPFMAN_OPERATOR_IMG} -f
DOCKER_BUILDKIT=1 $(OCI_BIN) rmi ${BPFMAN_AGENT_IMG} -f
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest create ${BPFMAN_OPERATOR_IMG} $(foreach target,$(MULTIARCH_TARGETS), --amend ${BPFMAN_OPERATOR_IMG}-$(target));
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest create ${BPFMAN_AGENT_IMG} $(foreach target,$(MULTIARCH_TARGETS), --amend ${BPFMAN_AGENT_IMG}-$(target));

.PHONY: manifest-push
manifest-push: ## Push MULTIARCH_TARGETS manifest for bpfman-operator and bpfman-agent.
@echo 'publish manifest for $(BPFMAN_OPERATOR_IMG) and $(BPFMAN_AGENT_IMG)'
ifeq (${OCI_BIN}, docker)
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${BPFMAN_OPERATOR_IMG};
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${BPFMAN_AGENT_IMG};
else
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${BPFMAN_OPERATOR_IMG} docker://${BPFMAN_OPERATOR_IMG};
DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${BPFMAN_AGENT_IMG} docker://${BPFMAN_AGENT_IMG};
endif

.PHONY: load-images-kind
load-images-kind: ## Load bpfman, bpfman-agent, and bpfman-operator images into the running local kind devel cluster.
Expand Down

0 comments on commit 605f65a

Please sign in to comment.