build/common.sh: fix support for Rootless Docker

In the case of Rootless mode, `docker run` should not be
invoked with `--user`.

Fix issue 134669

Regression in PR 134510

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2025-10-19 01:01:10 +09:00
parent e2453c503e
commit f6e2ea7b96
No known key found for this signature in database
GPG key ID: 49524C6F9F638F1A

View file

@ -322,6 +322,10 @@ function kube::build::destroy_container() {
"${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true
}
function kube::build::is_docker_rootless() {
"${DOCKER[@]}" info --format '{{json .SecurityOptions}}' | grep -q "name=rootless"
}
# ---------------------------------------------------------------------------
# Building
@ -367,11 +371,12 @@ function kube::build::run_build_command_ex() {
local -a docker_run_opts=(
"--name=${container_name}"
"--user=$(id -u):$(id -g)"
"--hostname=${HOSTNAME}"
"-e=GOPROXY=${GOPROXY}"
)
kube::build::is_docker_rootless || docker_run_opts+=("--user=$(id -u):$(id -g)")
local detach=false
[[ $# != 0 ]] || { echo "Invalid input - please specify docker arguments followed by --." >&2; return 4; }