From 8eb67c1d132dc5b0e62f47cda6009d0d34cefc61 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Fri, 24 May 2024 11:02:08 +0000 Subject: [PATCH] test: Fixup permissions of generated files when using docker Since containers managed by docker runs as root, files created in bind mounted volumes will be owned by root:root. This is a problem for files generated during test execution, as the calling user does not have permission to remove them. Therefore, add a wrapper entrypoint that hooks up an exit handler that will fixup the permissions before exiting the container. --- test/.env | 2 +- test/docker/Dockerfile | 4 ++++ test/docker/entrypoint.sh | 14 ++++++++++++++ test/env | 14 ++++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100755 test/docker/entrypoint.sh diff --git a/test/.env b/test/.env index 1c85c5fd..ab30d0d1 100644 --- a/test/.env +++ b/test/.env @@ -2,7 +2,7 @@ # shellcheck disable=SC2034,SC2154 # Current container image -INFIX_TEST=ghcr.io/kernelkit/infix-test:1.4 +INFIX_TEST=ghcr.io/kernelkit/infix-test:1.5 ixdir=$(readlink -f "$testdir/..") logdir=$(readlink -f "$testdir/.log") diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile index c986de93..2190fb2d 100644 --- a/test/docker/Dockerfile +++ b/test/docker/Dockerfile @@ -44,3 +44,7 @@ COPY pip-requirements.txt /root ADD yang /root/yang RUN ~/init-venv.sh ~/pip-requirements.txt + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/bin/sh"] diff --git a/test/docker/entrypoint.sh b/test/docker/entrypoint.sh new file mode 100755 index 00000000..19d6bde1 --- /dev/null +++ b/test/docker/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +fixup_owner() +{ + for dir in $HOST_CHOWN_PATH; do + chown -R $HOST_CHOWN_UID:$HOST_CHOWN_GID $dir + done +} + +trap fixup_owner EXIT + +"$@" diff --git a/test/env b/test/env index 7729bc8e..9508c1ed 100755 --- a/test/env +++ b/test/env @@ -164,6 +164,17 @@ while getopts "cCDf:hiKp:q:t:" opt; do done if [ "$containerize" ]; then + volumes="--volume $ixdir:$ixdir --workdir=$ixdir/test" + case "$(runner)" in + docker) + volumes="$volumes --env HOST_CHOWN_PATH=$ixdir/test" + volumes="$volumes --env HOST_CHOWN_UID=$(id -u)" + volumes="$volumes --env HOST_CHOWN_GID=$(id -g)" + ;; + podman) + ;; + esac + # shellcheck disable=SC2016 exec $(runner) run \ --cap-add=NET_RAW \ @@ -181,8 +192,7 @@ if [ "$containerize" ]; then --security-opt seccomp=unconfined \ $network \ --tty \ - --volume "$ixdir":"$ixdir" \ - --workdir "$ixdir/test" \ + $volumes \ $kvm \ $INFIX_TEST \ "$0" -C "$@"