]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ci: Makefile: Expose the CI_USER_LOGIN variable for users to use
authorErik Skultety <eskultet@redhat.com>
Wed, 10 Feb 2021 07:27:29 +0000 (08:27 +0100)
committerErik Skultety <eskultet@redhat.com>
Fri, 12 Feb 2021 16:01:41 +0000 (17:01 +0100)
More often than not I find myself debugging in the containers which
means that I need to have root inside, but without manually tweaking
the Makefile each time the execution would simply fail thanks to the
uid/gid mapping we do. What if we expose the CI_USER_LOGIN variable, so
that when needed, the root can be simply passed with this variable and
voila - you have a root shell inside the container with CWD=~root.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
ci/Makefile

index 9308738d2d3df5a78dd5c5ceb155ed90a6500bec..7bbff3e9aa9210e6ce8fac7eb79c015876834f55 100644 (file)
@@ -45,15 +45,15 @@ CI_CLEAN = 1
 # preserved env
 CI_REUSE = 0
 
-# We need the container process to run with current host IDs
-# so that it can access the passed in build directory
-CI_UID = $(shell id -u)
-CI_GID = $(shell id -g)
-
-# We also need the user's login and home directory to prepare the
+# We need the user's login and home directory to prepare the
 # environment the way some programs expect it
-CI_USER_LOGIN = $(shell echo "$$USER")
-CI_USER_HOME = $(shell echo "$$HOME")
+CI_USER_LOGIN = $(shell whoami)
+CI_USER_HOME = $(shell eval echo "~$(CI_USER_LOGIN)")
+
+# We also need the container process to run with current host IDs
+# so that it can access the passed in build directory
+CI_UID = $(shell id -u "$(CI_USER_LOGIN)")
+CI_GID = $(shell id -g "$(CI_USER_LOGIN)")
 
 CI_ENGINE = auto
 # Container engine we are going to use, can be overridden per make
@@ -124,14 +124,16 @@ ifeq ($(CI_ENGINE),podman)
        CI_UID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_UID)-$(CI_UID))))
        CI_GID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_GID)-$(CI_GID))))
 
-       CI_PODMAN_ARGS = \
-               --uidmap 0:1:$(CI_UID) \
-               --uidmap $(CI_UID):0:1 \
-               --uidmap $(CI_UID_OTHER):$(CI_UID_OTHER):$(CI_UID_OTHER_RANGE) \
-               --gidmap 0:1:$(CI_GID) \
-               --gidmap $(CI_GID):0:1 \
-               --gidmap $(CI_GID_OTHER):$(CI_GID_OTHER):$(CI_GID_OTHER_RANGE) \
-               $(NULL)
+       ifneq ($(CI_UID), 0)
+               CI_PODMAN_ARGS = \
+                       --uidmap 0:1:$(CI_UID) \
+                       --uidmap $(CI_UID):0:1 \
+                       --uidmap $(CI_UID_OTHER):$(CI_UID_OTHER):$(CI_UID_OTHER_RANGE) \
+                       --gidmap 0:1:$(CI_GID) \
+                       --gidmap $(CI_GID):0:1 \
+                       --gidmap $(CI_GID_OTHER):$(CI_GID_OTHER):$(CI_GID_OTHER_RANGE) \
+                       $(NULL)
+       endif
 endif
 
 # Args to use when cloning a git repo.
@@ -239,6 +241,7 @@ ci-help:
        @echo "    CI_CLEAN=0          - do not delete '$(CI_SCRATCHDIR)' after completion"
        @echo "    CI_REUSE=1          - re-use existing '$(CI_SCRATCHDIR)' content"
        @echo "    CI_ENGINE=auto      - container engine to use (podman, docker)"
+       @echo "    CI_USER_LOGIN=      - which user should run in the container (default is $$USER)"
        @echo "    CI_MESON_ARGS=      - extra arguments passed to meson"
        @echo "    CI_NINJA_ARGS=      - extra arguments passed to ninja"
        @echo