- Update ToolboxStack/output/toolbox-template/Dockerfile with template container configurations - Update ToolboxStack/output/toolbox-template/build.sh with template build process - Update ToolboxStack/output/toolbox-template/run.sh with template runtime configuration These changes improve the toolbox template for creating new developer environments.
82 lines
2.6 KiB
Bash
Executable File
82 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# Security: Validate input parameters to prevent command injection
|
|
sanitized_input() {
|
|
local input="$1"
|
|
# Check for potentially dangerous characters/commands
|
|
case "$input" in
|
|
*[\;\|\&\`\$]*)
|
|
echo "Error: Invalid input detected: $input" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Validate dependencies
|
|
if ! command -v docker &> /dev/null; then
|
|
echo "Error: docker is required but not installed." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! docker buildx version &> /dev/null; then
|
|
echo "Error: docker buildx is required but not available." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Get the toolbox name from the directory name (or you can pass it as an argument)
|
|
TOOLBOX_NAME="${TOOLBOX_NAME_OVERRIDE:-$(basename "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")}"
|
|
sanitized_input "$TOOLBOX_NAME"
|
|
IMAGE_NAME="tsysdevstack-toolboxstack-${TOOLBOX_NAME#toolbox-}"
|
|
sanitized_input "$IMAGE_NAME"
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Sanitize user input
|
|
USER_ID="${USER_ID_OVERRIDE:-$(id -u)}"
|
|
sanitized_input "$USER_ID"
|
|
GROUP_ID="${GROUP_ID_OVERRIDE:-$(id -g)}"
|
|
sanitized_input "$GROUP_ID"
|
|
USERNAME="${USERNAME_OVERRIDE:-toolbox}"
|
|
sanitized_input "$USERNAME"
|
|
TEA_VERSION="${TEA_VERSION_OVERRIDE:-0.11.1}"
|
|
sanitized_input "$TEA_VERSION"
|
|
BUILDER_NAME="${BUILDER_NAME:-tsysdevstack-toolboxstack-builder}"
|
|
sanitized_input "$BUILDER_NAME"
|
|
CACHE_DIR="${SCRIPT_DIR}/.build-cache"
|
|
|
|
echo "Building ${IMAGE_NAME} with UID=${USER_ID} GID=${GROUP_ID} USERNAME=${USERNAME}"
|
|
|
|
if ! docker buildx inspect "${BUILDER_NAME}" >/dev/null 2>&1; then
|
|
echo "Creating builder: ${BUILDER_NAME}"
|
|
docker buildx create --driver docker-container --name "${BUILDER_NAME}" --use >/dev/null
|
|
else
|
|
echo "Using existing builder: ${BUILDER_NAME}"
|
|
docker buildx use "${BUILDER_NAME}" >/dev/null
|
|
fi
|
|
|
|
mkdir -p "${CACHE_DIR}"
|
|
|
|
echo "Starting build..."
|
|
docker buildx build \
|
|
--builder "${BUILDER_NAME}" \
|
|
--load \
|
|
--progress=plain \
|
|
--build-arg USER_ID="${USER_ID}" \
|
|
--build-arg GROUP_ID="${GROUP_ID}" \
|
|
--build-arg USERNAME="${USERNAME}" \
|
|
--build-arg TEA_VERSION="${TEA_VERSION}" \
|
|
--cache-from "type=local,src=${CACHE_DIR}" \
|
|
--cache-to "type=local,dest=${CACHE_DIR},mode=max" \
|
|
--tag "${IMAGE_NAME}" \
|
|
"${SCRIPT_DIR}"
|
|
|
|
echo "Build completed successfully."
|
|
|
|
# Run security scan if TRIVY is available
|
|
if command -v trivy &> /dev/null; then
|
|
echo "Running security scan with Trivy..."
|
|
trivy image --exit-code 0 --severity HIGH,CRITICAL "${IMAGE_NAME}"
|
|
else
|
|
echo "Trivy not found. Install Trivy to perform security scanning."
|
|
fi |