@@ -30,31 +30,43 @@ TEMP_DIR:=$(shell mktemp -d)
3030ifeq ($(ARCH ) ,arm)
3131 BASEIMAGE?=armel/busybox:glibc
3232 TRIPLE? =arm-linux-gnueabi
33+ QEMUARCH =arm
3334endif
3435ifeq ($(ARCH ) ,arm64)
3536 BASEIMAGE?=aarch64/busybox:glibc
3637 TRIPLE? =aarch64-linux-gnu
38+ QEMUARCH =aarch64
3739endif
3840ifeq ($(ARCH ) ,ppc64le)
3941 BASEIMAGE?=ppc64le/busybox:glibc
4042 TRIPLE? =powerpc64le-linux-gnu
43+ QEMUARCH =ppc64le
4144endif
4245
4346all : build
4447
4548build :
4649ifeq ($(ARCH ) ,amd64)
4750 cp Dockerfile $(TEMP_DIR)
51+ # When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
52+ cd $(TEMP_DIR) && sed -i "/CROSS_BUILD_/d" Dockerfile
4853else
4954 cp Dockerfile.cross $(TEMP_DIR)/Dockerfile
50- sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" $(TEMP_DIR)/Dockerfile
55+ cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
56+ cd $(TEMP_DIR) && sed -i "s|ARCH|$(QEMUARCH)|g" Dockerfile
5157
5258 # Build the dnsmasq binary using the cross-compilation docker image
5359 docker run -it --rm -v $(TEMP_DIR):/build $(KUBE_CROSS_IMAGE) /bin/bash -c \
5460 "curl -sSL http://www.thekelleys.org.uk/dnsmasq/$(DNSMASQ_VERSION).tar.xz | tar -xJ \
5561 && cd $(DNSMASQ_VERSION) \
5662 && CC=$(TRIPLE)-gcc make \
5763 && cp src/dnsmasq /build"
64+
65+ # When cross-building, only the placeholder "CROSS_BUILD_" should be removed
66+ # Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel
67+ docker run --rm --privileged multiarch/qemu-user-static:register --reset
68+ curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/v2.5.0/x86_64_qemu-$(QEMUARCH)-static.tar.xz | tar -xJ -C $(TEMP_DIR)
69+ cd $(TEMP_DIR) && sed -i "s/CROSS_BUILD_//g" Dockerfile
5870endif
5971 cp dnsmasq.conf $(TEMP_DIR)
6072 docker build -t $(REGISTRY)/kube-dnsmasq-$(ARCH):$(TAG) $(TEMP_DIR)
0 commit comments