From ea4f13cc209e1222aadfab52224a48f687a6d483 Mon Sep 17 00:00:00 2001 From: Reid <61492567+reidliu41@users.noreply.github.com> Date: Sat, 1 Mar 2025 02:07:24 +0800 Subject: [PATCH] chore: add container cmd check (#1306) # What does this PR do? [Provide a short summary of what this PR does and why. Link to relevant issues if applicable.] [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan [Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.*] [//]: # (## Documentation) Signed-off-by: reidliu Co-authored-by: reidliu --- llama_stack/distribution/build_container.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/llama_stack/distribution/build_container.sh b/llama_stack/distribution/build_container.sh index 9b584a85c..68f8a0863 100755 --- a/llama_stack/distribution/build_container.sh +++ b/llama_stack/distribution/build_container.sh @@ -48,6 +48,9 @@ CONTAINER_OPTS=${CONTAINER_OPTS:-} TEMP_DIR=$(mktemp -d) +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +source "$SCRIPT_DIR/common.sh" + add_to_container() { output_file="$TEMP_DIR/Containerfile" if [ -t 0 ]; then @@ -58,6 +61,12 @@ add_to_container() { fi } +# Check if container command is available +if ! is_command_available $CONTAINER_BINARY; then + printf "${RED}Error: ${CONTAINER_BINARY} command not found. Is ${CONTAINER_BINARY} installed and in your PATH?${NC}" >&2 + exit 1 +fi + # Update and install UBI9 components if UBI9 base image is used if [[ $container_base == *"registry.access.redhat.com/ubi9"* ]]; then add_to_container << EOF @@ -212,7 +221,7 @@ if [ "$USE_COPY_NOT_MOUNT" != "true" ]; then fi fi -if command -v selinuxenabled &>/dev/null && selinuxenabled; then +if is_command_available selinuxenabled && selinuxenabled; then # Disable SELinux labels -- we don't want to relabel the llama-stack source dir CLI_ARGS+=("--security-opt" "label=disable") fi