#!/usr/bin/env bash # Script to build the tsysdevstack-toolboxes-docs container set -e # Default values IMAGE_NAME="tsysdevstack/toolbox-docs" BUILD_ARGS="" PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7" # Support PC, Raspberry Pi, Mac M series # Function to display usage usage() { echo "Usage: $0 [OPTIONS]" echo "Options:" echo " -p, --platform PLATFORM Target platform (default: all supported)" echo " -t, --tag TAG Tag for the image (default: latest)" echo " -c, --cache Use build cache (default: true)" echo " --no-cache Skip build cache" echo " --push Push image to registry after building" echo " -h, --help Show this help message" echo "" echo "Examples:" echo " $0 # Build for all platforms" echo " $0 -p linux/amd64 # Build for x86_64" echo " $0 -t v1.0.0 # Build with specific tag" echo " $0 --no-cache # Build without cache" echo " $0 --push # Build and push to registry" } # Parse command line arguments PLATFORM="" TAG="latest" USE_CACHE=true PUSH=false while [[ $# -gt 0 ]]; do case $1 in -p|--platform) PLATFORM="$2" shift 2 ;; -t|--tag) TAG="$2" shift 2 ;; -c|--cache) USE_CACHE=true shift ;; --no-cache) USE_CACHE=false shift ;; --push) PUSH=true shift ;; -h|--help) usage exit 0 ;; *) echo "Unknown option: $1" usage exit 1 ;; esac done # Build the image using Docker Buildx for multi-platform support echo "Building tsysdevstack/toolbox-docs Docker image..." # Create buildx builder if it doesn't exist if ! docker buildx ls | grep -q "tsysdevstack-builder"; then echo "Creating buildx builder instance..." docker buildx create --name tsysdevstack-builder --use --bootstrap fi # Prepare build arguments BUILD_ARGS="--progress=plain --platform=${PLATFORM:-$PLATFORMS} --tag ${IMAGE_NAME}:${TAG}" if [ "$USE_CACHE" = false ]; then BUILD_ARGS="$BUILD_ARGS --no-cache" fi if [ "$PUSH" = true ]; then BUILD_ARGS="$BUILD_ARGS --push" else BUILD_ARGS="$BUILD_ARGS --load" # Load to local Docker image store fi # Execute the build command BUILD_CMD="docker buildx build $BUILD_ARGS ." echo "Running: $BUILD_CMD" if eval "$BUILD_CMD"; then echo "Build completed successfully!" if [ "$PUSH" = true ]; then echo "Image pushed to registry." else echo "Image loaded to local Docker image store." fi else echo "Build failed!" exit 1 fi