mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Use sudo only when not already root
This commit is contained in:
parent
9e4fa1493d
commit
a88244598a
@ -27,6 +27,8 @@ ALL_ARCH = amd64 arm arm64 ppc64le s390x
|
|||||||
TEMP_DIR:=$(shell mktemp -d)
|
TEMP_DIR:=$(shell mktemp -d)
|
||||||
QEMUVERSION=v2.9.1
|
QEMUVERSION=v2.9.1
|
||||||
|
|
||||||
|
SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
|
||||||
|
|
||||||
# This option is for running docker manifest command
|
# This option is for running docker manifest command
|
||||||
export DOCKER_CLI_EXPERIMENTAL := enabled
|
export DOCKER_CLI_EXPERIMENTAL := enabled
|
||||||
|
|
||||||
@ -80,7 +82,7 @@ ifeq ($(ARCH),amd64)
|
|||||||
else
|
else
|
||||||
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
|
# 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
|
# 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)
|
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
|
# Ensure we don't get surprised by umask settings
|
||||||
chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static
|
chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static
|
||||||
|
@ -33,6 +33,8 @@ CNI_TARBALL=cni-plugins-$(ARCH)-$(CNI_VERSION).tgz
|
|||||||
# This option is for running docker manifest command
|
# This option is for running docker manifest command
|
||||||
export DOCKER_CLI_EXPERIMENTAL := enabled
|
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
|
.PHONY: all build push clean all-build all-push-images all-push push-manifest
|
||||||
|
|
||||||
all: all-push
|
all: all-push
|
||||||
@ -74,7 +76,7 @@ endif
|
|||||||
|
|
||||||
ifneq ($(ARCH),amd64)
|
ifneq ($(ARCH),amd64)
|
||||||
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
|
# 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
|
endif
|
||||||
docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
|
docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
|
||||||
rm -rf $(TEMP_DIR)
|
rm -rf $(TEMP_DIR)
|
||||||
|
@ -26,13 +26,15 @@ BASEIMAGE?=k8s.gcr.io/debian-base-$(ARCH):0.3.2
|
|||||||
# This option is for running docker manifest command
|
# This option is for running docker manifest command
|
||||||
export DOCKER_CLI_EXPERIMENTAL := enabled
|
export DOCKER_CLI_EXPERIMENTAL := enabled
|
||||||
|
|
||||||
|
SUDO=$(if $(filter 0,$(shell id -u)),,sudo)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cp ./* $(TEMP_DIR)
|
cp ./* $(TEMP_DIR)
|
||||||
cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
|
cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
|
||||||
|
|
||||||
ifneq ($(ARCH),amd64)
|
ifneq ($(ARCH),amd64)
|
||||||
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel
|
# 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
|
endif
|
||||||
|
|
||||||
docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
|
docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR)
|
||||||
|
@ -84,7 +84,11 @@ build() {
|
|||||||
${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile
|
${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile
|
||||||
# Register qemu-*-static for all supported processors except the current one
|
# Register qemu-*-static for all supported processors except the current one
|
||||||
echo "Registering qemu-*-static binaries in the kernel"
|
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}
|
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
|
# Ensure we don't get surprised by umask settings
|
||||||
chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"
|
chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"
|
||||||
|
Loading…
Reference in New Issue
Block a user