- Add src/build.sh for Docker-based ISO building - Add src/run-new.sh with enhanced container management - Add src/run.sh as host wrapper for build process 💘 Generated with Crush Assisted-by: GLM-4.6 via Crush <crush@charm.land>
292 lines
5.6 KiB
Bash
Executable File
292 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Enhanced version of the original run.sh script with explicit container management
|
|
set -euo pipefail
|
|
|
|
# Project metadata
|
|
readonly PROJECT_NAME="KNEL Football"
|
|
readonly VERSION="1.0.0"
|
|
|
|
# Configuration
|
|
readonly DOCKER_IMAGE="${DOCKER_IMAGE:-knel-football-dev:latest}" # Using required knel-football-dev image
|
|
readonly CONTAINER_PREFIX="knel-football"
|
|
readonly PROXY_ENABLED="${PROXY_ENABLED:-true}"
|
|
readonly PROXY_URL="${PROXY_URL:-http://10.0.0.1:3128}"
|
|
|
|
# Source utility functions
|
|
source "$(dirname "$0")/lib/docker.sh"
|
|
|
|
# Logging function
|
|
log() {
|
|
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"
|
|
}
|
|
|
|
# Usage information
|
|
usage() {
|
|
cat <<EOF
|
|
$PROJECT_NAME v$VERSION
|
|
Containerized ISO build and security hardening framework
|
|
|
|
USAGE:
|
|
$0 [OPTIONS] [COMMAND]
|
|
|
|
COMMANDS:
|
|
build Build Docker image
|
|
lint Run lint checks
|
|
test Run tests
|
|
test:unit Run unit tests
|
|
test:integration Run integration tests
|
|
test:functional Run functional tests
|
|
shell Start interactive shell
|
|
clean Clean build artifacts
|
|
iso Build ISO image
|
|
secure Generate security configuration
|
|
deploy Prepare deployment package
|
|
help Show this help message
|
|
|
|
OPTIONS:
|
|
-v, --verbose Enable verbose output
|
|
-q, --quiet Suppress non-error output
|
|
-e, --env Set environment variable (can be multiple)
|
|
--no-cache Build without using cache
|
|
--proxy Use proxy for network operations
|
|
--no-proxy Disable proxy for network operations
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
DOCKER_IMAGE Docker image to use (default: knel-football-dev:latest)
|
|
PROXY_ENABLED Enable/disable proxy (default: true)
|
|
PROXY_URL Proxy URL (default: http://10.0.0.1:3128)
|
|
|
|
EXAMPLES:
|
|
$0 build
|
|
$0 lint
|
|
$0 test
|
|
$0 shell
|
|
$0 iso
|
|
$0 clean
|
|
$0 -v --no-proxy test:unit
|
|
|
|
For more information, see: README.md
|
|
EOF
|
|
}
|
|
|
|
# Parse command line arguments
|
|
VERBOSE=false
|
|
QUIET=false
|
|
NO_CACHE=false
|
|
USE_PROXY=$PROXY_ENABLED
|
|
ENV_VARS=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-v | --verbose)
|
|
VERBOSE=true
|
|
QUIET=false
|
|
shift
|
|
;;
|
|
-q | --quiet)
|
|
QUIET=true
|
|
VERBOSE=false
|
|
shift
|
|
;;
|
|
-e | --env)
|
|
ENV_VARS+=("$2")
|
|
shift 2
|
|
;;
|
|
--no-cache)
|
|
NO_CACHE=true
|
|
shift
|
|
;;
|
|
--proxy)
|
|
USE_PROXY=true
|
|
shift
|
|
;;
|
|
--no-proxy)
|
|
USE_PROXY=false
|
|
shift
|
|
;;
|
|
-h | --help | help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
build | lint | test | test:unit | test:integration | test:functional | shell | clean | iso | secure | deploy)
|
|
COMMAND="$1"
|
|
shift
|
|
break
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Set default command
|
|
COMMAND="${COMMAND:-help}"
|
|
|
|
# Logging with verbosity control
|
|
log_info() {
|
|
if [ "$QUIET" = false ]; then
|
|
log "INFO: $*"
|
|
fi
|
|
}
|
|
|
|
log_error() {
|
|
log "ERROR: $*" >&2
|
|
}
|
|
|
|
log_debug() {
|
|
if [ "$VERBOSE" = true ]; then
|
|
log "DEBUG: $*"
|
|
fi
|
|
}
|
|
|
|
# Container management
|
|
run_with_container() {
|
|
local cmd="$1"
|
|
local container_name="${CONTAINER_PREFIX}-${cmd}"
|
|
shift
|
|
|
|
log_info "Starting container: $container_name"
|
|
log_debug "Command: $*"
|
|
|
|
# Build environment arguments
|
|
local env_args=()
|
|
for env_var in "${ENV_VARS[@]}"; do
|
|
env_args+=("-e" "$env_var")
|
|
done
|
|
|
|
if [ "$USE_PROXY" = true ]; then
|
|
env_args+=("-e" "http_proxy=$PROXY_URL")
|
|
env_args+=("-e" "https_proxy=$PROXY_URL")
|
|
fi
|
|
|
|
# Run container with explicit name and environment
|
|
docker run --name "$container_name" \
|
|
--env-file <(grep -v '^#' "$(dirname "$0")/.env" 2>/dev/null || true) \
|
|
"${env_args[@]}" \
|
|
-v "$(pwd)":/workspace:ro \
|
|
-v "$(pwd)/tmp":/build \
|
|
-v "$(pwd)/output":/output \
|
|
-e TZ="UTC" \
|
|
-e DEBIAN_FRONTEND="noninteractive" \
|
|
-e LC_ALL="C" \
|
|
--rm \
|
|
"$DOCKER_IMAGE" \
|
|
"$@"
|
|
}
|
|
|
|
# Main command handlers
|
|
cmd_build() {
|
|
log_info "Building Docker image: $DOCKER_IMAGE"
|
|
|
|
local build_args=()
|
|
if [ "$NO_CACHE" = true ]; then
|
|
build_args+=("--no-cache")
|
|
fi
|
|
|
|
if [ "$USE_PROXY" = true ]; then
|
|
build_args+=("--build-arg" "http_proxy=$PROXY_URL")
|
|
build_args+=("--build-arg" "https_proxy=$PROXY_URL")
|
|
fi
|
|
|
|
docker build "${build_args[@]}" -t "$DOCKER_IMAGE" "$(dirname "$0")"
|
|
}
|
|
|
|
cmd_lint() {
|
|
log_info "Running lint checks"
|
|
run_with_container "lint" make lint
|
|
}
|
|
|
|
cmd_test() {
|
|
log_info "Running all tests"
|
|
run_with_container "test" make test
|
|
}
|
|
|
|
cmd_test_unit() {
|
|
log_info "Running unit tests"
|
|
run_with_container "test-unit" make test-unit
|
|
}
|
|
|
|
cmd_test_integration() {
|
|
log_info "Running integration tests"
|
|
run_with_container "test-integration" make test-integration
|
|
}
|
|
|
|
cmd_test_functional() {
|
|
log_info "Running functional tests"
|
|
run_with_container "test-functional" make test-functional
|
|
}
|
|
|
|
cmd_shell() {
|
|
log_info "Starting interactive shell"
|
|
run_with_container "shell" /bin/bash
|
|
}
|
|
|
|
cmd_clean() {
|
|
log_info "Cleaning build artifacts"
|
|
rm -rf "$(dirname "$0")/tmp"
|
|
mkdir -p "$(dirname "$0")/tmp"
|
|
log_info "Cleanup completed"
|
|
}
|
|
|
|
cmd_iso() {
|
|
log_info "Building ISO image"
|
|
run_with_container "iso" make iso
|
|
}
|
|
|
|
cmd_secure() {
|
|
log_info "Generating security configuration"
|
|
run_with_container "secure" make secure
|
|
}
|
|
|
|
cmd_deploy() {
|
|
log_info "Preparing deployment package"
|
|
run_with_container "deploy" make deploy
|
|
}
|
|
|
|
# Execute command
|
|
case "$COMMAND" in
|
|
build)
|
|
cmd_build
|
|
;;
|
|
lint)
|
|
cmd_lint
|
|
;;
|
|
test)
|
|
cmd_test
|
|
;;
|
|
test:unit)
|
|
cmd_test_unit
|
|
;;
|
|
test:integration)
|
|
cmd_test_integration
|
|
;;
|
|
test:functional)
|
|
cmd_test_functional
|
|
;;
|
|
shell)
|
|
cmd_shell
|
|
;;
|
|
clean)
|
|
cmd_clean
|
|
;;
|
|
iso)
|
|
cmd_iso
|
|
;;
|
|
secure)
|
|
cmd_secure
|
|
;;
|
|
deploy)
|
|
cmd_deploy
|
|
;;
|
|
help)
|
|
usage
|
|
;;
|
|
*)
|
|
log_error "Unknown command: $COMMAND"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|