forked from tfgrid/zosbuilder
toolfixes
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Debug script to test container output behavior
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Script directory and project root detection
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo "=== HOST DEBUG TEST ==="
|
||||
echo "SCRIPT_DIR: $SCRIPT_DIR"
|
||||
echo "PROJECT_ROOT: $PROJECT_ROOT"
|
||||
echo "PWD: $(pwd)"
|
||||
echo "USER: $(whoami)"
|
||||
|
||||
# Source common functions
|
||||
source "${SCRIPT_DIR}/lib/common.sh"
|
||||
|
||||
echo "=== AFTER SOURCING COMMON.SH ==="
|
||||
log_info "Testing log_info function"
|
||||
log_warn "Testing log_warn function"
|
||||
log_error "Testing log_error function"
|
||||
|
||||
echo "=== TESTING SAFE_EXECUTE ==="
|
||||
safe_execute echo "Testing safe_execute with simple command"
|
||||
safe_execute ls -la "${SCRIPT_DIR}"
|
||||
|
||||
echo "=== TESTING IN_CONTAINER ==="
|
||||
if in_container; then
|
||||
log_info "Running inside container"
|
||||
else
|
||||
log_info "Running on host"
|
||||
fi
|
||||
|
||||
echo "=== CHECKING DOCKER FUNCTIONS ==="
|
||||
source "${SCRIPT_DIR}/lib/docker.sh"
|
||||
|
||||
if command_exists "podman" || command_exists "docker"; then
|
||||
log_info "Container runtime available, testing container run"
|
||||
|
||||
docker_detect_runtime
|
||||
|
||||
# Test minimal container run
|
||||
log_info "Testing minimal container echo"
|
||||
if [[ -n "${CONTAINER_RUNTIME:-}" ]]; then
|
||||
echo "Running: ${CONTAINER_RUNTIME} run --rm alpine:3.22 echo 'Container test successful'"
|
||||
${CONTAINER_RUNTIME} run --rm alpine:3.22 echo "Container test successful"
|
||||
|
||||
echo "Running: ${CONTAINER_RUNTIME} run --rm alpine:3.22 sh -c 'echo First line; echo Second line; echo Third line'"
|
||||
${CONTAINER_RUNTIME} run --rm alpine:3.22 sh -c 'echo First line; echo Second line; echo Third line'
|
||||
|
||||
echo "Testing with TTY:"
|
||||
${CONTAINER_RUNTIME} run --rm -it alpine:3.22 sh -c 'echo TTY test line 1; echo TTY test line 2'
|
||||
fi
|
||||
else
|
||||
log_warn "No container runtime available"
|
||||
fi
|
||||
|
||||
echo "=== DEBUG TEST COMPLETE ==="
|
||||
@@ -10,6 +10,9 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
CONTAINER_NAME="zero-os-dev"
|
||||
BUILDER_IMAGE="zero-os-builder:latest"
|
||||
|
||||
# Default to verbose, streaming logs for dev flows unless explicitly disabled
|
||||
export DEBUG="${DEBUG:-1}"
|
||||
|
||||
# Source common functions
|
||||
source "${SCRIPT_DIR}/lib/common.sh"
|
||||
|
||||
@@ -38,9 +41,38 @@ Examples:
|
||||
EOF
|
||||
}
|
||||
|
||||
function ensure_builder_image() {
|
||||
section_header "Ensuring Builder Image"
|
||||
# Check for existing image under common tags (short and localhost-qualified)
|
||||
local candidates=("$BUILDER_IMAGE" "localhost/${BUILDER_IMAGE}")
|
||||
for img in "${candidates[@]}"; do
|
||||
if podman image exists "$img" 2>/dev/null; then
|
||||
log_info "Found builder image: ${img}"
|
||||
BUILDER_IMAGE="$img"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
log_warn "Builder image not found locally; building: ${BUILDER_IMAGE}"
|
||||
safe_execute podman build -t "${BUILDER_IMAGE}" -f "${PROJECT_ROOT}/Dockerfile" "${PROJECT_ROOT}"
|
||||
if podman image exists "$BUILDER_IMAGE" 2>/dev/null; then
|
||||
log_info "Builder image built successfully: ${BUILDER_IMAGE}"
|
||||
return 0
|
||||
fi
|
||||
# As a fallback, also tag with localhost to satisfy Podman short-name policy
|
||||
local local_tag="localhost/${BUILDER_IMAGE}"
|
||||
log_info "Tagging builder image as ${local_tag}"
|
||||
safe_execute podman tag "${BUILDER_IMAGE}" "${local_tag}" || true
|
||||
if podman image exists "$local_tag" 2>/dev/null; then
|
||||
BUILDER_IMAGE="$local_tag"
|
||||
fi
|
||||
}
|
||||
|
||||
function dev_container_start() {
|
||||
section_header "Starting Development Container"
|
||||
|
||||
# Ensure builder image exists (handles clean --all case and short-name policy)
|
||||
ensure_builder_image
|
||||
|
||||
# Check if container already exists
|
||||
if podman container exists "$CONTAINER_NAME" 2>/dev/null; then
|
||||
if podman container inspect "$CONTAINER_NAME" --format '{{.State.Status}}' | grep -q "running"; then
|
||||
|
||||
@@ -52,29 +52,37 @@ function log_debug() {
|
||||
|
||||
# Command execution with full transparency
|
||||
function safe_execute() {
|
||||
local cmd="$*"
|
||||
log_info "Executing: ${cmd}"
|
||||
# Stream output live when DEBUG=1 or inside container; otherwise capture and emit only on error.
|
||||
local cmd_display="$*"
|
||||
log_info "Executing: ${cmd_display}"
|
||||
|
||||
if [[ "${DEBUG:-0}" == "1" ]] || in_container; then
|
||||
# In debug mode or container, show all output for visibility
|
||||
if ! ${cmd}; then
|
||||
log_error "Command failed: ${cmd}"
|
||||
if ! "$@"; then
|
||||
log_error "Command failed: ${cmd_display}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Normal mode, capture output and show only on error
|
||||
local output
|
||||
if ! output=$(${cmd} 2>&1); then
|
||||
log_error "Command failed: ${cmd}"
|
||||
if ! output=$("$@" 2>&1); then
|
||||
log_error "Command failed: ${cmd_display}"
|
||||
log_error "Output: ${output}"
|
||||
exit 1
|
||||
else
|
||||
# Show minimal progress indicator for non-debug mode
|
||||
log_debug "Command completed successfully: ${cmd}"
|
||||
log_debug "Command completed successfully: ${cmd_display}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Always-streaming variant (forces live stdout/stderr regardless of DEBUG)
|
||||
function safe_execute_stream() {
|
||||
local cmd_display="$*"
|
||||
log_info "Executing (stream): ${cmd_display}"
|
||||
if ! "$@"; then
|
||||
log_error "Command failed: ${cmd_display}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Section headers with clear text separators
|
||||
function section_header() {
|
||||
local title="$1"
|
||||
@@ -263,7 +271,7 @@ fi
|
||||
export SCRIPT_DIR PROJECT_ROOT
|
||||
export INSTALL_DIR COMPONENTS_DIR KERNEL_DIR DIST_DIR
|
||||
export -f log_info log_warn log_error log_debug
|
||||
export -f safe_execute section_header
|
||||
export -f safe_execute safe_execute_stream section_header
|
||||
export -f command_exists in_container check_dependencies
|
||||
export -f safe_mkdir safe_rmdir safe_copy
|
||||
export -f is_absolute_path resolve_path get_file_size wait_for_file
|
||||
Reference in New Issue
Block a user