|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2026 Dell Inc. or its subsidiaries. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# ============================================================================= |
| 18 | +# build_images.sh — BuildStream Container Build (Self-Contained) |
| 19 | +# ============================================================================= |
| 20 | +# Builds the omnia_build_stream container (FastAPI build automation + S3). |
| 21 | +# |
| 22 | +# Usage: |
| 23 | +# ./build_images.sh # Build (default) |
| 24 | +# ./build_images.sh build_stream_tag=1.2 # Custom tag |
| 25 | +# ./build_images.sh build_tool=docker # Use docker |
| 26 | +# ./build_images.sh build_tool=docker build_action=push # Push to registry |
| 27 | +# ./build_images.sh registry=myregistry.io/myrepo # Custom registry |
| 28 | +# |
| 29 | +# Parameters: |
| 30 | +# build_stream_tag=<tag> Image tag (default: 1.1) |
| 31 | +# build_tool=<tool> podman | docker (default: podman) |
| 32 | +# build_action=<action> load | push (default: load) |
| 33 | +# registry=<url> Registry URL (default: docker.io/dellhpcomniaaisolution) |
| 34 | +# ============================================================================= |
| 35 | + |
| 36 | +set -euo pipefail |
| 37 | + |
| 38 | +# ── Resolve paths ── |
| 39 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 40 | + |
| 41 | +# ── Color codes ── |
| 42 | +RED='\033[0;31m' |
| 43 | +GREEN='\033[0;32m' |
| 44 | +BLUE='\033[34m' |
| 45 | +YELLOW='\033[1;33m' |
| 46 | +NC='\033[0m' |
| 47 | + |
| 48 | +# ============================================================================= |
| 49 | +# Show help |
| 50 | +# ============================================================================= |
| 51 | +show_help() { |
| 52 | + echo -e "${GREEN}BuildStream Container Build Script${NC}" |
| 53 | + echo -e "${GREEN}======================================${NC}" |
| 54 | + echo "" |
| 55 | + echo -e "${BLUE}USAGE:${NC}" |
| 56 | + echo " ./build_images.sh [parameters]" |
| 57 | + echo "" |
| 58 | + echo -e "${BLUE}PARAMETERS (key=value format):${NC}" |
| 59 | + echo " build_stream_tag=<tag> Image tag (default: 1.1)" |
| 60 | + echo " build_tool=<tool> podman | docker (default: podman)" |
| 61 | + echo " build_action=<action> load | push (default: load)" |
| 62 | + echo " registry=<url> Registry URL (default: docker.io/dellhpcomniaaisolution)" |
| 63 | + echo "" |
| 64 | + echo -e "${BLUE}EXAMPLES:${NC}" |
| 65 | + echo " ./build_images.sh" |
| 66 | + echo " ./build_images.sh build_stream_tag=1.2" |
| 67 | + echo " ./build_images.sh build_tool=docker" |
| 68 | + echo " ./build_images.sh build_tool=docker build_action=push" |
| 69 | + echo " ./build_images.sh registry=myregistry.io/myrepo" |
| 70 | + echo "" |
| 71 | + echo -e "${BLUE}NOTES:${NC}" |
| 72 | + echo " - build_action=push requires build_tool=docker" |
| 73 | + echo " - Default registry: docker.io/dellhpcomniaaisolution" |
| 74 | + echo " - Builds the omnia_build_stream container (FastAPI + S3)" |
| 75 | + exit 0 |
| 76 | +} |
| 77 | + |
| 78 | +# ============================================================================= |
| 79 | +# Default parameterized values |
| 80 | +# ============================================================================= |
| 81 | +BUILD_TOOL="podman" |
| 82 | +BUILD_ACTION="load" |
| 83 | +OMNIA_DOCKER_REGISTERY="docker.io/dellhpcomniaaisolution" |
| 84 | +BUILD_STREAM_TAG="1.1" |
| 85 | + |
| 86 | +# ============================================================================= |
| 87 | +# Parse command-line parameters (key=value format) |
| 88 | +# ============================================================================= |
| 89 | +for arg in "$@"; do |
| 90 | + case "$arg" in |
| 91 | + build_tool=*) BUILD_TOOL="${arg#*=}" ;; |
| 92 | + build_action=*) BUILD_ACTION="${arg#*=}" ;; |
| 93 | + registry=*) OMNIA_DOCKER_REGISTERY="${arg#*=}" ;; |
| 94 | + build_stream_tag=*) BUILD_STREAM_TAG="${arg#*=}" ;; |
| 95 | + -h|--help) |
| 96 | + show_help |
| 97 | + ;; |
| 98 | + *) |
| 99 | + echo -e "${RED}Error: Unknown parameter '$arg'${NC}" |
| 100 | + echo -e "${YELLOW}Valid: build_stream_tag, build_tool, build_action, registry${NC}" |
| 101 | + exit 1 |
| 102 | + ;; |
| 103 | + esac |
| 104 | +done |
| 105 | + |
| 106 | +# ============================================================================= |
| 107 | +# Validate inputs |
| 108 | +# ============================================================================= |
| 109 | +if [[ "$BUILD_TOOL" != "podman" && "$BUILD_TOOL" != "docker" ]]; then |
| 110 | + echo -e "${RED}Error: Invalid build_tool '${BUILD_TOOL}'. Valid: podman, docker${NC}" |
| 111 | + exit 1 |
| 112 | +fi |
| 113 | + |
| 114 | +if [[ "$BUILD_ACTION" != "load" && "$BUILD_ACTION" != "push" ]]; then |
| 115 | + echo -e "${RED}Error: Invalid build_action '${BUILD_ACTION}'. Valid: load, push${NC}" |
| 116 | + exit 1 |
| 117 | +fi |
| 118 | + |
| 119 | +if [[ "$BUILD_ACTION" == "push" && "$BUILD_TOOL" != "docker" ]]; then |
| 120 | + echo -e "${RED}Error: build_action=push requires build_tool=docker${NC}" |
| 121 | + exit 1 |
| 122 | +fi |
| 123 | + |
| 124 | +# ============================================================================= |
| 125 | +# Build omnia_build_stream container |
| 126 | +# ============================================================================= |
| 127 | +echo -e "${GREEN}=======================================${NC}" |
| 128 | +echo -e "${GREEN} BuildStream — Container Build ${NC}" |
| 129 | +echo -e "${GREEN}=======================================${NC}" |
| 130 | +echo -e "${BLUE}Build tool: ${BUILD_TOOL}${NC}" |
| 131 | +echo -e "${BLUE}Build action: ${BUILD_ACTION}${NC}" |
| 132 | +echo -e "${BLUE}Tag: ${BUILD_STREAM_TAG}${NC}" |
| 133 | +echo "" |
| 134 | + |
| 135 | +BUILD_DIR="${SCRIPT_DIR}/omnia_build_stream" |
| 136 | + |
| 137 | +cd "$BUILD_DIR" || exit 1 |
| 138 | + |
| 139 | +BUILD_RESULT=0 |
| 140 | + |
| 141 | +if [ "$BUILD_TOOL" = "podman" ]; then |
| 142 | + podman build -t "omnia_build_stream:${BUILD_STREAM_TAG}" -f "Containerfile" . |
| 143 | + BUILD_RESULT=$? |
| 144 | +elif [ "$BUILD_TOOL" = "docker" ]; then |
| 145 | + if [ "$BUILD_ACTION" = "load" ]; then |
| 146 | + docker buildx build --no-cache -t "omnia_build_stream:${BUILD_STREAM_TAG}" \ |
| 147 | + --file "Containerfile" --platform "linux/amd64" --network=host --load . |
| 148 | + BUILD_RESULT=$? |
| 149 | + elif [ "$BUILD_ACTION" = "push" ]; then |
| 150 | + docker buildx build --no-cache \ |
| 151 | + -t "${OMNIA_DOCKER_REGISTERY}/omnia_build_stream:${BUILD_STREAM_TAG}" \ |
| 152 | + --file "Containerfile" --platform "linux/amd64" --network=host \ |
| 153 | + --provenance=true --sbom=true --push . |
| 154 | + BUILD_RESULT=$? |
| 155 | + fi |
| 156 | +fi |
| 157 | + |
| 158 | +cd - > /dev/null || exit 1 |
| 159 | + |
| 160 | +if [ $BUILD_RESULT -eq 0 ]; then |
| 161 | + echo -e "\n${GREEN}omnia_build_stream:${BUILD_STREAM_TAG} built successfully.${NC}" |
| 162 | + if [ "$BUILD_TOOL" = "docker" ] && [ "$BUILD_ACTION" = "push" ]; then |
| 163 | + echo -e "${GREEN}Pushed: ${OMNIA_DOCKER_REGISTERY}/omnia_build_stream:${BUILD_STREAM_TAG}${NC}" |
| 164 | + fi |
| 165 | +else |
| 166 | + echo -e "\n${RED}omnia_build_stream:${BUILD_STREAM_TAG} build FAILED.${NC}" |
| 167 | + exit 1 |
| 168 | +fi |
0 commit comments