scripts: dev_cli: Fix build directory permisions

All our tests must be run as root and thus the build directory is owned
by root after we run any of them.

Start another container to fix all permissions whenever we're done with
our tests.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2020-02-07 21:25:10 +01:00 committed by Sebastien Boeuf
parent c8fa8092c5
commit 0a1d6e1cb3

View File

@ -23,7 +23,8 @@ CLH_INTEGRATION_WORKLOADS="${HOME}/workloads"
# Container paths
CTR_CLH_ROOT_DIR="/cloud-hypervisor"
CTR_CLH_CARGO_TARGET="${CTR_CLH_ROOT_DIR}/build/cargo_target"
CTR_CLH_CARGO_BUILT_DIR="${CTR_CLH_ROOT_DIR}/build"
CTR_CLH_CARGO_TARGET="${CTR_CLH_CARGO_BUILT_DIR}/cargo_target"
CTR_CLH_INTEGRATION_WORKLOADS="/root/workloads"
# Cargo paths
@ -112,6 +113,25 @@ ensure_build_dir() {
done
}
# Fix build/ dir permissions after a container ran as root
# Since the container ran as root, any files it creates will be owned by root.
# This fixes that by recursively changing the ownership of build/ to the
# current user.
#
fix_build_dir_perms() {
# Yes, running Docker to get elevated privileges, just to chown some files
# is a dirty hack.
$DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \
--rm \
--volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
"$CTR_IMAGE" \
chown -R "$(id -u):$(id -g)" "$CTR_CLH_CARGO_BUILT_DIR"
return $1
}
cmd_help() {
echo ""
echo "Cloud Hypervisor $(basename $0)"
@ -226,18 +246,17 @@ cmd_tests() {
--volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
"$CTR_IMAGE" \
./scripts/run_unit_tests.sh "$@" || exit $?
./scripts/run_unit_tests.sh "$@" || fix_build_dir_perms $? || exit $?
fi
if [ "$cargo" = true ] ; then
say "Running cargo tests..."
$DOCKER_RUNTIME run \
--user "$(id -u):$(id -g)" \
--workdir "$CTR_CLH_ROOT_DIR" \
--rm \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
"$CTR_IMAGE" \
./scripts/run_cargo_tests.sh || exit $?
./scripts/run_cargo_tests.sh || fix_build_dir_perms $? || exit $?
fi
if [ "$integration" = true ] ; then
@ -251,8 +270,10 @@ cmd_tests() {
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
"$CTR_IMAGE" \
./scripts/run_integration_tests.sh "$@" || exit $?
./scripts/run_integration_tests.sh "$@" || fix_build_dir_perms $? || exit $?
fi
fix_build_dir_perms $?
}
cmd_build-container() {