Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ MEMBER_NET_CONTROLLER_MANAGER_IMAGE_NAME ?= member-net-controller-manager
MCS_CONTROLLER_MANAGER_IMAGE_NAME ?= mcs-controller-manager
NET_CRD_INSTALLER_IMAGE_NAME ?= net-crd-installer

TARGET_OS ?= linux
TARGET_ARCH ?= amd64
AUTO_DETECT_ARCH ?= TRUE

# Auto-detect system architecture if it is allowed and the necessary commands are available on the system.
ifeq ($(AUTO_DETECT_ARCH), TRUE)
ARCH_CMD_INSTALLED := $(shell command -v arch 2>/dev/null)
ifdef ARCH_CMD_INSTALLED
TARGET_ARCH := $(shell arch)
# The arch command may return arch strings that are aliases of expected TARGET_ARCH values;
# do the mapping here.
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
TARGET_ARCH := amd64
else ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),aarch64 arm))
TARGET_ARCH := arm64
endif
$(info Auto-detected system architecture: $(TARGET_ARCH))
endif
endif

# Note (chenyu1): switch to the `plain` progress type to see the full outputs in the docker build
# progress.
BUILDKIT_PROGRESS_TYPE ?= auto


# Directories
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TOOLS_DIR := hack/tools
Expand Down Expand Up @@ -196,9 +221,22 @@ push:

# By default, docker buildx create will pull image moby/buildkit:buildx-stable-1 and hit the too many requests error.
.PHONY: docker-buildx-builder
# Note (chenyu1): the step below sets up emulation for building/running non-native binaries on the host. The original
# setup assumes that the Makefile is always run on an x86_64 platform, and adds support for non-x86_64 hosts. Here
# we keep the original setup if the build target is x86_64 platforms (default) for compatibility reasons, but will switch to
# a more general setup for non-x86_64 hosts.
#
# On some systems the emulation setup might not work at all (e.g., macOS on Apple Silicon -> Rosetta 2 will be used
# by Docker Desktop as the default emulation option for AMD64 on ARM64 container compatibility).
docker-buildx-builder:
@if ! docker buildx ls | grep $(BUILDX_BUILDER_NAME); then \
docker run --rm --privileged mcr.microsoft.com/mirror/docker/multiarch/qemu-user-static:$(QEMU_VERSION) --reset -p yes; \
if [ "$(TARGET_ARCH)" = "amd64" ] ; then \
echo "The target is an x86_64 platform; setting up emulation for other known architectures"; \
docker run --rm --privileged mcr.microsoft.com/mirror/docker/multiarch/qemu-user-static:$(QEMU_VERSION) --reset -p yes; \
else \
echo "Setting up emulation for known architectures"; \
docker run --rm --privileged tonistiigi/binfmt --install all; \
fi ;\
docker buildx create --driver-opt image=mcr.microsoft.com/oss/v2/moby/buildkit:$(BUILDKIT_VERSION) --name $(BUILDX_BUILDER_NAME) --use; \
docker buildx inspect $(BUILDX_BUILDER_NAME) --bootstrap; \
fi
Expand All @@ -208,27 +246,36 @@ docker-build-hub-net-controller-manager: docker-buildx-builder vendor
docker buildx build \
--file docker/$(HUB_NET_CONTROLLER_MANAGER_IMAGE_NAME).Dockerfile \
--output=$(OUTPUT_TYPE) \
--platform="linux/amd64" \
--platform=$(TARGET_OS)/$(TARGET_ARCH) \
--pull \
--tag $(REGISTRY)/$(HUB_NET_CONTROLLER_MANAGER_IMAGE_NAME):$(HUB_NET_CONTROLLER_MANAGER_IMAGE_VERSION) .
--tag $(REGISTRY)/$(HUB_NET_CONTROLLER_MANAGER_IMAGE_NAME):$(HUB_NET_CONTROLLER_MANAGER_IMAGE_VERSION) \
--progress=$(BUILDKIT_PROGRESS_TYPE) \
--build-arg GOARCH=$(TARGET_ARCH) \
--build-arg GOOS=$(TARGET_OS) .

.PHONY: docker-build-member-net-controller-manager
docker-build-member-net-controller-manager: docker-buildx-builder vendor
docker buildx build \
--file docker/$(MEMBER_NET_CONTROLLER_MANAGER_IMAGE_NAME).Dockerfile \
--output=$(OUTPUT_TYPE) \
--platform="linux/amd64" \
--platform=$(TARGET_OS)/$(TARGET_ARCH) \
--pull \
--tag $(REGISTRY)/$(MEMBER_NET_CONTROLLER_MANAGER_IMAGE_NAME):$(MEMBER_NET_CONTROLLER_MANAGER_IMAGE_VERSION) .
--tag $(REGISTRY)/$(MEMBER_NET_CONTROLLER_MANAGER_IMAGE_NAME):$(MEMBER_NET_CONTROLLER_MANAGER_IMAGE_VERSION) \
--progress=$(BUILDKIT_PROGRESS_TYPE) \
--build-arg GOARCH=$(TARGET_ARCH) \
--build-arg GOOS=$(TARGET_OS) .

