Skip to content

Commit

Permalink
Add build_and_install and update build_and_run with container_args
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp committed Aug 28, 2024
1 parent c589da4 commit 5f63ce2
Showing 1 changed file with 152 additions and 3 deletions.
155 changes: 152 additions & 3 deletions dev_container
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,143 @@ launch() {
"$@"
}

build_and_install_desc() { c_echo 'Build the application and install the binaries into install/<app> if supported
Usage: ./dev_container install <application_name>
Options:
--base_img : Fully qualified base image name, e.g. holoscan-sdk-dev:latest
--docker_file : Path to Dockerfile to use for building container.
Defaults to:
- Application-provided "Dockerfile", if it exists;
- Otherwise the top-level HoloHub "Dockerfile"
If `--img` is not specified then a custom image tag will be defined.
--language : Specify the app language implementation to run.
Some applications provide both `cpp` and `python` implementations.
--container_args: Additional Docker run args.
--build_args : Build the app with additional CMake configuration arguments
--build_with : List of optional operators that should be built separated by semicolons (;)
--verbose : Print extra output to console
--dryrun : View build and run commands without doing anything
'
}

build_and_install() {
local app_name=""
local app_language=""
local container_build_args=""
local container_launch_args=""
local docker_opts="--entrypoint=bash"
local image_name=""
local docker_file=""
local extra_build_args=""
local extra_build_with=""

# Parse CLI arguments next
while [[ $# -gt 0 ]]; do
case "$1" in
--base_img)
if [[ -n "$2" && ! "$2" =~ ^-- ]]; then
container_build_args+=" --base_img $2"
shift 2
else
echo "Error: --base_img requires a value"
build_and_run_desc
exit 1
fi
;;
--docker_file)
if [[ -n "$2" && ! "$2" =~ ^-- ]]; then
docker_file="$2"
shift 2
else
echo "Error: --docker_file requires a value"
build_and_run_desc
exit 1
fi
;;
--container_args)
if [[ -n "$2" ]]; then
docker_opts+=" $2"
shift 2
else
echo "Error: --container_args requires a value"
build_and_run_desc
exit 1
fi
;;
--build_args)
if [[ -n "$2" ]]; then
extra_build_args="--configure-args '$2'"
shift 2
else
echo "Error: --build_args requires a value"
build_and_run_desc
exit 1
fi
;;
--build_with)
if [[ -n "$2" ]]; then
extra_build_with="--with '$2'"
shift 2
else
echo "Error: --build_with requires a value"
build_and_run_desc
exit 1
fi
;;
--verbose)
container_build_args+=" --verbose"
container_launch_args+=" --verbose"
shift
;;
--language)
if [[ -n "$2" && ! "$2" =~ ^-- ]]; then
app_language="$2"
shift 2
else
echo "Error: --language requires a value"
build_and_run_desc
exit 1
fi
;;
*)
if [[ -z "$app_name" ]]; then
app_name="$1"
shift
else
echo "Error: Invalid argument '$1'"
build_and_run_desc
exit 1
fi
;;
esac
done
if [ -z "${app_name}" ]; then
fatal "Must specify a HoloHub application to build and run."
fi

if [[ -z "${docker_file}" ]]; then
docker_file=$(./run get_app_dockerfile ${app_name} ${app_language:-cpp})
fi
if [[ -n "${docker_file}" ]]; then
container_build_args+=" --docker_file ${docker_file}"
fi

if [[ -z "$image_name" ]]; then
if [[ -n "${docker_file}" ]] && [[ "${docker_file}" != "${SCRIPT_DIR}/Dockerfile" ]]; then
image_name="holohub:${app_name}"
else
image_name=$(get_default_img)
fi
fi

container_build_args+=" --img $image_name"
container_launch_args+=" --img $image_name"

run_command ${SCRIPT_DIR}/dev_container build $container_build_args
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name --install $extra_build_with $extra_build_args"

}

build_and_run_desc() { c_echo 'Build and run a requested application in a Docker container
Usage: ./dev_container build_and_run <application_name> [options]
Options:
Expand All @@ -826,6 +963,7 @@ build_and_run_desc() { c_echo 'Build and run a requested application in a Docker
- Otherwise the top-level HoloHub "Dockerfile"
If `--img` is not specified then a custom image tag will be defined.
--img : Specify fully qualified output container name
--container_args: Additional Docker run args.
--language : Specify the app language implementation to run.
Some applications provide both `cpp` and `python` implementations.
--no_build : Launch the app without attempting to build it first
Expand All @@ -841,7 +979,8 @@ build_and_run() {
local app_name=""
local app_language=""
local container_build_args=""
local container_launch_args="--docker_opts --entrypoint=bash"
local container_launch_args=""
local docker_opts="--entrypoint=bash"
local build_app=1
local image_name=""
local docker_file=""
Expand Down Expand Up @@ -941,6 +1080,16 @@ build_and_run() {
exit 1
fi
;;
--container_args)
if [[ -n "$2" ]]; then
docker_opts+=" $2"
shift 2
else
echo "Error: --container_args requires a value"
build_and_run_desc
exit 1
fi
;;
*)
if [[ -z "$app_name" ]]; then
app_name="$1"
Expand Down Expand Up @@ -978,9 +1127,9 @@ build_and_run() {

run_command ${SCRIPT_DIR}/dev_container build $container_build_args
if [[ $build_app == 1 ]]; then
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args -- -c "./run build $app_name $extra_build_with $extra_build_args"
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name $extra_build_with $extra_build_args"
fi
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args -- -c "./run launch $app_name $app_language $extra_run_args"
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run launch $app_name $app_language $extra_run_args"
}

vscode_desc() { c_echo 'Launch VS Code in Dev Container
Expand Down

0 comments on commit 5f63ce2

Please sign in to comment.