scipts: dev_cli.sh: Reformat script for consistency

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2022-02-21 11:04:19 +00:00
parent 2805e7b1dc
commit 1a5b94ee0e
+304 -275
View File
@@ -48,32 +48,32 @@ CARGO_TARGET_DIR="${CLH_BUILD_DIR}/cargo_target"
# Send a decorated message to stdout, followed by a new line # Send a decorated message to stdout, followed by a new line
# #
say() { say() {
[ -t 1 ] && [ -n "$TERM" ] \ [ -t 1 ] && [ -n "$TERM" ] &&
&& echo "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" \ echo "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" ||
|| echo "[$CLI_NAME] $*" echo "[$CLI_NAME] $*"
} }
# Send a decorated message to stdout, without a trailing new line # Send a decorated message to stdout, without a trailing new line
# #
say_noln() { say_noln() {
[ -t 1 ] && [ -n "$TERM" ] \ [ -t 1 ] && [ -n "$TERM" ] &&
&& echo -n "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" \ echo -n "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" ||
|| echo "[$CLI_NAME] $*" echo "[$CLI_NAME] $*"
} }
# Send a text message to stderr # Send a text message to stderr
# #
say_err() { say_err() {
[ -t 2 ] && [ -n "$TERM" ] \ [ -t 2 ] && [ -n "$TERM" ] &&
&& echo "$(tput setaf 1)[$CLI_NAME] $*$(tput sgr0)" 1>&2 \ echo "$(tput setaf 1)[$CLI_NAME] $*$(tput sgr0)" 1>&2 ||
|| echo "[$CLI_NAME] $*" 1>&2 echo "[$CLI_NAME] $*" 1>&2
} }
# Send a warning-highlighted text to stdout # Send a warning-highlighted text to stdout
say_warn() { say_warn() {
[ -t 1 ] && [ -n "$TERM" ] \ [ -t 1 ] && [ -n "$TERM" ] &&
&& echo "$(tput setaf 3)[$CLI_NAME] $*$(tput sgr0)" \ echo "$(tput setaf 3)[$CLI_NAME] $*$(tput sgr0)" ||
|| echo "[$CLI_NAME] $*" echo "[$CLI_NAME] $*"
} }
# Exit with an error message and (optional) code # Exit with an error message and (optional) code
@@ -101,17 +101,17 @@ ok_or_die() {
# #
ensure_build_dir() { ensure_build_dir() {
for dir in "$CLH_BUILD_DIR" \ for dir in "$CLH_BUILD_DIR" \
"$CLH_INTEGRATION_WORKLOADS" \ "$CLH_INTEGRATION_WORKLOADS" \
"$CLH_CTR_BUILD_DIR" \ "$CLH_CTR_BUILD_DIR" \
"$CARGO_TARGET_DIR" \ "$CARGO_TARGET_DIR" \
"$CARGO_REGISTRY_DIR" \ "$CARGO_REGISTRY_DIR" \
"$CARGO_GIT_REGISTRY_DIR"; do "$CARGO_GIT_REGISTRY_DIR"; do
mkdir -p "$dir" || die "Error: cannot create dir $dir" mkdir -p "$dir" || die "Error: cannot create dir $dir"
[ -x "$dir" ] && [ -w "$dir" ] || \ [ -x "$dir" ] && [ -w "$dir" ] ||
{ {
say "Wrong permissions for $dir. Attempting to fix them ..." say "Wrong permissions for $dir. Attempting to fix them ..."
chmod +x+w "$dir" chmod +x+w "$dir"
} || \ } ||
die "Error: wrong permissions for $dir. Should be +x+w" die "Error: wrong permissions for $dir. Should be +x+w"
done done
} }
@@ -132,12 +132,12 @@ fix_dir_perms() {
# Yes, running Docker to get elevated privileges, just to chown some files # Yes, running Docker to get elevated privileges, just to chown some files
# is a dirty hack. # is a dirty hack.
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
chown -R "$(id -u):$(id -g)" "$CTR_CLH_ROOT_DIR" chown -R "$(id -u):$(id -g)" "$CTR_CLH_ROOT_DIR"
return "$1" return "$1"
} }
@@ -151,8 +151,7 @@ process_volumes_args() {
fi fi
exported_volumes="" exported_volumes=""
arr_vols=(${arg_vols//#/ }) arr_vols=(${arg_vols//#/ })
for var in "${arr_vols[@]}" for var in "${arr_vols[@]}"; do
do
parts=(${var//:/ }) parts=(${var//:/ })
if [[ ! -e "${parts[0]}" ]]; then if [[ ! -e "${parts[0]}" ]]; then
echo "The volume ${parts[0]} does not exist." echo "The volume ${parts[0]} does not exist."
@@ -214,37 +213,43 @@ cmd_build() {
features_build="" features_build=""
exported_device="/dev/kvm" exported_device="/dev/kvm"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
"-h"|"--help") { cmd_help; exit 1; } ;; "-h" | "--help") {
"--debug") { build="debug"; } ;; cmd_help
"--release") { build="release"; } ;; exit 1
"--libc") } ;;
shift "--debug") { build="debug"; } ;;
[[ "$1" =~ ^(musl|gnu)$ ]] || \ "--release") { build="release"; } ;;
die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"." "--libc")
libc="$1" shift
;; [[ "$1" =~ ^(musl|gnu)$ ]] ||
"--volumes") die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"."
shift libc="$1"
arg_vols="$1" ;;
;; "--volumes")
"--hypervisor") shift
shift arg_vols="$1"
hypervisor="$1" ;;
;; "--hypervisor")
"--") { shift; break; } ;; shift
*) hypervisor="$1"
die "Unknown build argument: $1. Please use --help for help." ;;
;; "--") {
esac shift
shift break
} ;;
*)
die "Unknown build argument: $1. Please use --help for help."
;;
esac
shift
done done
ensure_build_dir ensure_build_dir
ensure_latest_ctr ensure_latest_ctr
process_volumes_args process_volumes_args
if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then
die "Hypervisor value must be kvm or mshv" die "Hypervisor value must be kvm or mshv"
fi fi
if [[ "$hypervisor" = "mshv" ]]; then if [[ "$hypervisor" = "mshv" ]]; then
@@ -259,21 +264,21 @@ cmd_build() {
[ "$(uname -m)" = "aarch64" ] && cargo_args+=(--features "$hypervisor") [ "$(uname -m)" = "aarch64" ] && cargo_args+=(--features "$hypervisor")
rustflags="" rustflags=""
if [ "$(uname -m)" = "aarch64" ] && [ "$libc" = "musl" ] ; then if [ "$(uname -m)" = "aarch64" ] && [ "$libc" = "musl" ]; then
rustflags="-C link-arg=-lgcc -C link_arg=-specs -C link_arg=/usr/lib/aarch64-linux-musl/musl-gcc.specs" rustflags="-C link-arg=-lgcc -C link_arg=-specs -C link_arg=/usr/lib/aarch64-linux-musl/musl-gcc.specs"
fi fi
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--user "$(id -u):$(id -g)" \ --user "$(id -u):$(id -g)" \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--volume $exported_device \ --volume $exported_device \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--env RUSTFLAGS="$rustflags" \ --env RUSTFLAGS="$rustflags" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
cargo build --all "$features_build" \ cargo build --all "$features_build" \
--target-dir "$CTR_CLH_CARGO_TARGET" \ --target-dir "$CTR_CLH_CARGO_TARGET" \
"${cargo_args[@]}" && say "Binaries placed under $CLH_CARGO_TARGET/$target/$build" "${cargo_args[@]}" && say "Binaries placed under $CLH_CARGO_TARGET/$target/$build"
} }
cmd_clean() { cmd_clean() {
@@ -283,15 +288,15 @@ cmd_clean() {
ensure_latest_ctr ensure_latest_ctr
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--user "$(id -u):$(id -g)" \ --user "$(id -u):$(id -g)" \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
cargo clean \ cargo clean \
--target-dir "$CTR_CLH_CARGO_TARGET" \ --target-dir "$CTR_CLH_CARGO_TARGET" \
"${cargo_args[@]}" "${cargo_args[@]}"
} }
cmd_tests() { cmd_tests() {
unit=false unit=false
@@ -307,39 +312,49 @@ cmd_tests() {
hypervisor="kvm" hypervisor="kvm"
exported_device="/dev/kvm" exported_device="/dev/kvm"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
"-h"|"--help") { cmd_help; exit 1; } ;; "-h" | "--help") {
"--unit") { unit=true; } ;; cmd_help
"--cargo") { cargo=true; } ;; exit 1
"--integration") { integration=true; } ;; } ;;
"--integration-sgx") { integration_sgx=true; } ;; "--unit") { unit=true; } ;;
"--integration-vfio") { integration_vfio=true; } ;; "--cargo") { cargo=true; } ;;
"--integration-windows") { integration_windows=true; } ;; "--integration") { integration=true; } ;;
"--integration-live-migration") { integration_live_migration=true; } ;; "--integration-sgx") { integration_sgx=true; } ;;
"--metrics") { metrics=true; } ;; "--integration-vfio") { integration_vfio=true; } ;;
"--libc") "--integration-windows") { integration_windows=true; } ;;
shift "--integration-live-migration") { integration_live_migration=true; } ;;
[[ "$1" =~ ^(musl|gnu)$ ]] || \ "--metrics") { metrics=true; } ;;
die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"." "--libc")
libc="$1" shift
;; [[ "$1" =~ ^(musl|gnu)$ ]] ||
"--volumes") die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"."
shift libc="$1"
arg_vols="$1" ;;
;; "--volumes")
"--hypervisor") shift
shift arg_vols="$1"
hypervisor="$1" ;;
;; "--hypervisor")
"--all") { cargo=true; unit=true; integration=true; } ;; shift
"--") { shift; break; } ;; hypervisor="$1"
*) ;;
die "Unknown tests argument: $1. Please use --help for help." "--all") {
;; cargo=true
esac unit=true
shift integration=true
} ;;
"--") {
shift
break
} ;;
*)
die "Unknown tests argument: $1. Please use --help for help."
;;
esac
shift
done done
if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then
die "Hypervisor value must be kvm or mshv" die "Hypervisor value must be kvm or mshv"
fi fi
@@ -355,142 +370,142 @@ cmd_tests() {
process_volumes_args process_volumes_args
target="$(uname -m)-unknown-linux-${libc}" target="$(uname -m)-unknown-linux-${libc}"
if [[ "$unit" = true ]] ; then if [[ "$unit" = true ]]; then
say "Running unit tests for $target..." say "Running unit tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--device $exported_device \ --device $exported_device \
--device /dev/net/tun \ --device /dev/net/tun \
--cap-add net_admin \ --cap-add net_admin \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--env BUILD_TARGET="$target" \ --env BUILD_TARGET="$target" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_unit_tests.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_unit_tests.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$cargo" = true ] ; then if [ "$cargo" = true ]; then
say "Running cargo tests..." say "Running cargo tests..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_cargo_tests.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_cargo_tests.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$integration" = true ] ; then if [ "$integration" = true ]; then
say "Running integration tests for $target..." say "Running integration tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_integration_tests_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_integration_tests_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$integration_sgx" = true ] ; then if [ "$integration_sgx" = true ]; then
say "Running SGX integration tests for $target..." say "Running SGX integration tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_integration_tests_sgx.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_integration_tests_sgx.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$integration_vfio" = true ] ; then if [ "$integration_vfio" = true ]; then
say "Running VFIO integration tests for $target..." say "Running VFIO integration tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_integration_tests_vfio.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_integration_tests_vfio.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$integration_windows" = true ] ; then if [ "$integration_windows" = true ]; then
say "Running Windows integration tests for $target..." say "Running Windows integration tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_integration_tests_windows.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_integration_tests_windows.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$integration_live_migration" = true ] ; then if [ "$integration_live_migration" = true ]; then
say "Running 'live migration' integration tests for $target..." say "Running 'live migration' integration tests for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_integration_tests_live_migration.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_integration_tests_live_migration.sh "$@" || fix_dir_perms $? || exit $?
fi fi
if [ "$metrics" = true ] ; then if [ "$metrics" = true ]; then
say "Generating performance metrics for $target..." say "Generating performance metrics for $target..."
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--mount type=tmpfs,destination=/tmp \ --mount type=tmpfs,destination=/tmp \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--env CH_LIBC="${libc}" \ --env CH_LIBC="${libc}" \
"$CTR_IMAGE" \ "$CTR_IMAGE" \
./scripts/run_metrics.sh "$@" || fix_dir_perms $? || exit $? ./scripts/run_metrics.sh "$@" || fix_dir_perms $? || exit $?
fi fi
fix_dir_perms $? fix_dir_perms $?
@@ -500,15 +515,21 @@ cmd_build-container() {
container_type="dev" container_type="dev"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
"-h"|"--help") { cmd_help; exit 1; } ;; "-h" | "--help") {
"--dev") { container_type="dev"; } ;; cmd_help
"--") { shift; break; } ;; exit 1
*) } ;;
die "Unknown build-container argument: $1. Please use --help for help." "--dev") { container_type="dev"; } ;;
;; "--") {
esac shift
shift break
} ;;
*)
die "Unknown build-container argument: $1. Please use --help for help."
;;
esac
shift
done done
ensure_build_dir ensure_build_dir
@@ -523,26 +544,32 @@ cmd_build-container() {
[ "$(uname -m)" = "x86_64" ] && TARGETARCH="amd64" [ "$(uname -m)" = "x86_64" ] && TARGETARCH="amd64"
$DOCKER_RUNTIME build \ $DOCKER_RUNTIME build \
--target $container_type \ --target $container_type \
-t $CTR_IMAGE \ -t $CTR_IMAGE \
-f $BUILD_DIR/Dockerfile \ -f $BUILD_DIR/Dockerfile \
--build-arg TARGETARCH=$TARGETARCH \ --build-arg TARGETARCH=$TARGETARCH \
$BUILD_DIR $BUILD_DIR
} }
cmd_shell() { cmd_shell() {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
"-h"|"--help") { cmd_help; exit 1; } ;; "-h" | "--help") {
"--volumes") cmd_help
shift exit 1
arg_vols="$1" } ;;
;; "--volumes")
"--") { shift; break; } ;; shift
*) arg_vols="$1"
;; ;;
esac "--") {
shift shift
break
} ;;
*) ;;
esac
shift
done done
ensure_build_dir ensure_build_dir
ensure_latest_ctr ensure_latest_ctr
@@ -550,20 +577,20 @@ cmd_shell() {
say_warn "Starting a privileged shell prompt as root ..." say_warn "Starting a privileged shell prompt as root ..."
say_warn "WARNING: Your $CLH_ROOT_DIR folder will be bind-mounted in the container under $CTR_CLH_ROOT_DIR" say_warn "WARNING: Your $CLH_ROOT_DIR folder will be bind-mounted in the container under $CTR_CLH_ROOT_DIR"
$DOCKER_RUNTIME run \ $DOCKER_RUNTIME run \
-ti \ -ti \
--workdir "$CTR_CLH_ROOT_DIR" \ --workdir "$CTR_CLH_ROOT_DIR" \
--rm \ --rm \
--privileged \ --privileged \
--security-opt seccomp=unconfined \ --security-opt seccomp=unconfined \
--ipc=host \ --ipc=host \
--net="$CTR_CLH_NET" \ --net="$CTR_CLH_NET" \
--tmpfs /tmp:exec \ --tmpfs /tmp:exec \
--volume /dev:/dev \ --volume /dev:/dev \
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \ --volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" "$exported_volumes" \
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \ --volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
--env USER="root" \ --env USER="root" \
--entrypoint bash \ --entrypoint bash \
"$CTR_IMAGE" "$CTR_IMAGE"
fix_dir_perms $? fix_dir_perms $?
} }
@@ -572,14 +599,17 @@ cmd_shell() {
# #
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
-h|--help) { cmd_help; exit 1; } ;; -h | --help) {
-y|--unattended) { OPT_UNATTENDED=true; } ;; cmd_help
-*) exit 1
die "Unknown arg: $1. Please use \`$0 help\` for help." } ;;
;; -y | --unattended) { OPT_UNATTENDED=true; } ;;
*) -*)
break die "Unknown arg: $1. Please use \`$0 help\` for help."
;; ;;
*)
break
;;
esac esac
shift shift
done done
@@ -587,11 +617,10 @@ done
# $1 is now a command name. Check if it is a valid command and, if so, # $1 is now a command name. Check if it is a valid command and, if so,
# run it. # run it.
# #
declare -f "cmd_$1" > /dev/null declare -f "cmd_$1" >/dev/null
ok_or_die "Unknown command: $1. Please use \`$0 help\` for help." ok_or_die "Unknown command: $1. Please use \`$0 help\` for help."
cmd=cmd_$1 cmd=cmd_$1
shift shift
$cmd "$@" $cmd "$@"