diff --git a/scripts/dev_cli.sh b/scripts/dev_cli.sh index 8441e3f40..71a9cf757 100755 --- a/scripts/dev_cli.sh +++ b/scripts/dev_cli.sh @@ -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() {