#!/usr/bin/env bash # Script to run the tsysdevstack-toolboxes-docs container set -e # Default values CONTAINER_NAME="tsysdevstack-toolboxes-docs" IMAGE_NAME="tsysdevstack/toolbox-docs:latest" WORKDIR="/home/tsysdevstack/docs" # Function to display usage usage() { echo "Usage: $0 [OPTIONS]" echo "Options:" echo " -i, --interactive Run container interactively (default)" echo " -b, --build Build the image before running" echo " -d, --detached Run container in detached mode" echo " -h, --help Show this help message" echo "" echo "Examples:" echo " $0 # Run interactively (default)" echo " $0 -d # Run in detached mode" echo " $0 -b # Build image and run" echo " $0 -b -d # Build image and run in detached mode" } # Parse command line arguments INTERACTIVE=true DETACHED=false BUILD=false while [[ $# -gt 0 ]]; do case $1 in -i|--interactive) INTERACTIVE=true shift ;; -d|--detached) DETACHED=true INTERACTIVE=false shift ;; -b|--build) BUILD=true shift ;; -h|--help) usage exit 0 ;; *) echo "Unknown option: $1" usage exit 1 ;; esac done # If both interactive and detached are false, default to interactive if [ "$INTERACTIVE" = true ] && [ "$DETACHED" = false ]; then # Default behavior remains interactive : fi # Build the image if requested if [ "$BUILD" = true ]; then echo "Building the Docker image..." docker build -t "$IMAGE_NAME" . fi # Prepare docker run command DOCKER_RUN_CMD="docker run --rm" # Add user mapping to match host user if [ -n "${UID:-}" ] && [ -n "${GID:-}" ]; then DOCKER_RUN_CMD="$DOCKER_RUN_CMD --user $UID:$GID" else # Fallback to default user ID DOCKER_RUN_CMD="$DOCKER_RUN_CMD --user 1000:1000" fi # Add volume mounts SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DOCKER_RUN_CMD="$DOCKER_RUN_CMD -v $SCRIPT_DIR/docs:$WORKDIR" DOCKER_RUN_CMD="$DOCKER_RUN_CMD -v $SCRIPT_DIR/output:/home/tsysdevstack/output" # Add container name DOCKER_RUN_CMD="$DOCKER_RUN_CMD --name $CONTAINER_NAME" # Add detached mode flag if requested if [ "$DETACHED" = true ]; then DOCKER_RUN_CMD="$DOCKER_RUN_CMD -d" else # Add interactive and TTY flags for interactive mode DOCKER_RUN_CMD="$DOCKER_RUN_CMD -it" fi # Add image name DOCKER_RUN_CMD="$DOCKER_RUN_CMD $IMAGE_NAME" # Run the container echo "Running: $DOCKER_RUN_CMD" eval "$DOCKER_RUN_CMD"