.PHONY: docker-build-mcs-controller-manager
docker-build-mcs-controller-manager: docker-buildx-builder vendor
docker buildx build \
--file docker/$(MCS_CONTROLLER_MANAGER_IMAGE_NAME).Dockerfile \
--output=$(OUTPUT_TYPE) \
--platform="linux/amd64" \
--platform=$(TARGET_OS)/$(TARGET_ARCH) \
--pull \
--tag $(REGISTRY)/$(MCS_CONTROLLER_MANAGER_IMAGE_NAME):$(MCS_CONTROLLER_MANAGER_IMAGE_VERSION) .
--tag $(REGISTRY)/$(MCS_CONTROLLER_MANAGER_IMAGE_NAME):$(MCS_CONTROLLER_MANAGER_IMAGE_VERSION) \
--progress=$(BUILDKIT_PROGRESS_TYPE) \
--build-arg GOARCH=$(TARGET_ARCH) \
--build-arg GOOS=$(TARGET_OS) .

.PHONY: docker-build-net-crd-installer
docker-build-net-crd-installer: docker-buildx-builder vendor
Expand Down
8 changes: 5 additions & 3 deletions docker/hub-net-controller-manager.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build the hub-net-controller-manager binary
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.24.6 as builder

ARG GOOS=linux
ARG GOARCH=amd64

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -15,9 +18,8 @@ COPY api/ api/
COPY pkg/ pkg/

# Build with CGO enabled and GOEXPERIMENT=systemcrypto for internal usage
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o hub-net-controller-manager main.go
RUN echo "Building images with GOOS=$GOOS GOARCH=$GOARCH"
RUN CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o hub-net-controller-manager main.go

# Use Azure Linux distroless base image to package hub-net-controller-manager binary
# Refer to https://mcr.microsoft.com/en-us/artifact/mar/azurelinux/distroless/base/about for more details
Expand Down
8 changes: 5 additions & 3 deletions docker/mcs-controller-manager.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build the mcs-controller-manager binary
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.24.6 as builder

ARG GOOS=linux
ARG GOARCH=amd64

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -15,9 +18,8 @@ COPY api/ api/
COPY pkg/ pkg/

# Build with CGO enabled and GOEXPERIMENT=systemcrypto for internal usage
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o mcs-controller-manager main.go
RUN echo "Building images with GOOS=$GOOS GOARCH=$GOARCH"
RUN CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o mcs-controller-manager main.go

# Use Azure Linux distroless base image to package mcs-controller-manager binary
# Refer to https://mcr.microsoft.com/en-us/artifact/mar/azurelinux/distroless/base/about for more details
Expand Down
8 changes: 5 additions & 3 deletions docker/member-net-controller-manager.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build the member-net-controller-manager binary
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.24.6 as builder

ARG GOOS=linux
ARG GOARCH=amd64

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -15,9 +18,8 @@ COPY api/ api/
COPY pkg/ pkg/

# Build with CGO enabled and GOEXPERIMENT=systemcrypto for internal usage
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o member-net-controller-manager main.go
RUN echo "Building images with GOOS=$GOOS GOARCH=$GOARCH"
RUN CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o member-net-controller-manager main.go

# Use Azure Linux distroless base image to package member-net-controller-manager binary
# Refer to https://mcr.microsoft.com/en-us/artifact/mar/azurelinux/distroless/base/about for more details
Expand Down
8 changes: 5 additions & 3 deletions docker/net-crd-installer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build the net-crd-installer binary
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.24.6 AS builder

ARG GOOS=linux
ARG GOARCH=amd64

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -12,10 +15,9 @@ RUN go mod download
# Copy the go source
COPY cmd/net-crd-installer/ cmd/net-crd-installer/

ARG TARGETARCH

# Build with CGO enabled and GOEXPERIMENT=systemcrypto for internal usage
RUN CGO_ENABLED=1 GOOS=linux GOARCH=${TARGETARCH} GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o net-crd-installer cmd/net-crd-installer/main.go
RUN echo "Building images with GOOS=linux GOARCH=$GOARCH"
RUN CGO_ENABLED=1 GOOS=linux GOARCH=$GOARCH GOEXPERIMENT=systemcrypto GO111MODULE=on go build -o net-crd-installer cmd/net-crd-installer/main.go

# Use Azure Linux distroless base image to package net-crd-installer binary
# Refer to https://mcr.microsoft.com/en-us/artifact/mar/azurelinux/distroless/base/about for more details
Expand Down
Loading