diff --git a/build/debian-base/Makefile b/build/debian-base/Makefile index d9f0ac5a0c..7ab9ac5bfc 100755 --- a/build/debian-base/Makefile +++ b/build/debian-base/Makefile @@ -27,6 +27,8 @@ ALL_ARCH = amd64 arm arm64 ppc64le s390x TEMP_DIR:=$(shell mktemp -d) QEMUVERSION=v2.9.1 +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled @@ -80,7 +82,7 @@ ifeq ($(ARCH),amd64) else # When cross-building, only the placeholder "CROSS_BUILD_" should be removed # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR) # Ensure we don't get surprised by umask settings chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static diff --git a/build/debian-hyperkube-base/Makefile b/build/debian-hyperkube-base/Makefile index 53d7aa35a2..71dbd8bfca 100644 --- a/build/debian-hyperkube-base/Makefile +++ b/build/debian-hyperkube-base/Makefile @@ -33,6 +33,8 @@ CNI_TARBALL=cni-plugins-$(ARCH)-$(CNI_VERSION).tgz # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + .PHONY: all build push clean all-build all-push-images all-push push-manifest all: all-push @@ -74,7 +76,7 @@ endif ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) rm -rf $(TEMP_DIR) diff --git a/build/debian-iptables/Makefile b/build/debian-iptables/Makefile index 56a55ebaf3..6d0438ffef 100644 --- a/build/debian-iptables/Makefile +++ b/build/debian-iptables/Makefile @@ -26,13 +26,15 @@ BASEIMAGE?=k8s.gcr.io/debian-base-$(ARCH):0.3.2 # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + build: cp ./* $(TEMP_DIR) cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) diff --git a/test/images/image-util.sh b/test/images/image-util.sh index 555fd821c1..61a57e844f 100755 --- a/test/images/image-util.sh +++ b/test/images/image-util.sh @@ -84,7 +84,11 @@ build() { ${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile # Register qemu-*-static for all supported processors except the current one echo "Registering qemu-*-static binaries in the kernel" - sudo "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset + local sudo="" + if [[ $(id -u) != 0 ]]; then + sudo=sudo + fi + "${sudo}" "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/${QEMUVERSION}/x86_64_qemu-${QEMUARCHS[$arch]}-static.tar.gz | tar -xz -C ${temp_dir} # Ensure we don't get surprised by umask settings chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"