Fix TypeScript build errors

This commit is contained in:
defiQUG
2026-01-02 20:27:42 -08:00
parent 849e6a8357
commit d4fb8e77cb
295 changed files with 18595 additions and 1391 deletions

194
scripts/utils/common.sh Executable file
View File

@@ -0,0 +1,194 @@
#!/usr/bin/env bash
# Common functions and utilities for DBIS Core deployment scripts
# Don't use set -euo pipefail here as this is a library file
set +euo pipefail
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1" >&2
}
log_success() {
echo -e "${GREEN}[✓]${NC} $1" >&2
}
log_warn() {
echo -e "${YELLOW}[WARNING]${NC} $1" >&2
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
log_debug() {
if [[ "${DEBUG:-}" == "1" ]] || [[ "${DBIS_DEBUG:-}" == "1" ]]; then
echo -e "${BLUE}[DEBUG]${NC} $1" >&2
fi
}
# Error handling
error_exit() {
log_error "$1"
exit 1
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if running as root (for Proxmox host operations)
check_root() {
if [[ $EUID -ne 0 ]]; then
error_exit "This script must be run as root for Proxmox host operations"
fi
}
# Get script directory
get_script_dir() {
local depth=1
local script_dir
while [[ $depth -lt 10 ]]; do
if [[ -n "${BASH_SOURCE[$depth]:-}" ]]; then
script_dir="$(cd "$(dirname "${BASH_SOURCE[$depth]}")" && pwd)"
if [[ "$(basename "$script_dir")" != "lib" ]] && [[ "$(basename "$script_dir")" != "utils" ]]; then
echo "$script_dir"
return 0
fi
fi
depth=$((depth + 1))
done
cd "$(dirname "${BASH_SOURCE[0]}")" && pwd
}
# Get project root
get_project_root() {
local script_dir
script_dir="$(get_script_dir)"
# Navigate to proxmox project root
if [[ "$script_dir" == */dbis_core/scripts/* ]]; then
echo "$(cd "$script_dir/../../.." && pwd)"
elif [[ "$script_dir" == */dbis_core/* ]]; then
echo "$(cd "$script_dir/../.." && pwd)"
else
echo "$(cd "$script_dir/.." && pwd)"
fi
}
# Load configuration
load_config() {
local project_root
project_root="$(get_project_root)"
# Load main Proxmox config
if [[ -f "${project_root}/smom-dbis-138-proxmox/config/proxmox.conf" ]]; then
source "${project_root}/smom-dbis-138-proxmox/config/proxmox.conf" 2>/dev/null || true
fi
# Load DBIS Core config
if [[ -f "${project_root}/dbis_core/config/dbis-core-proxmox.conf" ]]; then
source "${project_root}/dbis_core/config/dbis-core-proxmox.conf" 2>/dev/null || true
fi
# Load .env file if exists
if [[ -f "${HOME}/.env" ]]; then
set -a
source <(grep -E "^PROXMOX_" "${HOME}/.env" 2>/dev/null | sed 's/^/export /' || true)
set +a
fi
}
# Wait for container to be ready
wait_for_container() {
local vmid="$1"
local max_wait=60
local waited=0
while ! pct exec "$vmid" -- true 2>/dev/null && [[ $waited -lt $max_wait ]]; do
sleep 2
waited=$((waited + 2))
done
if ! pct exec "$vmid" -- true 2>/dev/null; then
log_error "Container $vmid not ready after ${max_wait}s"
return 1
fi
return 0
}
# Start container and wait
start_container_and_wait() {
local vmid="$1"
if ! pct start "$vmid" 2>/dev/null; then
log_warn "Container $vmid may already be running"
fi
wait_for_container "$vmid"
}
# Verify container is ready for file operations
verify_container_ready() {
local vmid="$1"
local max_attempts=10
local attempt=0
while [[ $attempt -lt $max_attempts ]]; do
if pct exec "$vmid" -- test -d /root 2>/dev/null; then
return 0
fi
sleep 1
attempt=$((attempt + 1))
done
return 1
}
# Check if container exists
container_exists() {
local vmid="$1"
pct list | grep -q "^\s*$vmid\s"
}
# Get container IP address
get_container_ip() {
local vmid="$1"
pct config "$vmid" | grep -E "^net0:" | sed -E 's/.*ip=([^,]+).*/\1/' | head -1
}
# Set container static IP
set_container_ip() {
local vmid="$1"
local ip_address="$2"
local gateway="${3:-192.168.11.1}"
pct set "$vmid" --net0 "bridge=${PROXMOX_BRIDGE:-vmbr0},name=eth0,ip=${ip_address}/24,gw=${gateway},type=veth" 2>/dev/null || {
log_warn "Failed to set static IP for container $vmid"
return 1
}
return 0
}
# Ensure OS template exists
ensure_os_template() {
local template="${1:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}"
if pvesm list local | grep -q "$(basename "$template")"; then
return 0
fi
log_warn "OS template not found: $template"
return 1
}

187
scripts/utils/dbis-core-utils.sh Executable file
View File

@@ -0,0 +1,187 @@
#!/usr/bin/env bash
# DBIS Core specific utility functions
# Source common utilities
if [[ -f "$(dirname "${BASH_SOURCE[0]}")/common.sh" ]]; then
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
fi
# Validate environment variables
validate_env_vars() {
local required_vars=("$@")
local missing_vars=()
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
missing_vars+=("$var")
fi
done
if [[ ${#missing_vars[@]} -gt 0 ]]; then
log_error "Missing required environment variables: ${missing_vars[*]}"
return 1
fi
return 0
}
# Test database connection
test_database_connection() {
local vmid="$1"
local db_host="${2:-192.168.11.100}"
local db_port="${3:-5432}"
local db_name="${4:-dbis_core}"
local db_user="${5:-dbis}"
log_info "Testing database connection to $db_host:$db_port..."
if pct exec "$vmid" -- bash -c "command -v psql >/dev/null 2>&1" 2>/dev/null; then
if pct exec "$vmid" -- bash -c "PGPASSWORD=\${DB_PASSWORD:-} psql -h $db_host -p $db_port -U $db_user -d $db_name -c 'SELECT 1;' >/dev/null 2>&1" 2>/dev/null; then
log_success "Database connection successful"
return 0
fi
fi
log_warn "Database connection test failed (psql may not be installed in container)"
return 1
}
# Test Redis connection
test_redis_connection() {
local vmid="$1"
local redis_host="${2:-192.168.11.120}"
local redis_port="${3:-6379}"
log_info "Testing Redis connection to $redis_host:$redis_port..."
if pct exec "$vmid" -- bash -c "command -v redis-cli >/dev/null 2>&1" 2>/dev/null; then
if pct exec "$vmid" -- bash -c "redis-cli -h $redis_host -p $redis_port ping >/dev/null 2>&1" 2>/dev/null; then
log_success "Redis connection successful"
return 0
fi
fi
log_warn "Redis connection test failed (redis-cli may not be installed in container)"
return 1
}
# Test API health endpoint
test_api_health() {
local api_host="${1:-192.168.11.150}"
local api_port="${2:-3000}"
log_info "Testing API health endpoint at http://$api_host:$api_port/health..."
if command_exists curl; then
if curl -s -f "http://$api_host:$api_port/health" >/dev/null 2>&1; then
log_success "API health check passed"
return 0
fi
fi
log_warn "API health check failed"
return 1
}
# Check service status in container
check_service_status() {
local vmid="$1"
local service_name="$2"
if pct exec "$vmid" -- systemctl is-active --quiet "$service_name" 2>/dev/null; then
return 0
fi
return 1
}
# Get service logs
get_service_logs() {
local vmid="$1"
local service_name="$2"
local lines="${3:-50}"
pct exec "$vmid" -- journalctl -u "$service_name" -n "$lines" --no-pager 2>/dev/null || {
log_warn "Failed to get logs for service $service_name"
return 1
}
}
# Wait for service to be ready
wait_for_service() {
local vmid="$1"
local service_name="$2"
local max_wait="${3:-60}"
local waited=0
log_info "Waiting for service $service_name to be ready..."
while [[ $waited -lt $max_wait ]]; do
if check_service_status "$vmid" "$service_name"; then
log_success "Service $service_name is ready"
return 0
fi
sleep 2
waited=$((waited + 2))
done
log_error "Service $service_name not ready after ${max_wait}s"
return 1
}
# Generate JWT secret
generate_jwt_secret() {
openssl rand -hex 32 2>/dev/null || {
# Fallback to /dev/urandom
head -c 32 /dev/urandom | base64 | tr -d '\n'
}
}
# Validate JWT secret
validate_jwt_secret() {
local secret="$1"
if [[ ${#secret} -lt 32 ]]; then
log_error "JWT secret must be at least 32 characters"
return 1
fi
return 0
}
# Create database user
create_database_user() {
local vmid="$1"
local db_user="${2:-dbis}"
local db_password="${3:-}"
if [[ -z "$db_password" ]]; then
log_error "Database password required"
return 1
fi
log_info "Creating database user $db_user..."
pct exec "$vmid" -- bash -c "sudo -u postgres psql -c \"CREATE USER $db_user WITH PASSWORD '$db_password';\" 2>/dev/null" || {
log_warn "User $db_user may already exist"
}
pct exec "$vmid" -- bash -c "sudo -u postgres psql -c \"ALTER USER $db_user CREATEDB;\" 2>/dev/null" || true
log_success "Database user $db_user created"
return 0
}
# Create database
create_database() {
local vmid="$1"
local db_name="${2:-dbis_core}"
local db_user="${3:-dbis}"
log_info "Creating database $db_name..."
pct exec "$vmid" -- bash -c "sudo -u postgres psql -c \"CREATE DATABASE $db_name OWNER $db_user;\" 2>/dev/null" || {
log_warn "Database $db_name may already exist"
}
log_success "Database $db_name created"
return 0
}