kas-docker: Warn when running as root

While this works from kas perspective, some build recipes will no like
to be run with ID 0 and may either fail loudly or subtly. Better warn
when a user applies sudo on kas-docker or otherwise runs it from a root
shell.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2020-05-15 17:15:18 +02:00
parent 96df30a80f
commit 385e42ff11

View File

@ -192,6 +192,13 @@ KAS_FILES=/repo/"$(echo "${KAS_FILES}" | sed 's|'"${REPO_DIR}"'/||g;s|:|:/repo/|
trace mkdir -p "${KAS_WORK_DIR}"
if [ $(id -u) -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
echo "Error: Running as root - may break certain recipes."
echo "Better give a regular user docker access. Set" \
"KAS_ALLOW_ROOT=yes to override."
exit 1
fi
set -- -v "${REPO_DIR}":/repo:ro \
-v "${KAS_WORK_DIR}":/work:rw --workdir=/work \
-e USER_ID=$(id -u) -e GROUP_ID=$(id -g) --rm