container: Disable git safe.directory when running without kas-container

This is for the sake of the gitlab-ci runner which does not properly
aligns the ownership of the repo it checks out with the UID:GID of
our builder user. Reason not yet understood and hard to debug (logging
of the runner is incomplete).

Work around this issue by disabling safe.directory checks in case the
container is called without kas-container as wrapper (means, when it is
called without setting "--user=root"). This preserves git's checks for
the common interactive case, the more critical one.

Reported-by: Ross Burton <ross@burtonini.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2023-02-06 17:57:53 +01:00
parent 492b2c56ab
commit 06aae60b65

View File

@ -13,8 +13,15 @@ may also need to update the host distribution (e.g. Debian Jessie -> Stretch).
EOF EOF
fi fi
if [ -z "$USER_ID" ] || [ "$USER_ID" == 0 ]; then if [ -z "$USER_ID" ]; then
# Not a kas-container call, or we shall run everything as root # Not a kas-container call
GOSU=""
# Work around gitlab-runner not aligning checked out repo ownership
# with our builder user
sudo git config --system safe.directory "*"
elif [ "$USER_ID" == 0 ]; then
# We shall run everything as root
GOSU="" GOSU=""
else else
GROUP_ID=${GROUP_ID:-$(id -g)} GROUP_ID=${GROUP_ID:-$(id -g)}