11REGISTRY ?= ghcr.io
2- KIND_IMAGE ?= kindest/node:v1.31.0
2+ KIND_IMAGE ?= kindest/node:v1.33.4
33ifndef TAG
44 TAG ?= $(shell git rev-parse --short=7 HEAD)
55endif
@@ -11,6 +11,30 @@ HUB_AGENT_IMAGE_NAME ?= hub-agent
1111MEMBER_AGENT_IMAGE_NAME ?= member-agent
1212REFRESH_TOKEN_IMAGE_NAME := refresh-token
1313
14+ TARGET_OS ?= linux
15+ TARGET_ARCH ?= amd64
16+ AUTO_DETECT_ARCH ?= TRUE
17+
18+ # Auto-detect system architecture if it is allowed and the necessary commands are available on the system.
19+ ifeq ($(AUTO_DETECT_ARCH ) , TRUE)
20+ ARCH_CMD_INSTALLED := $(shell command -v arch 2>/dev/null)
21+ ifdef ARCH_CMD_INSTALLED
22+ TARGET_ARCH := $(shell arch)
23+ # The arch command may return arch strings that are aliases of expected TARGET_ARCH values;
24+ # do the mapping here.
25+ ifeq ($(TARGET_ARCH ) ,$(filter $(TARGET_ARCH ) ,x86_64) )
26+ TARGET_ARCH := amd64
27+ else ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),aarch64 arm))
28+ TARGET_ARCH := arm64
29+ endif
30+ $(info Auto-detected system architecture : $(TARGET_ARCH ) )
31+ endif
32+ endif
33+
34+ # Note (chenyu1): switch to the `plain` progress type to see the full outputs in the docker build
35+ # progress.
36+ BUILDKIT_PROGRESS_TYPE ?= auto
37+
1438KUBECONFIG ?= $(HOME ) /.kube/config
1539HUB_SERVER_URL ?= https://172.19.0.2:6443
1640
@@ -137,6 +161,8 @@ test: manifests generate fmt vet local-unit-test integration-test## Run tests.
137161# # workaround to bypass the pkg/controllers/workv1alpha1 tests failure
138162# # rollout controller tests need a bit longer to complete, so we increase the timeout
139163# #
164+ # Set up the timeout parameters as some of the test lengths have exceeded the default 10 minute mark.
165+ # TO-DO (chenyu1): enable parallelization for single package integration tests.
140166.PHONY : local-unit-test
141167local-unit-test : $(ENVTEST ) # # Run tests.
142168 export CGO_ENABLED=1 && \
@@ -285,9 +311,22 @@ push:
285311
286312# By default, docker buildx create will pull image moby/buildkit:buildx-stable-1 and hit the too many requests error
287313.PHONY : docker-buildx-builder
314+ # Note (chenyu1): the step below sets up emulation for building/running non-native binaries on the host. The original
315+ # setup assumes that the Makefile is always run on an x86_64 platform, and adds support for non-x86_64 hosts. Here
316+ # we keep the original setup if the build target is x86_64 platforms (default) for compatibility reasons, but will switch to
317+ # a more general setup for non-x86_64 hosts.
318+ #
319+ # On some systems the emulation setup might not work at all (e.g., macOS on Apple Silicon -> Rosetta 2 will be used
320+ # by Docker Desktop as the default emulation option for AMD64 on ARM64 container compatibility).
288321docker-buildx-builder :
289322 @if ! docker buildx ls | grep $(BUILDX_BUILDER_NAME ) ; then \
290- docker run --rm --privileged mcr.microsoft.com/mirror/docker/multiarch/qemu-user-static:$(QEMU_VERSION ) --reset -p yes; \
323+ if [ " $( TARGET_ARCH) " = " amd64" ] ; then \
324+ echo " The target is an x86_64 platform; setting up emulation for other known architectures" ; \
325+ docker run --rm --privileged mcr.microsoft.com/mirror/docker/multiarch/qemu-user-static:$(QEMU_VERSION ) --reset -p yes; \
326+ else \
327+ echo " Setting up emulation for known architectures" ; \
328+ docker run --rm --privileged tonistiigi/binfmt --install all; \
329+ fi ; \
291330 docker buildx create --driver-opt image=mcr.microsoft.com/oss/v2/moby/buildkit:$(BUILDKIT_VERSION ) --name $(BUILDX_BUILDER_NAME ) --use; \
292331 docker buildx inspect $(BUILDX_BUILDER_NAME ) --bootstrap; \
293332 fi
@@ -297,27 +336,36 @@ docker-build-hub-agent: docker-buildx-builder
297336 docker buildx build \
298337 --file docker/$(HUB_AGENT_IMAGE_NAME ) .Dockerfile \
299338 --output=$(OUTPUT_TYPE ) \
300- --platform=" linux/amd64 " \
339+ --platform=$( TARGET_OS ) / $( TARGET_ARCH ) \
301340 --pull \
302- --tag $(REGISTRY ) /$(HUB_AGENT_IMAGE_NAME ) :$(HUB_AGENT_IMAGE_VERSION ) .
341+ --tag $(REGISTRY ) /$(HUB_AGENT_IMAGE_NAME ) :$(HUB_AGENT_IMAGE_VERSION ) \
342+ --progress=$(BUILDKIT_PROGRESS_TYPE ) \
343+ --build-arg GOARCH=$(TARGET_ARCH ) \
344+ --build-arg GOOS=$(TARGET_OS ) .
303345
304346.PHONY : docker-build-member-agent
305347docker-build-member-agent : docker-buildx-builder
306348 docker buildx build \
307349 --file docker/$(MEMBER_AGENT_IMAGE_NAME ) .Dockerfile \
308350 --output=$(OUTPUT_TYPE ) \
309- --platform=" linux/amd64 " \
351+ --platform=$( TARGET_OS ) / $( TARGET_ARCH ) \
310352 --pull \
311- --tag $(REGISTRY ) /$(MEMBER_AGENT_IMAGE_NAME ) :$(MEMBER_AGENT_IMAGE_VERSION ) .
353+ --tag $(REGISTRY ) /$(MEMBER_AGENT_IMAGE_NAME ) :$(MEMBER_AGENT_IMAGE_VERSION ) \
354+ --progress=$(BUILDKIT_PROGRESS_TYPE ) \
355+ --build-arg GOARCH=$(TARGET_ARCH ) \
356+ --build-arg GOOS=$(TARGET_OS ) .
312357
313358.PHONY : docker-build-refresh-token
314359docker-build-refresh-token : docker-buildx-builder
315360 docker buildx build \
316361 --file docker/$(REFRESH_TOKEN_IMAGE_NAME ) .Dockerfile \
317362 --output=$(OUTPUT_TYPE ) \
318- --platform=" linux/amd64 " \
363+ --platform=$( TARGET_OS ) / $( TARGET_ARCH ) \
319364 --pull \
320- --tag $(REGISTRY ) /$(REFRESH_TOKEN_IMAGE_NAME ) :$(REFRESH_TOKEN_IMAGE_VERSION ) .
365+ --tag $(REGISTRY ) /$(REFRESH_TOKEN_IMAGE_NAME ) :$(REFRESH_TOKEN_IMAGE_VERSION ) \
366+ --progress=$(BUILDKIT_PROGRESS_TYPE ) \
367+ --build-arg GOARCH=$(TARGET_ARCH ) \
368+ --build-arg GOOS=${TARGET_OS} .
321369
322370# # -----------------------------------
323371# # Cleanup
0 commit comments