@@ -7,6 +7,13 @@ GCP_BUCKET_PREFIX ?= $(GCP_PROJECT_ID)-
77HOSTNAME := $(shell hostname 2> /dev/null || hostnamectl hostname 2> /dev/null)
88$(if $(HOSTNAME ) ,,$(error Failed to determine hostname : both 'hostname' and 'hostnamectl' failed))
99
10+ # Architecture for builds. Defaults to local arch; override for cross-compilation
11+ # (e.g., BUILD_ARCH=amd64 make build from an ARM64 host).
12+ BUILD_ARCH ?= $(shell go env GOARCH)
13+ # Docker platform string. Override for multi-arch builds:
14+ # BUILD_PLATFORM=linux/amd64,linux/arm64 make build
15+ BUILD_PLATFORM ?= linux/$(BUILD_ARCH )
16+
1017.PHONY : init
1118init :
1219 brew install protobuf
@@ -18,18 +25,18 @@ generate:
1825.PHONY : build
1926build :
2027 $(eval COMMIT_SHA := $(shell git rev-parse --short HEAD) )
21- @docker build --platform linux/amd64 --output=bin --build-arg COMMIT_SHA=" $( COMMIT_SHA) " -f ./Dockerfile ..
28+ @docker build --platform $( BUILD_PLATFORM ) --output=bin --build-arg COMMIT_SHA=" $( COMMIT_SHA) " -f ./Dockerfile ..
2229
2330.PHONY : build-local
24- build-local :
31+ build-local : fetch-busybox
2532 # Allow for passing commit sha directly for docker builds
2633 $(eval COMMIT_SHA ?= $(shell git rev-parse --short HEAD) )
27- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/orchestrator -ldflags " -X=main.commitSHA=$( COMMIT_SHA) " .
28- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/clean-nfs-cache -ldflags " -X=main.commitSHA=$( COMMIT_SHA) " ./cmd/clean-nfs-cache
34+ CGO_ENABLED=1 GOOS=linux GOARCH=$( BUILD_ARCH ) go build -o bin/orchestrator -ldflags " -X=main.commitSHA=$( COMMIT_SHA) " .
35+ CGO_ENABLED=1 GOOS=linux GOARCH=$( BUILD_ARCH ) go build -o bin/clean-nfs-cache -ldflags " -X=main.commitSHA=$( COMMIT_SHA) " ./cmd/clean-nfs-cache
2936
3037.PHONY : build-debug
31- build-debug :
32- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -race -gcflags=all=" -N -l" -o bin/orchestrator .
38+ build-debug : fetch-busybox
39+ CGO_ENABLED=1 GOOS=linux GOARCH=$( BUILD_ARCH ) go build -race -gcflags=all=" -N -l" -o bin/orchestrator .
3340
3441.PHONY : run-debug
3542run-debug :
@@ -105,7 +112,7 @@ test-docker:
105112 @cp -r ../shared .shared/
106113 @rm -rf .clickhouse/
107114 @cp -r ../clickhouse .clickhouse/
108- @docker build --platform linux/amd64 -f test.Dockerfile --no-cache-filter runner --progress=plain -t orchestrator-test .
115+ @docker build --platform $( BUILD_PLATFORM ) -f test.Dockerfile --no-cache-filter runner --progress=plain -t orchestrator-test .
109116 @rm -rf .shared/
110117 @rm -rf .clickhouse/
111118 @echo " Done"
@@ -125,6 +132,34 @@ build-template:
125132 -kernel $(KERNEL_VERSION ) \
126133 -firecracker $(FIRECRACKER_VERSION )
127134
135+ .PHONY : fetch-busybox
136+ fetch-busybox :
137+ @ARCH=$(BUILD_ARCH ) ; \
138+ BUSYBOX_TARGET=./pkg/template/build/core/systeminit/busybox_1.36.1-2; \
139+ if [ " $$ ARCH" != " arm64" ]; then \
140+ echo " ✓ Using bundled amd64 busybox" ; \
141+ elif file " $$ BUSYBOX_TARGET" 2> /dev/null | grep -q ' aarch64\|ARM aarch64' ; then \
142+ echo " ✓ Busybox is already arm64" ; \
143+ elif command -v busybox > /dev/null 2>&1 && file " $$ (command -v busybox)" 2> /dev/null | grep -q ' aarch64\|ARM aarch64' && file " $$ (command -v busybox)" 2> /dev/null | grep -q ' statically linked' ; then \
144+ cp " $$ (command -v busybox)" " $$ BUSYBOX_TARGET" && \
145+ echo " ✓ Copied host busybox (arm64, static) to embedded path" ; \
146+ elif command -v apt-get > /dev/null 2>&1 && command -v dpkg-deb > /dev/null 2>&1 ; then \
147+ echo " Fetching arm64 busybox via apt..." ; \
148+ TMPDIR=$$(mktemp -d ) ; \
149+ apt-get download busybox-static 2> /dev/null && \
150+ dpkg-deb -x busybox-static_* .deb " $$ TMPDIR" && \
151+ cp " $$ TMPDIR/bin/busybox" " $$ BUSYBOX_TARGET" && \
152+ rm -rf " $$ TMPDIR" busybox-static_* .deb && \
153+ echo " ✓ Replaced embedded busybox with arm64 binary (from busybox-static package)" || \
154+ { rm -rf " $$ TMPDIR" busybox-static_* .deb; echo " ⚠ apt-get download failed" ; exit 1; }; \
155+ else \
156+ echo " ⚠ ARM64 busybox required but no method available to fetch it." ; \
157+ echo " Options:" ; \
158+ echo " 1. Install busybox-static: apt install busybox-static, then re-run" ; \
159+ echo " 2. Manually place an arm64 busybox binary at: $$ BUSYBOX_TARGET" ; \
160+ exit 1; \
161+ fi
162+
128163.PHONY : migrate
129164migrate :
130165 ./scripts/upload-envs.sh /mnt/disks/fc-envs/v1 $(TEMPLATE_BUCKET_NAME )
0 commit comments