ci: Run $(CI_PREPARE_SCRIPT) as root

In order for the prepare script to be really useful, it needs
to be able to perform privileged operations such as installing
additional packages or setting up custom mount points.

In order to achieve that, we now run the container as root,
run the prepare script with full privilege, and only then
switch to the unprivileged account with sudo.

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 15:37:38 +02:00
parent 2ce3274ea5
commit 4c39e54ca9
2 changed files with 15 additions and 8 deletions

View File

@ -178,7 +178,6 @@ CI_GIT_ARGS = \
# --tty Ensure we have ability to Ctrl-C the build # --tty Ensure we have ability to Ctrl-C the build
CI_ENGINE_ARGS = \ CI_ENGINE_ARGS = \
--rm \ --rm \
--user $(CI_UID):$(CI_GID) \
--interactive \ --interactive \
--tty \ --tty \
$(CI_PODMAN_ARGS) \ $(CI_PODMAN_ARGS) \
@ -219,13 +218,17 @@ ci-run-command@%: ci-prepare-tree
$(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) \ $(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) \
/bin/bash -c ' \ /bin/bash -c ' \
$(CI_USER_HOME)/prepare || exit 1; \ $(CI_USER_HOME)/prepare || exit 1; \
export CI_CONT_SRCDIR="$(CI_CONT_SRCDIR)"; \ sudo \
export CI_CONT_BUILDDIR="$(CI_CONT_BUILDDIR)"; \ --login \
export CI_SMP="$(CI_SMP)"; \ --user="#$(CI_UID)" \
export CI_CONFIGURE="$(CI_CONFIGURE)"; \ --group="#$(CI_GID)" \
export CI_CONFIGURE_ARGS="$(CI_CONFIGURE_ARGS)"; \ CI_CONT_SRCDIR="$(CI_CONT_SRCDIR)" \
export CI_MAKE_ARGS="$(CI_MAKE_ARGS)"; \ CI_CONT_BUILDDIR="$(CI_CONT_BUILDDIR)" \
$(CI_COMMAND) || exit 1' CI_SMP="$(CI_SMP)" \
CI_CONFIGURE="$(CI_CONFIGURE)" \
CI_CONFIGURE_ARGS="$(CI_CONFIGURE_ARGS)" \
CI_MAKE_ARGS="$(CI_MAKE_ARGS)" \
$(CI_COMMAND) || exit 1'
@test "$(CI_CLEAN)" = "1" && rm -rf $(CI_SCRATCHDIR) || : @test "$(CI_CLEAN)" = "1" && rm -rf $(CI_SCRATCHDIR) || :
ci-shell@%: ci-shell@%:

View File

@ -7,3 +7,7 @@
# CI_PREPARE_SCRIPT=/path/to/your/prepare/script # CI_PREPARE_SCRIPT=/path/to/your/prepare/script
# #
# to make. # to make.
#
# Note that this script will have root privileges inside the
# container, so it can be used for things like installing additional
# packages.