ci: Create user's home directory in the container

Some applications expect the user's home directory to be
present on the system and require workarounds when that's not
the case. Creating the home directory along with everything
else is easy enough for us, so let's just do that.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Andrea Bolognani 2019-08-15 20:34:20 +02:00
parent ffad19f94c
commit e14bfc97b7

View File

@ -65,6 +65,11 @@ CI_REUSE = 0
CI_UID = $(shell id -u) CI_UID = $(shell id -u)
CI_GID = $(shell id -g) CI_GID = $(shell id -g)
# We also 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_ENGINE = auto CI_ENGINE = auto
# Container engine we are going to use, can be overridden per make # Container engine we are going to use, can be overridden per make
# invocation, if it is not we try podman and then default to docker. # invocation, if it is not we try podman and then default to docker.
@ -87,6 +92,10 @@ CI_PWDB_MOUNTS = \
--volume $(CI_SCRATCHDIR)/passwd:/etc/passwd:ro,z \ --volume $(CI_SCRATCHDIR)/passwd:/etc/passwd:ro,z \
$(NULL) $(NULL)
CI_HOME_MOUNTS = \
--volume $(CI_SCRATCHDIR)/home:$(CI_USER_HOME):z \
$(NULL)
# Docker containers can have very large ulimits # Docker containers can have very large ulimits
# for nofiles - as much as 1048576. This makes # for nofiles - as much as 1048576. This makes
# libvirt very slow at exec'ing programs. # libvirt very slow at exec'ing programs.
@ -113,8 +122,8 @@ ifeq ($(CI_ENGINE),podman)
# your /etc/sub{u,g}id allow users to have more IDs. Unless # your /etc/sub{u,g}id allow users to have more IDs. Unless
# --keep-uid is supported, let's do this in a way that should # --keep-uid is supported, let's do this in a way that should
# work for everyone. # work for everyone.
CI_MAX_UID = $(shell sed -n "s/^$$USER:[^:]\+://p" /etc/subuid) CI_MAX_UID = $(shell sed -n "s/^$(CI_USER_LOGIN):[^:]\+://p" /etc/subuid)
CI_MAX_GID = $(shell sed -n "s/^$$USER:[^:]\+://p" /etc/subgid) CI_MAX_GID = $(shell sed -n "s/^$(CI_USER_LOGIN):[^:]\+://p" /etc/subgid)
ifeq ($(CI_MAX_UID),) ifeq ($(CI_MAX_UID),)
CI_MAX_UID = 65536 CI_MAX_UID = 65536
endif endif
@ -163,6 +172,7 @@ CI_ENGINE_ARGS = \
--tty \ --tty \
$(CI_PODMAN_ARGS) \ $(CI_PODMAN_ARGS) \
$(CI_PWDB_MOUNTS) \ $(CI_PWDB_MOUNTS) \
$(CI_HOME_MOUNTS) \
--volume $(CI_HOST_SRCDIR):$(CI_CONT_SRCDIR):z \ --volume $(CI_HOST_SRCDIR):$(CI_CONT_SRCDIR):z \
--workdir $(CI_CONT_SRCDIR) \ --workdir $(CI_CONT_SRCDIR) \
--ulimit nofile=$(CI_ULIMIT_FILES):$(CI_ULIMIT_FILES) \ --ulimit nofile=$(CI_ULIMIT_FILES):$(CI_ULIMIT_FILES) \
@ -179,6 +189,7 @@ ci-prepare-tree: ci-check-engine
mkdir -p $(CI_SCRATCHDIR); \ mkdir -p $(CI_SCRATCHDIR); \
cp /etc/passwd $(CI_SCRATCHDIR); \ cp /etc/passwd $(CI_SCRATCHDIR); \
cp /etc/group $(CI_SCRATCHDIR); \ cp /etc/group $(CI_SCRATCHDIR); \
mkdir -p $(CI_SCRATCHDIR)/home; \
echo "Cloning $(CI_GIT_ROOT) to $(CI_HOST_SRCDIR)"; \ echo "Cloning $(CI_GIT_ROOT) to $(CI_HOST_SRCDIR)"; \
git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT) $(CI_HOST_SRCDIR) || exit 1; \ git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT) $(CI_HOST_SRCDIR) || exit 1; \
for mod in $$(git submodule | awk '{ print $$2 }' | sed -E 's,^../,,g') ; \ for mod in $$(git submodule | awk '{ print $$2 }' | sed -E 's,^../,,g') ; \