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.
This commit is contained in:
Tobias Waldekranz
2024-05-24 19:10:10 +02:00
committed by Joachim Wiberg
parent 8fdd147d1e
commit 8eb67c1d13
4 changed files with 31 additions and 3 deletions
+1 -1
View File
@@ -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")
+4
View File
@@ -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"]
+14
View File
@@ -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
"$@"
+12 -2
View File
@@ -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 "$@"