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

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env bash
# Configure Database - Run migrations and setup for DBIS Core
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Database Configuration"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
VMID_POSTGRES="${VMID_DBIS_POSTGRES_PRIMARY:-10100}"
DB_HOST="${DBIS_POSTGRES_PRIMARY_IP:-192.168.11.100}"
DB_NAME="${DBIS_DB_NAME:-dbis_core}"
DB_USER="${DBIS_DB_USER:-dbis}"
DB_PASSWORD="${DBIS_DB_PASSWORD:-}"
if [[ -z "$DB_PASSWORD" ]]; then
log_error "DBIS_DB_PASSWORD not set. Please set it in config or environment."
exit 1
fi
log_info "Configuring database on container $VMID_POSTGRES..."
# Check if container is running
if ! pct list | grep -q "^\s*$VMID_POSTGRES\s"; then
error_exit "PostgreSQL container $VMID_POSTGRES not found"
fi
# Wait for PostgreSQL to be ready
log_info "Waiting for PostgreSQL to be ready..."
sleep 5
# Run Prisma migrations
log_info "Running Prisma migrations..."
# Find API container to run migrations from
VMID_API="${VMID_DBIS_API_PRIMARY:-10150}"
if pct list | grep -q "^\s*$VMID_API\s"; then
log_info "Running migrations from API container $VMID_API..."
# Set DATABASE_URL in container
pct exec "$VMID_API" -- bash -c "export DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}"
# Generate Prisma client
log_info "Generating Prisma client..."
pct exec "$VMID_API" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npx prisma generate" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to generate Prisma client"
exit 1
}
# Run migrations
log_info "Running database migrations..."
pct exec "$VMID_API" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npx prisma migrate deploy" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to run migrations"
exit 1
}
# Verify migration status
log_info "Verifying migration status..."
pct exec "$VMID_API" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npx prisma migrate status" 2>&1 | grep -vE "(perl: warning|locale:)" || true
log_success "Database migrations completed!"
else
log_warn "API container not found. Migrations will need to be run manually."
log_info "To run migrations manually:"
log_info "1. Connect to API container: pct enter $VMID_API"
log_info "2. cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}"
log_info "3. export DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}"
log_info "4. npx prisma migrate deploy"
fi
log_info ""
log_info "Database configuration completed!"

View File

@@ -0,0 +1,217 @@
#!/usr/bin/env bash
# Create all missing DBIS Core containers on Proxmox host
# This script creates 6 containers: PostgreSQL (primary + replica), Redis, API (primary + secondary), Frontend
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh" 2>/dev/null || {
# Fallback if common.sh doesn't exist
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
error_exit() { log_error "$1"; exit 1; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
}
# Load configuration
PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.10}"
STORAGE="${STORAGE:-local-lvm}"
TEMPLATE="${TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}"
NETWORK="${NETWORK:-vmbr0}"
GATEWAY="${GATEWAY:-192.168.11.1}"
# DBIS Core VMIDs and IPs
declare -A DBIS_CONTAINERS=(
[10100]="dbis-postgres-primary:192.168.11.100:8:4:200:PostgreSQL Primary Database"
[10101]="dbis-postgres-replica-1:192.168.11.101:8:4:200:PostgreSQL Replica Database"
[10120]="dbis-redis:192.168.11.120:4:2:50:Redis Cache Server"
[10150]="dbis-api-primary:192.168.11.150:8:4:100:Backend API Primary Server"
[10151]="dbis-api-secondary:192.168.11.151:8:4:100:Backend API Secondary Server"
[10130]="dbis-frontend:192.168.11.130:4:2:50:Frontend Admin Console"
)
# Check SSH access
check_ssh_access() {
log_info "Checking SSH access to $PROXMOX_HOST..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PROXMOX_HOST} "echo 'SSH OK'" &>/dev/null; then
log_success "SSH access confirmed"
return 0
else
log_error "Cannot access $PROXMOX_HOST via SSH"
log_error "Please ensure:"
log_error " 1. SSH key is set up"
log_error " 2. Host is reachable"
log_error " 3. Root access is available"
return 1
fi
}
# Check if container exists
container_exists() {
local vmid=$1
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PROXMOX_HOST} \
"pct list | grep -q '^$vmid ' && echo 'exists' || echo 'missing'" 2>/dev/null || echo "error"
}
# Create a container
create_container() {
local vmid=$1
local hostname=$2
local ip=$3
local memory=$4
local cores=$5
local disk=$6
local description="$7"
log_info "Creating container $vmid: $hostname ($ip)..."
# Check if already exists
local exists=$(container_exists "$vmid")
if [[ "$exists" == "exists" ]]; then
log_warn "Container $vmid already exists, skipping..."
return 0
fi
# Create container
log_info " Memory: ${memory}GB, CPU: ${cores} cores, Disk: ${disk}GB"
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PROXMOX_HOST} <<CREATE_CONTAINER_EOF
set -e
pct create $vmid $TEMPLATE \
--hostname $hostname \
--memory $((memory * 1024)) \
--cores $cores \
--rootfs $STORAGE:${disk} \
--net0 name=eth0,bridge=$NETWORK,ip=$ip/24,gw=$GATEWAY \
--description "$description" \
--start 1 \
--onboot 1 \
--unprivileged 1 \
--features nesting=1,keyctl=1 \
--swap $((memory / 4 * 1024))
CREATE_CONTAINER_EOF
if [ $? -eq 0 ]; then
log_success "Container $vmid created successfully"
# Wait for container to start
log_info " Waiting for container to start..."
sleep 5
# Check status
local status=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PROXMOX_HOST} \
"pct status $vmid 2>/dev/null | awk '{print \$2}'" || echo "unknown")
if [[ "$status" == "running" ]]; then
log_success " Container $vmid is running"
else
log_warn " Container $vmid status: $status"
fi
return 0
else
log_error "Failed to create container $vmid"
return 1
fi
}
# Main execution
main() {
echo ""
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "DBIS Core Container Creation Script"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
log_info "Target: $PROXMOX_HOST"
log_info "Storage: $STORAGE"
log_info "Template: $TEMPLATE"
echo ""
# Check SSH access
if ! check_ssh_access; then
exit 1
fi
echo ""
log_info "This will create 6 DBIS Core containers:"
log_info " • 2 PostgreSQL databases (primary + replica)"
log_info " • 1 Redis cache server"
log_info " • 2 Backend API servers (primary + secondary)"
log_info " • 1 Frontend admin console"
echo ""
# Check for non-interactive mode
if [[ "${NON_INTERACTIVE:-}" == "1" ]] || [[ ! -t 0 ]]; then
log_info "Non-interactive mode: proceeding automatically"
else
read -p "Continue? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_info "Creation cancelled"
exit 0
fi
fi
local success_count=0
local fail_count=0
local skip_count=0
echo ""
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "Creating DBIS Core Containers"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Create containers in deployment order
for vmid in 10100 10101 10120 10150 10151 10130; do
IFS=':' read -r hostname ip memory cores disk description <<< "${DBIS_CONTAINERS[$vmid]}"
local exists=$(container_exists "$vmid")
if [[ "$exists" == "exists" ]]; then
log_warn "Container $vmid already exists, skipping..."
skip_count=$((skip_count + 1))
elif create_container "$vmid" "$hostname" "$ip" "$memory" "$cores" "$disk" "$description"; then
success_count=$((success_count + 1))
else
fail_count=$((fail_count + 1))
fi
echo ""
done
# Summary
echo ""
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "Creation Summary"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
log_success "Successfully created: $success_count containers"
if [ $skip_count -gt 0 ]; then
log_warn "Skipped (already exist): $skip_count containers"
fi
if [ $fail_count -gt 0 ]; then
log_error "Failed: $fail_count containers"
fi
echo ""
if [ $success_count -gt 0 ] || [ $skip_count -gt 0 ]; then
log_info "Next steps:"
log_info " 1. Run: cd $PROJECT_ROOT/dbis_core && ./scripts/deployment/deploy-all.sh"
log_info " 2. Verify: ./scripts/management/status.sh"
log_info " 3. Configure database: ./scripts/deployment/configure-database.sh"
fi
echo ""
}
main "$@"

View File

@@ -0,0 +1,134 @@
#!/usr/bin/env bash
# Master deployment script for DBIS Core Banking System
# Orchestrates deployment of all services in correct order
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Complete Deployment"
log_info "========================================="
log_info ""
# Check if running as root
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Deployment flags
DEPLOY_POSTGRESQL="${DEPLOY_POSTGRESQL:-true}"
DEPLOY_REDIS="${DEPLOY_REDIS:-true}"
DEPLOY_API="${DEPLOY_API:-true}"
DEPLOY_FRONTEND="${DEPLOY_FRONTEND:-true}"
# Track deployment status
DEPLOYMENT_SUCCESS=true
FAILED_SERVICES=()
# Function to deploy service with error handling
deploy_service() {
local service_name="$1"
local script_path="$2"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "Deploying: $service_name"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [[ ! -f "$script_path" ]]; then
log_error "Deployment script not found: $script_path"
DEPLOYMENT_SUCCESS=false
FAILED_SERVICES+=("$service_name (script not found)")
return 1
fi
if bash "$script_path"; then
log_success "$service_name deployed successfully"
return 0
else
log_error "$service_name deployment failed"
DEPLOYMENT_SUCCESS=false
FAILED_SERVICES+=("$service_name")
return 1
fi
}
# Phase 1: Foundation Services
log_info "Phase 1: Deploying Foundation Services"
log_info ""
if [[ "$DEPLOY_POSTGRESQL" == "true" ]]; then
deploy_service "PostgreSQL" "$SCRIPT_DIR/deploy-postgresql.sh" || {
log_warn "PostgreSQL deployment failed, but continuing..."
}
log_info ""
fi
if [[ "$DEPLOY_REDIS" == "true" ]]; then
deploy_service "Redis" "$SCRIPT_DIR/deploy-redis.sh" || {
log_warn "Redis deployment failed, but continuing..."
}
log_info ""
fi
# Wait for foundation services to be ready
log_info "Waiting for foundation services to be ready..."
sleep 10
# Phase 2: Application Services
log_info "Phase 2: Deploying Application Services"
log_info ""
if [[ "$DEPLOY_API" == "true" ]]; then
deploy_service "API" "$SCRIPT_DIR/deploy-api.sh" || {
log_warn "API deployment failed, but continuing..."
}
log_info ""
fi
if [[ "$DEPLOY_FRONTEND" == "true" ]]; then
deploy_service "Frontend" "$SCRIPT_DIR/deploy-frontend.sh" || {
log_warn "Frontend deployment failed, but continuing..."
}
log_info ""
fi
# Deployment Summary
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "Deployment Summary"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info ""
if [[ "$DEPLOYMENT_SUCCESS" == "true" ]]; then
log_success "All services deployed successfully!"
log_info ""
log_info "Service Endpoints:"
log_info " PostgreSQL: ${DBIS_POSTGRES_PRIMARY_IP:-192.168.11.100}:5432"
log_info " Redis: ${DBIS_REDIS_IP:-192.168.11.120}:6379"
log_info " API: http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}"
log_info " Frontend: http://${DBIS_FRONTEND_IP:-192.168.11.130}"
log_info ""
log_info "Next Steps:"
log_info "1. Run database migrations: ./scripts/deployment/configure-database.sh"
log_info "2. Check service status: ./scripts/management/status.sh"
log_info "3. Test API health: curl http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}/health"
else
log_error "Deployment completed with errors!"
log_info ""
log_info "Failed Services:"
for service in "${FAILED_SERVICES[@]}"; do
log_error " - $service"
done
log_info ""
log_info "Please review the errors above and retry failed deployments."
exit 1
fi

249
scripts/deployment/deploy-api.sh Executable file
View File

@@ -0,0 +1,249 @@
#!/usr/bin/env bash
# Deploy Backend API Containers for DBIS Core Banking System
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
source "$PROJECT_ROOT/smom-dbis-138-proxmox/lib/container-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - API Deployment"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Ensure OS template exists
ensure_os_template "${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" || {
error_exit "OS template not available. Please download it first."
}
# Function to create API container
create_api_container() {
local vmid="$1"
local hostname="$2"
local ip_address="$3"
local instance_name="${4:-primary}"
log_info "Creating API container: $hostname (VMID: $vmid, IP: $ip_address)"
if container_exists "$vmid"; then
log_warn "Container $vmid already exists, skipping creation"
else
log_info "Creating container $vmid..."
pct create "$vmid" \
"${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" \
--storage "${PROXMOX_STORAGE:-local-lvm}" \
--hostname "$hostname" \
--memory "${DBIS_API_MEMORY:-8192}" \
--cores "${DBIS_API_CORES:-4}" \
--rootfs "${PROXMOX_STORAGE:-local-lvm}:${DBIS_API_DISK:-100}" \
--net0 "bridge=${DBIS_NETWORK_BRIDGE:-vmbr0},name=eth0,ip=${ip_address}/24,gw=192.168.11.1,type=veth" \
--unprivileged "${DBIS_CONTAINER_UNPRIVILEGED:-1}" \
--swap "${DBIS_API_SWAP:-1024}" \
--onboot "${DBIS_CONTAINER_ONBOOT:-1}" \
--timezone "${DBIS_CONTAINER_TIMEZONE:-America/Los_Angeles}" \
--features nesting=1,keyctl=1
log_success "Container $vmid created"
fi
wait_for_container "$vmid"
# Configure container
log_info "Configuring container $vmid..."
pct set "$vmid" --features nesting=1,keyctl=1
# Start container and wait for readiness
if ! start_container_and_wait "$vmid"; then
log_error "Failed to start container $vmid"
return 1
fi
# Verify container is ready
if ! verify_container_ready "$vmid"; then
log_error "Container $vmid is not ready for file operations"
return 1
fi
# Configure locale
pct exec "$vmid" -- bash -c "export LC_ALL=C; export LANG=C; echo 'export LC_ALL=C' >> /root/.bashrc; echo 'export LANG=C' >> /root/.bashrc; echo 'export LC_ALL=C' >> /etc/environment; echo 'export LANG=C' >> /etc/environment" 2>/dev/null || true
# Update system
log_info "Updating system packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock* 2>/dev/null || true; apt-get update -qq && apt-get upgrade -y -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Remove conflicting Node.js packages FIRST (before Node.js installation)
log_info "Removing conflicting Node.js packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock* 2>/dev/null || true; dpkg -r --force-depends nodejs libnode72 nodejs-doc 2>/dev/null || true; apt-get remove -y -qq nodejs libnode72 nodejs-doc 2>/dev/null || true; apt-get autoremove -y -qq 2>/dev/null || true; apt-get update -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Install curl (required for Node.js installation) - check first if already installed
if pct exec "$vmid" -- command -v curl >/dev/null 2>&1; then
log_info "Curl already installed"
else
log_info "Installing curl..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock* 2>/dev/null || true; dpkg --configure -a 2>/dev/null || true; apt-get install -y -qq curl" 2>&1 | grep -vE "(perl: warning|locale:)" || {
if ! pct exec "$vmid" -- command -v curl >/dev/null 2>&1; then
log_error "Failed to install curl"
return 1
fi
}
fi
# Install Node.js using nvm (Node Version Manager) to avoid conflicts
log_info "Installing Node.js ${DBIS_NODE_VERSION:-18} using nvm..."
pct exec "$vmid" -- bash -c "export NVM_DIR=\"/root/.nvm\"; curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash && [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" && nvm install ${DBIS_NODE_VERSION:-18} && nvm use ${DBIS_NODE_VERSION:-18} && nvm alias default ${DBIS_NODE_VERSION:-18}" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "nvm installation may have issues, checking Node.js..."
if ! pct exec "$vmid" -- bash -c "source /root/.nvm/nvm.sh 2>/dev/null && node --version" 2>/dev/null; then
log_error "Failed to install Node.js via nvm"
return 1
fi
}
# Create symlink for node and npm in /usr/local/bin for system-wide access
pct exec "$vmid" -- bash -c "source /root/.nvm/nvm.sh 2>/dev/null && ln -sf \$(nvm which node) /usr/local/bin/node && ln -sf \$(nvm which npm) /usr/local/bin/npm 2>/dev/null || true"
# Install PM2 globally
log_info "Installing PM2 process manager..."
pct exec "$vmid" -- bash -c "npm install -g pm2" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Create application directory
log_info "Setting up application directory..."
pct exec "$vmid" -- bash -c "mkdir -p ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}" 2>/dev/null || true
# Copy dbis_core repository to container
log_info "Copying DBIS Core repository to container..."
if [[ -d "$PROJECT_ROOT/dbis_core" ]]; then
# Use tar to copy files (pct push doesn't support recursive)
log_info "Pushing repository files to container..."
local temp_tar="/tmp/dbis_core_$$.tar.gz"
tar czf "$temp_tar" -C "$PROJECT_ROOT" dbis_core 2>/dev/null
if [[ -f "$temp_tar" ]]; then
pct push "$vmid" "$temp_tar" /tmp/dbis_core.tar.gz 2>&1 | grep -vE "(perl: warning|locale:)" || true
pct exec "$vmid" -- bash -c "cd /opt && tar xzf /tmp/dbis_core.tar.gz && mv dbis_core dbis-core 2>/dev/null && rm -f /tmp/dbis_core.tar.gz" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "Failed to extract repository, will clone instead"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
}
rm -f "$temp_tar" 2>/dev/null || true
else
log_warn "Failed to create tar archive, will clone instead"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
fi
else
log_warn "Local repository not found, will need to clone from git"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
fi
# Install dependencies
log_info "Installing npm dependencies..."
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npm ci 2>&1 | tail -20" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "npm ci failed, trying npm install"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npm install 2>&1 | tail -20" 2>&1 | grep -vE "(perl: warning|locale:)" || true
}
# Generate Prisma client
log_info "Generating Prisma client..."
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npx prisma generate 2>&1 | tail -10" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Build TypeScript
log_info "Building TypeScript..."
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core} && npm run build 2>&1 | tail -20" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Create environment file
log_info "Creating environment configuration..."
local db_host="${DBIS_POSTGRES_PRIMARY_IP:-192.168.11.100}"
local db_name="${DBIS_DB_NAME:-dbis_core}"
local db_user="${DBIS_DB_USER:-dbis}"
local db_password="${DBIS_DB_PASSWORD:-}"
local redis_host="${DBIS_REDIS_IP:-192.168.11.120}"
local jwt_secret="${JWT_SECRET:-$(generate_jwt_secret)}"
pct exec "$vmid" -- bash -c "cat > ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/.env <<EOF
DATABASE_URL=postgresql://${db_user}:${db_password}@${db_host}:5432/${db_name}
JWT_SECRET=${jwt_secret}
ALLOWED_ORIGINS=http://${DBIS_FRONTEND_IP:-192.168.11.130},https://${DBIS_FRONTEND_IP:-192.168.11.130}
NODE_ENV=production
LOG_LEVEL=info
HSM_ENABLED=false
REDIS_URL=redis://${redis_host}:6379
PORT=${DBIS_API_PORT:-3000}
EOF
" 2>/dev/null || true
# Create systemd service
log_info "Creating systemd service..."
pct exec "$vmid" -- bash -c "cat > /etc/systemd/system/dbis-api.service <<EOF
[Unit]
Description=DBIS Core API Server
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}
Environment=NODE_ENV=production
ExecStart=/usr/bin/node dist/index.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
" 2>/dev/null || true
# Enable and start service
log_info "Starting API service..."
pct exec "$vmid" -- systemctl daemon-reload 2>/dev/null || true
pct exec "$vmid" -- systemctl enable dbis-api 2>/dev/null || true
pct exec "$vmid" -- systemctl start dbis-api 2>/dev/null || true
# Wait for service to be ready
log_info "Waiting for API service to be ready..."
sleep 5
# Configure firewall
if pct exec "$vmid" -- command -v ufw >/dev/null 2>&1; then
log_info "Configuring firewall..."
pct exec "$vmid" -- bash -c "ufw allow ${DBIS_API_PORT:-3000}/tcp comment 'DBIS API'" 2>/dev/null || true
fi
log_success "API container $hostname (VMID: $vmid) deployed successfully"
return 0
}
# Deploy API Primary
log_info "Deploying API Primary..."
create_api_container \
"${VMID_DBIS_API_PRIMARY:-10150}" \
"dbis-api-primary" \
"${DBIS_API_PRIMARY_IP:-192.168.11.150}" \
"primary"
# Deploy API Secondary (if HA enabled)
if [[ "${DBIS_ENABLE_HA:-true}" == "true" ]] && [[ "${DBIS_API_COUNT:-2}" -ge 2 ]]; then
log_info "Deploying API Secondary..."
create_api_container \
"${VMID_DBIS_API_SECONDARY:-10151}" \
"dbis-api-secondary" \
"${DBIS_API_SECONDARY_IP:-192.168.11.151}" \
"secondary"
fi
log_success "API deployment completed!"
log_info ""
log_info "Next steps:"
log_info "1. Run database migrations: ./scripts/deployment/configure-database.sh"
log_info "2. Deploy Frontend: ./scripts/deployment/deploy-frontend.sh"
log_info "3. Check API status: ./scripts/management/status.sh"

View File

@@ -0,0 +1,248 @@
#!/usr/bin/env bash
# Deploy Frontend Admin Console Container for DBIS Core Banking System
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
source "$PROJECT_ROOT/smom-dbis-138-proxmox/lib/container-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Frontend Deployment"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Ensure OS template exists
ensure_os_template "${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" || {
error_exit "OS template not available. Please download it first."
}
# Function to create Frontend container
create_frontend_container() {
local vmid="$1"
local hostname="$2"
local ip_address="$3"
log_info "Creating Frontend container: $hostname (VMID: $vmid, IP: $ip_address)"
if container_exists "$vmid"; then
log_warn "Container $vmid already exists, skipping creation"
else
log_info "Creating container $vmid..."
pct create "$vmid" \
"${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" \
--storage "${PROXMOX_STORAGE:-local-lvm}" \
--hostname "$hostname" \
--memory "${DBIS_FRONTEND_MEMORY:-4096}" \
--cores "${DBIS_FRONTEND_CORES:-2}" \
--rootfs "${PROXMOX_STORAGE:-local-lvm}:${DBIS_FRONTEND_DISK:-50}" \
--net0 "bridge=${DBIS_NETWORK_BRIDGE:-vmbr0},name=eth0,ip=${ip_address}/24,gw=192.168.11.1,type=veth" \
--unprivileged "${DBIS_CONTAINER_UNPRIVILEGED:-1}" \
--swap "${DBIS_FRONTEND_SWAP:-512}" \
--onboot "${DBIS_CONTAINER_ONBOOT:-1}" \
--timezone "${DBIS_CONTAINER_TIMEZONE:-America/Los_Angeles}" \
--features nesting=1,keyctl=1
log_success "Container $vmid created"
fi
wait_for_container "$vmid"
# Configure container
log_info "Configuring container $vmid..."
pct set "$vmid" --features nesting=1,keyctl=1
# Start container and wait for readiness
if ! start_container_and_wait "$vmid"; then
log_error "Failed to start container $vmid"
return 1
fi
# Verify container is ready
if ! verify_container_ready "$vmid"; then
log_error "Container $vmid is not ready for file operations"
return 1
fi
# Configure locale
pct exec "$vmid" -- bash -c "export LC_ALL=C; export LANG=C; echo 'export LC_ALL=C' >> /root/.bashrc; echo 'export LANG=C' >> /root/.bashrc; echo 'export LC_ALL=C' >> /etc/environment; echo 'export LANG=C' >> /etc/environment" 2>/dev/null || true
# Update system
log_info "Updating system packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get update -qq && apt-get upgrade -y -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Install curl first (required for Node.js installation)
log_info "Installing curl..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -qq curl" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install curl"
return 1
}
# Remove conflicting Node.js packages BEFORE setup (must happen first)
log_info "Removing conflicting Node.js packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get remove -y -qq nodejs libnode72 nodejs-doc 2>/dev/null; apt-get autoremove -y -qq 2>/dev/null; apt-get update -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Install Node.js
log_info "Installing Node.js ${DBIS_NODE_VERSION:-18}..."
pct exec "$vmid" -- bash -c "curl -fsSL https://deb.nodesource.com/setup_${DBIS_NODE_VERSION:-18}.x | bash -" 2>&1 | grep -vE "(perl: warning|locale:)" || true
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -qq nodejs build-essential" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install Node.js"
return 1
}
# Install Nginx
log_info "Installing Nginx..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -qq nginx" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install Nginx"
return 1
}
# Create application directory
log_info "Setting up application directory..."
pct exec "$vmid" -- bash -c "mkdir -p ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}" 2>/dev/null || true
# Copy dbis_core repository to container
log_info "Copying DBIS Core repository to container..."
if [[ -d "$PROJECT_ROOT/dbis_core" ]]; then
# Use tar to copy files (pct push doesn't support recursive)
log_info "Pushing repository files to container..."
local temp_tar="/tmp/dbis_core_$$.tar.gz"
tar czf "$temp_tar" -C "$PROJECT_ROOT" dbis_core 2>/dev/null
if [[ -f "$temp_tar" ]]; then
pct push "$vmid" "$temp_tar" /tmp/dbis_core.tar.gz 2>&1 | grep -vE "(perl: warning|locale:)" || true
pct exec "$vmid" -- bash -c "cd /opt && tar xzf /tmp/dbis_core.tar.gz && mv dbis_core dbis-core 2>/dev/null && rm -f /tmp/dbis_core.tar.gz" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "Failed to extract repository, will clone instead"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
}
rm -f "$temp_tar" 2>/dev/null || true
else
log_warn "Failed to create tar archive, will clone instead"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
fi
else
log_warn "Local repository not found, will need to clone from git"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt} && git clone https://github.com/Order-of-Hospitallers/dbis_core.git dbis-core 2>/dev/null || true" || true
fi
# Install frontend dependencies
log_info "Installing frontend dependencies..."
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend && npm ci 2>&1 | tail -20" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "npm ci failed, trying npm install"
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend && npm install 2>&1 | tail -20" 2>&1 | grep -vE "(perl: warning|locale:)" || true
}
# Create environment file for frontend
log_info "Creating frontend environment configuration..."
local api_url="http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}"
pct exec "$vmid" -- bash -c "cat > ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend/.env <<EOF
VITE_API_BASE_URL=${api_url}
VITE_APP_NAME=DBIS Admin Console
VITE_REAL_TIME_UPDATE_INTERVAL=5000
EOF
" 2>/dev/null || true
# Build frontend
log_info "Building frontend application..."
pct exec "$vmid" -- bash -c "cd ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend && npm run build 2>&1 | tail -30" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Frontend build failed"
return 1
}
# Configure Nginx
log_info "Configuring Nginx..."
pct exec "$vmid" -- bash -c "cat > /etc/nginx/sites-available/dbis-frontend <<EOF
server {
listen 80;
server_name ${ip_address};
root ${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend/dist;
index index.html;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# Security headers
add_header X-Frame-Options \"SAMEORIGIN\" always;
add_header X-Content-Type-Options \"nosniff\" always;
add_header X-XSS-Protection \"1; mode=block\" always;
# SPA routing
location / {
try_files \$uri \$uri/ /index.html;
}
# API proxy (optional)
location /api {
proxy_pass ${api_url};
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header X-Forwarded-Proto \$scheme;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control \"public, immutable\";
}
}
EOF
" 2>/dev/null || true
# Enable site
pct exec "$vmid" -- bash -c "ln -sf /etc/nginx/sites-available/dbis-frontend /etc/nginx/sites-enabled/" 2>/dev/null || true
pct exec "$vmid" -- bash -c "rm -f /etc/nginx/sites-enabled/default" 2>/dev/null || true
# Test and reload Nginx
log_info "Testing Nginx configuration..."
pct exec "$vmid" -- nginx -t 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Nginx configuration test failed"
return 1
}
log_info "Starting Nginx..."
pct exec "$vmid" -- systemctl restart nginx 2>/dev/null || true
pct exec "$vmid" -- systemctl enable nginx 2>/dev/null || true
# Configure firewall
if pct exec "$vmid" -- command -v ufw >/dev/null 2>&1; then
log_info "Configuring firewall..."
pct exec "$vmid" -- bash -c "ufw allow 80/tcp comment 'HTTP'" 2>/dev/null || true
pct exec "$vmid" -- bash -c "ufw allow 443/tcp comment 'HTTPS'" 2>/dev/null || true
fi
log_success "Frontend container $hostname (VMID: $vmid) deployed successfully"
return 0
}
# Deploy Frontend
log_info "Deploying Frontend Admin Console..."
create_frontend_container \
"${VMID_DBIS_FRONTEND:-10130}" \
"dbis-frontend" \
"${DBIS_FRONTEND_IP:-192.168.11.130}"
log_success "Frontend deployment completed!"
log_info ""
log_info "Deployment Summary:"
log_info " Frontend: http://${DBIS_FRONTEND_IP:-192.168.11.130}"
log_info " API: http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}"
log_info ""
log_info "Next steps:"
log_info "1. Check service status: ./scripts/management/status.sh"
log_info "2. Run database migrations: ./scripts/deployment/configure-database.sh"
log_info "3. Test API health: curl http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}/health"

View File

@@ -0,0 +1,168 @@
#!/usr/bin/env bash
# Deploy PostgreSQL Database Containers for DBIS Core Banking System
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
source "$PROJECT_ROOT/smom-dbis-138-proxmox/lib/container-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - PostgreSQL Deployment"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Ensure OS template exists
ensure_os_template "${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" || {
error_exit "OS template not available. Please download it first."
}
# Function to create PostgreSQL container
create_postgresql_container() {
local vmid="$1"
local hostname="$2"
local ip_address="$3"
local is_replica="${4:-false}"
log_info "Creating PostgreSQL container: $hostname (VMID: $vmid, IP: $ip_address)"
if container_exists "$vmid"; then
log_warn "Container $vmid already exists, skipping creation"
else
log_info "Creating container $vmid..."
pct create "$vmid" \
"${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" \
--storage "${PROXMOX_STORAGE:-local-lvm}" \
--hostname "$hostname" \
--memory "${DBIS_POSTGRES_MEMORY:-8192}" \
--cores "${DBIS_POSTGRES_CORES:-4}" \
--rootfs "${PROXMOX_STORAGE:-local-lvm}:${DBIS_POSTGRES_DISK:-200}" \
--net0 "bridge=${DBIS_NETWORK_BRIDGE:-vmbr0},name=eth0,ip=${ip_address}/24,gw=192.168.11.1,type=veth" \
--unprivileged "${DBIS_CONTAINER_UNPRIVILEGED:-1}" \
--swap "${DBIS_POSTGRES_SWAP:-1024}" \
--onboot "${DBIS_CONTAINER_ONBOOT:-1}" \
--timezone "${DBIS_CONTAINER_TIMEZONE:-America/Los_Angeles}" \
--features nesting=1,keyctl=1
log_success "Container $vmid created"
fi
wait_for_container "$vmid"
# Configure container
log_info "Configuring container $vmid..."
pct set "$vmid" --features nesting=1,keyctl=1
# Start container and wait for readiness
if ! start_container_and_wait "$vmid"; then
log_error "Failed to start container $vmid"
return 1
fi
# Verify container is ready
if ! verify_container_ready "$vmid"; then
log_error "Container $vmid is not ready for file operations"
return 1
fi
# Configure locale
pct exec "$vmid" -- bash -c "export LC_ALL=C; export LANG=C; echo 'export LC_ALL=C' >> /root/.bashrc; echo 'export LANG=C' >> /root/.bashrc; echo 'export LC_ALL=C' >> /etc/environment; echo 'export LANG=C' >> /etc/environment" 2>/dev/null || true
# Update system
log_info "Updating system packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get update -qq && apt-get upgrade -y -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Install PostgreSQL
log_info "Installing PostgreSQL ${DBIS_POSTGRES_VERSION:-15}..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -qq postgresql-${DBIS_POSTGRES_VERSION:-15} postgresql-contrib-${DBIS_POSTGRES_VERSION:-15}" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install PostgreSQL"
return 1
}
# Configure PostgreSQL
log_info "Configuring PostgreSQL..."
# Set PostgreSQL to listen on all interfaces
pct exec "$vmid" -- bash -c "sed -i \"s/#listen_addresses = 'localhost'/listen_addresses = '*'/\" /etc/postgresql/${DBIS_POSTGRES_VERSION:-15}/main/postgresql.conf" 2>/dev/null || true
# Configure pg_hba.conf to allow connections from API containers
pct exec "$vmid" -- bash -c "echo 'host all all 192.168.11.0/24 md5' >> /etc/postgresql/${DBIS_POSTGRES_VERSION:-15}/main/pg_hba.conf" 2>/dev/null || true
# Restart PostgreSQL
log_info "Starting PostgreSQL service..."
pct exec "$vmid" -- systemctl restart postgresql 2>/dev/null || true
pct exec "$vmid" -- systemctl enable postgresql 2>/dev/null || true
# Wait for PostgreSQL to be ready
log_info "Waiting for PostgreSQL to be ready..."
sleep 5
# Create database and user (only for primary)
if [[ "$is_replica" != "true" ]]; then
local db_name="${DBIS_DB_NAME:-dbis_core}"
local db_user="${DBIS_DB_USER:-dbis}"
local db_password="${DBIS_DB_PASSWORD:-}"
if [[ -z "$db_password" ]]; then
log_warn "DBIS_DB_PASSWORD not set, generating random password..."
db_password=$(generate_jwt_secret)
fi
log_info "Creating database and user..."
create_database_user "$vmid" "$db_user" "$db_password"
create_database "$vmid" "$db_name" "$db_user"
log_info "Database credentials:"
log_info " Database: $db_name"
log_info " User: $db_user"
log_info " Password: $db_password"
log_warn "Save these credentials securely!"
fi
# Configure firewall (if ufw is available)
if pct exec "$vmid" -- command -v ufw >/dev/null 2>&1; then
log_info "Configuring firewall..."
pct exec "$vmid" -- bash -c "ufw allow 5432/tcp comment 'PostgreSQL'" 2>/dev/null || true
fi
log_success "PostgreSQL container $hostname (VMID: $vmid) deployed successfully"
return 0
}
# Deploy PostgreSQL Primary
log_info "Deploying PostgreSQL Primary..."
create_postgresql_container \
"${VMID_DBIS_POSTGRES_PRIMARY:-10100}" \
"dbis-postgres-primary" \
"${DBIS_POSTGRES_PRIMARY_IP:-192.168.11.100}" \
"false"
# Deploy PostgreSQL Replica (if enabled)
if [[ "${DBIS_POSTGRES_REPLICA_COUNT:-0}" -gt 0 ]]; then
log_info "Deploying PostgreSQL Replica..."
create_postgresql_container \
"${VMID_DBIS_POSTGRES_REPLICA:-10101}" \
"dbis-postgres-replica-1" \
"${DBIS_POSTGRES_REPLICA_IP:-192.168.11.101}" \
"true"
fi
log_success "PostgreSQL deployment completed!"
log_info ""
log_info "Next steps:"
log_info "1. Run database migrations: ./scripts/deployment/configure-database.sh"
log_info "2. Deploy Redis: ./scripts/deployment/deploy-redis.sh"
log_info "3. Deploy API: ./scripts/deployment/deploy-api.sh"

View File

@@ -0,0 +1,145 @@
#!/usr/bin/env bash
# Deploy Redis Cache Container for DBIS Core Banking System
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
source "$PROJECT_ROOT/smom-dbis-138-proxmox/lib/container-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Redis Deployment"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Ensure OS template exists
ensure_os_template "${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" || {
error_exit "OS template not available. Please download it first."
}
# Function to create Redis container
create_redis_container() {
local vmid="$1"
local hostname="$2"
local ip_address="$3"
log_info "Creating Redis container: $hostname (VMID: $vmid, IP: $ip_address)"
if container_exists "$vmid"; then
log_warn "Container $vmid already exists, skipping creation"
else
log_info "Creating container $vmid..."
pct create "$vmid" \
"${DBIS_CONTAINER_OS_TEMPLATE:-${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}}" \
--storage "${PROXMOX_STORAGE:-local-lvm}" \
--hostname "$hostname" \
--memory "${DBIS_REDIS_MEMORY:-4096}" \
--cores "${DBIS_REDIS_CORES:-2}" \
--rootfs "${PROXMOX_STORAGE:-local-lvm}:${DBIS_REDIS_DISK:-50}" \
--net0 "bridge=${DBIS_NETWORK_BRIDGE:-vmbr0},name=eth0,ip=${ip_address}/24,gw=192.168.11.1,type=veth" \
--unprivileged "${DBIS_CONTAINER_UNPRIVILEGED:-1}" \
--swap "${DBIS_REDIS_SWAP:-512}" \
--onboot "${DBIS_CONTAINER_ONBOOT:-1}" \
--timezone "${DBIS_CONTAINER_TIMEZONE:-America/Los_Angeles}" \
--features nesting=1,keyctl=1
log_success "Container $vmid created"
fi
wait_for_container "$vmid"
# Configure container
log_info "Configuring container $vmid..."
pct set "$vmid" --features nesting=1,keyctl=1
# Start container and wait for readiness
if ! start_container_and_wait "$vmid"; then
log_error "Failed to start container $vmid"
return 1
fi
# Verify container is ready
if ! verify_container_ready "$vmid"; then
log_error "Container $vmid is not ready for file operations"
return 1
fi
# Configure locale
pct exec "$vmid" -- bash -c "export LC_ALL=C; export LANG=C; echo 'export LC_ALL=C' >> /root/.bashrc; echo 'export LANG=C' >> /root/.bashrc; echo 'export LC_ALL=C' >> /etc/environment; echo 'export LANG=C' >> /etc/environment" 2>/dev/null || true
# Update system
log_info "Updating system packages..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get update -qq && apt-get upgrade -y -qq" 2>&1 | grep -vE "(perl: warning|locale:)" || true
# Install Redis
log_info "Installing Redis ${DBIS_REDIS_VERSION:-7}..."
pct exec "$vmid" -- bash -c "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -qq redis-server" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install Redis"
return 1
}
# Configure Redis
log_info "Configuring Redis..."
# Enable Redis to listen on all interfaces
pct exec "$vmid" -- bash -c "sed -i 's/bind 127.0.0.1 ::1/bind 0.0.0.0/' /etc/redis/redis.conf" 2>/dev/null || true
# Enable persistence
pct exec "$vmid" -- bash -c "sed -i 's/# save 900 1/save 900 1/' /etc/redis/redis.conf" 2>/dev/null || true
pct exec "$vmid" -- bash -c "sed -i 's/# save 300 10/save 300 10/' /etc/redis/redis.conf" 2>/dev/null || true
pct exec "$vmid" -- bash -c "sed -i 's/# save 60 10000/save 60 10000/' /etc/redis/redis.conf" 2>/dev/null || true
# Set maxmemory policy
pct exec "$vmid" -- bash -c "echo 'maxmemory-policy allkeys-lru' >> /etc/redis/redis.conf" 2>/dev/null || true
# Restart Redis
log_info "Starting Redis service..."
pct exec "$vmid" -- systemctl restart redis-server 2>/dev/null || true
pct exec "$vmid" -- systemctl enable redis-server 2>/dev/null || true
# Wait for Redis to be ready
log_info "Waiting for Redis to be ready..."
sleep 3
# Test Redis connection
if test_redis_connection "$vmid" "$ip_address"; then
log_success "Redis is responding"
else
log_warn "Redis connection test inconclusive (redis-cli may not be installed)"
fi
# Configure firewall (if ufw is available)
if pct exec "$vmid" -- command -v ufw >/dev/null 2>&1; then
log_info "Configuring firewall..."
pct exec "$vmid" -- bash -c "ufw allow 6379/tcp comment 'Redis'" 2>/dev/null || true
fi
log_success "Redis container $hostname (VMID: $vmid) deployed successfully"
return 0
}
# Deploy Redis
log_info "Deploying Redis Cache..."
create_redis_container \
"${VMID_DBIS_REDIS:-10120}" \
"dbis-redis" \
"${DBIS_REDIS_IP:-192.168.11.120}"
log_success "Redis deployment completed!"
log_info ""
log_info "Next steps:"
log_info "1. Deploy API: ./scripts/deployment/deploy-api.sh"
log_info "2. Deploy Frontend: ./scripts/deployment/deploy-frontend.sh"

View File

@@ -0,0 +1,139 @@
#!/usr/bin/env bash
# Fix Frontend Deployment - Build and Deploy Frontend Application
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh" 2>/dev/null || true
log_info "========================================="
log_info "Fix Frontend Deployment"
log_info "========================================="
log_info ""
# Check if running on Proxmox host
if command_exists pct; then
FRONTEND_VMID="${VMID_DBIS_FRONTEND:-10130}"
log_info "Detected Proxmox host - fixing frontend in container $FRONTEND_VMID"
log_info ""
# Check if container exists
if ! pct status "$FRONTEND_VMID" &>/dev/null; then
log_error "Container $FRONTEND_VMID not found"
exit 1
fi
# Start container if not running
if [ "$(pct status "$FRONTEND_VMID" 2>/dev/null | awk '{print $2}')" != "running" ]; then
log_info "Starting container $FRONTEND_VMID..."
pct start "$FRONTEND_VMID"
sleep 5
fi
log_info "Building frontend application..."
log_info ""
# Install dependencies if needed
log_info "Checking dependencies..."
pct exec "$FRONTEND_VMID" -- bash -c "
cd /opt/dbis-core/frontend || cd /opt/dbis-core/frontend || { echo 'Frontend directory not found'; exit 1; }
if [ ! -d 'node_modules' ]; then
echo 'Installing dependencies...'
npm install
else
echo 'Dependencies already installed'
fi
" 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_error "Failed to install dependencies"
exit 1
}
# Build the application
log_info "Building frontend..."
pct exec "$FRONTEND_VMID" -- bash -c "
cd /opt/dbis-core/frontend
npm run build
" 2>&1 | tail -30 | grep -vE "(perl: warning|locale:)" || {
log_error "Build failed - check errors above"
exit 1
}
# Verify build
log_info "Verifying build..."
if pct exec "$FRONTEND_VMID" -- test -f /opt/dbis-core/frontend/dist/index.html; then
log_success "✅ Build successful!"
else
log_error "❌ Build failed - index.html not found"
exit 1
fi
# Restart nginx
log_info "Restarting nginx..."
pct exec "$FRONTEND_VMID" -- systemctl restart nginx 2>&1 | grep -vE "(perl: warning|locale:)" || {
log_warn "Nginx restart had issues, checking status..."
pct exec "$FRONTEND_VMID" -- systemctl status nginx --no-pager -l || true
}
# Verify nginx is running
if pct exec "$FRONTEND_VMID" -- systemctl is-active --quiet nginx; then
log_success "✅ Nginx is running"
else
log_error "❌ Nginx is not running"
exit 1
fi
log_success ""
log_success "Frontend deployment fixed!"
log_info ""
log_info "Frontend should now be accessible at:"
log_info " http://${DBIS_FRONTEND_IP:-192.168.11.130}"
log_info ""
log_info "If you still see the placeholder message:"
log_info " 1. Clear your browser cache (Ctrl+Shift+R or Cmd+Shift+R)"
log_info " 2. Check browser console for errors"
log_info " 3. Verify nginx is serving from: /opt/dbis-core/frontend/dist"
else
# Running directly on the container
log_info "Running directly on container - building frontend..."
log_info ""
FRONTEND_DIR="${DBIS_CORE_PROJECT_ROOT:-/opt/dbis-core}/frontend"
if [ ! -d "$FRONTEND_DIR" ]; then
log_error "Frontend directory not found: $FRONTEND_DIR"
exit 1
fi
cd "$FRONTEND_DIR"
# Install dependencies if needed
if [ ! -d "node_modules" ]; then
log_info "Installing dependencies..."
npm install
fi
# Build
log_info "Building frontend..."
npm run build
# Verify
if [ -f "dist/index.html" ]; then
log_success "✅ Build successful!"
else
log_error "❌ Build failed - index.html not found"
exit 1
fi
# Restart nginx
log_info "Restarting nginx..."
systemctl restart nginx
log_success ""
log_success "Frontend deployment fixed!"
fi

4
scripts/fix-frontend.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
# Quick Frontend Fix - Run on Proxmox Host
VMID=10130
pct exec $VMID -- bash -c "cd /opt/dbis-core/frontend && npm install && npm run build && systemctl restart nginx && echo '✅ Frontend fixed!'"

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Restart all DBIS Core services
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Restart Services"
log_info "========================================="
log_info ""
log_info "Stopping services..."
bash "$SCRIPT_DIR/stop-services.sh"
log_info ""
log_info "Starting services..."
bash "$SCRIPT_DIR/start-services.sh"
log_info ""
log_success "Services restarted!"
log_info ""
log_info "Run './scripts/management/status.sh' to check service status"

View File

@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# Start all DBIS Core services
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Start Services"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Start containers in order
log_info "Starting containers..."
# Start PostgreSQL
if pct list | grep -q "^\s*${VMID_DBIS_POSTGRES_PRIMARY:-10100}\s"; then
log_info "Starting PostgreSQL Primary..."
pct start "${VMID_DBIS_POSTGRES_PRIMARY:-10100}" 2>/dev/null || log_warn "PostgreSQL may already be running"
sleep 3
fi
# Start Redis
if pct list | grep -q "^\s*${VMID_DBIS_REDIS:-10120}\s"; then
log_info "Starting Redis..."
pct start "${VMID_DBIS_REDIS:-10120}" 2>/dev/null || log_warn "Redis may already be running"
sleep 2
fi
# Start API
if pct list | grep -q "^\s*${VMID_DBIS_API_PRIMARY:-10150}\s"; then
log_info "Starting API Primary..."
pct start "${VMID_DBIS_API_PRIMARY:-10150}" 2>/dev/null || log_warn "API may already be running"
sleep 3
fi
# Start Frontend
if pct list | grep -q "^\s*${VMID_DBIS_FRONTEND:-10130}\s"; then
log_info "Starting Frontend..."
pct start "${VMID_DBIS_FRONTEND:-10130}" 2>/dev/null || log_warn "Frontend may already be running"
sleep 2
fi
log_info ""
log_info "Waiting for services to be ready..."
sleep 5
log_info ""
log_success "Services started!"
log_info ""
log_info "Run './scripts/management/status.sh' to check service status"

129
scripts/management/status.sh Executable file
View File

@@ -0,0 +1,129 @@
#!/usr/bin/env bash
# Check status of all DBIS Core services
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
source "$PROJECT_ROOT/dbis_core/scripts/utils/dbis-core-utils.sh" 2>/dev/null || true
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Service Status"
log_info "========================================="
log_info ""
# Check if running as root
if [[ $EUID -ne 0 ]]; then
log_warn "Not running as root. Some checks may fail."
fi
# Function to check container status
check_container_status() {
local vmid="$1"
local service_name="$2"
if ! pct list | grep -q "^\s*$vmid\s"; then
echo -e "${RED}${NC} Container $vmid ($service_name): NOT FOUND"
return 1
fi
local status
status=$(pct status "$vmid" 2>/dev/null | awk '{print $2}' || echo "unknown")
local ip
ip=$(get_container_ip "$vmid" 2>/dev/null || echo "N/A")
if [[ "$status" == "running" ]]; then
echo -e "${GREEN}${NC} Container $vmid ($service_name): RUNNING (IP: $ip)"
return 0
else
echo -e "${YELLOW}${NC} Container $vmid ($service_name): $status (IP: $ip)"
return 1
fi
}
# Function to check service status in container
check_service_in_container() {
local vmid="$1"
local service_name="$2"
if ! pct list | grep -q "^\s*$vmid\s"; then
return 1
fi
local status
status=$(pct status "$vmid" 2>/dev/null | awk '{print $2}' || echo "unknown")
if [[ "$status" != "running" ]]; then
return 1
fi
if pct exec "$vmid" -- systemctl is-active --quiet "$service_name" 2>/dev/null; then
echo -e "${GREEN}${NC} Service $service_name: ACTIVE"
return 0
else
echo -e "${RED}${NC} Service $service_name: INACTIVE"
return 1
fi
}
# Check containers
log_info "Container Status:"
log_info ""
check_container_status "${VMID_DBIS_POSTGRES_PRIMARY:-10100}" "PostgreSQL Primary"
check_container_status "${VMID_DBIS_POSTGRES_REPLICA:-10101}" "PostgreSQL Replica" || true
check_container_status "${VMID_DBIS_REDIS:-10120}" "Redis"
check_container_status "${VMID_DBIS_API_PRIMARY:-10150}" "API Primary"
check_container_status "${VMID_DBIS_API_SECONDARY:-10151}" "API Secondary" || true
check_container_status "${VMID_DBIS_FRONTEND:-10130}" "Frontend"
log_info ""
log_info "Service Status:"
log_info ""
# Check PostgreSQL service
if pct list | grep -q "^\s*${VMID_DBIS_POSTGRES_PRIMARY:-10100}\s"; then
check_service_in_container "${VMID_DBIS_POSTGRES_PRIMARY:-10100}" "postgresql"
fi
# Check Redis service
if pct list | grep -q "^\s*${VMID_DBIS_REDIS:-10120}\s"; then
check_service_in_container "${VMID_DBIS_REDIS:-10120}" "redis-server"
fi
# Check API service
if pct list | grep -q "^\s*${VMID_DBIS_API_PRIMARY:-10150}\s"; then
check_service_in_container "${VMID_DBIS_API_PRIMARY:-10150}" "dbis-api"
fi
# Check Frontend service
if pct list | grep -q "^\s*${VMID_DBIS_FRONTEND:-10130}\s"; then
check_service_in_container "${VMID_DBIS_FRONTEND:-10130}" "nginx"
fi
log_info ""
log_info "Service Endpoints:"
log_info " PostgreSQL: ${DBIS_POSTGRES_PRIMARY_IP:-192.168.11.100}:5432"
log_info " Redis: ${DBIS_REDIS_IP:-192.168.11.120}:6379"
log_info " API: http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}"
log_info " Frontend: http://${DBIS_FRONTEND_IP:-192.168.11.130}"
log_info ""
# Test API health if available
if command_exists curl; then
log_info "Testing API health endpoint..."
if curl -s -f "http://${DBIS_API_PRIMARY_IP:-192.168.11.150}:${DBIS_API_PORT:-3000}/health" >/dev/null 2>&1; then
log_success "API health check: PASSED"
else
log_warn "API health check: FAILED (API may not be ready yet)"
fi
fi
log_info ""

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# Stop all DBIS Core services gracefully
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source utilities
source "$PROJECT_ROOT/dbis_core/scripts/utils/common.sh"
# Load configuration
load_config
log_info "========================================="
log_info "DBIS Core - Stop Services"
log_info "========================================="
log_info ""
check_root
if ! command_exists pct; then
error_exit "This script must be run on Proxmox host (pct command not found)"
fi
# Stop containers in reverse order
log_info "Stopping containers..."
# Stop Frontend
if pct list | grep -q "^\s*${VMID_DBIS_FRONTEND:-10130}\s"; then
log_info "Stopping Frontend..."
pct stop "${VMID_DBIS_FRONTEND:-10130}" 2>/dev/null || log_warn "Frontend may already be stopped"
sleep 2
fi
# Stop API
if pct list | grep -q "^\s*${VMID_DBIS_API_PRIMARY:-10150}\s"; then
log_info "Stopping API Primary..."
pct stop "${VMID_DBIS_API_PRIMARY:-10150}" 2>/dev/null || log_warn "API may already be stopped"
sleep 2
fi
# Stop Redis
if pct list | grep -q "^\s*${VMID_DBIS_REDIS:-10120}\s"; then
log_info "Stopping Redis..."
pct stop "${VMID_DBIS_REDIS:-10120}" 2>/dev/null || log_warn "Redis may already be stopped"
sleep 2
fi
# Stop PostgreSQL (last)
if pct list | grep -q "^\s*${VMID_DBIS_POSTGRES_PRIMARY:-10100}\s"; then
log_info "Stopping PostgreSQL Primary..."
pct stop "${VMID_DBIS_POSTGRES_PRIMARY:-10100}" 2>/dev/null || log_warn "PostgreSQL may already be stopped"
sleep 2
fi
log_info ""
log_success "Services stopped!"
log_info ""
log_info "Run './scripts/management/start-services.sh' to start services again"

130
scripts/run-frontend-fix.sh Normal file
View File

@@ -0,0 +1,130 @@
#!/usr/bin/env bash
# Frontend Fix Script - Run this on Proxmox Host
set -e
VMID=10130
FRONTEND_DIR="/opt/dbis-core/frontend"
echo "========================================="
echo "Frontend Deployment Fix"
echo "========================================="
echo ""
# Check if pct command exists (Proxmox host)
if ! command -v pct &> /dev/null; then
echo "❌ ERROR: This script must be run on the Proxmox host"
echo " The 'pct' command is required to access containers"
echo ""
echo "Please SSH into your Proxmox host and run:"
echo " cd /home/intlc/projects/proxmox/dbis_core"
echo " ./scripts/run-frontend-fix.sh"
exit 1
fi
# Check container exists
if ! pct status $VMID &>/dev/null; then
echo "❌ ERROR: Container $VMID not found"
exit 1
fi
echo "✅ Container $VMID found"
echo ""
# Check if container is running
CONTAINER_STATUS=$(pct status $VMID 2>/dev/null | awk '{print $2}' || echo "stopped")
if [ "$CONTAINER_STATUS" != "running" ]; then
echo "Starting container $VMID..."
pct start $VMID
sleep 5
fi
echo "Container is running"
echo ""
# Step 1: Check if frontend directory exists
echo "Step 1: Checking frontend directory..."
if pct exec $VMID -- test -d "$FRONTEND_DIR"; then
echo "✅ Frontend directory exists: $FRONTEND_DIR"
else
echo "❌ Frontend directory not found: $FRONTEND_DIR"
echo " Please check the deployment configuration"
exit 1
fi
echo ""
# Step 2: Install dependencies
echo "Step 2: Installing dependencies..."
pct exec $VMID -- bash -c "cd $FRONTEND_DIR && npm install" 2>&1 | grep -vE "(perl: warning|locale:)" || {
echo "⚠️ npm install had warnings, continuing..."
}
echo "✅ Dependencies installed"
echo ""
# Step 3: Build frontend
echo "Step 3: Building frontend application..."
if pct exec $VMID -- bash -c "cd $FRONTEND_DIR && npm run build" 2>&1 | grep -vE "(perl: warning|locale:)"; then
echo "✅ Build completed"
else
echo "❌ Build failed - check errors above"
exit 1
fi
echo ""
# Step 4: Verify build
echo "Step 4: Verifying build..."
if pct exec $VMID -- test -f "$FRONTEND_DIR/dist/index.html"; then
echo "✅ index.html exists"
JS_COUNT=$(pct exec $VMID -- bash -c "ls -1 $FRONTEND_DIR/dist/*.js 2>/dev/null | wc -l" || echo "0")
echo "✅ Found $JS_COUNT JavaScript files"
else
echo "❌ Build verification failed - index.html not found"
exit 1
fi
echo ""
# Step 5: Restart nginx
echo "Step 5: Restarting nginx..."
if pct exec $VMID -- systemctl restart nginx 2>&1 | grep -vE "(perl: warning|locale:)"; then
echo "✅ Nginx restarted"
else
echo "⚠️ Nginx restart had issues, checking status..."
pct exec $VMID -- systemctl status nginx --no-pager -l | head -10 || true
fi
# Verify nginx is running
if pct exec $VMID -- systemctl is-active --quiet nginx; then
echo "✅ Nginx is running"
else
echo "❌ Nginx is not running"
exit 1
fi
echo ""
# Step 6: Verify nginx configuration
echo "Step 6: Verifying nginx configuration..."
NGINX_ROOT=$(pct exec $VMID -- bash -c "grep 'root' /etc/nginx/sites-available/dbis-frontend 2>/dev/null | head -1 | awk '{print \$2}' | tr -d ';'" || echo "")
if [ -n "$NGINX_ROOT" ]; then
echo "✅ Nginx root directory: $NGINX_ROOT"
if [ "$NGINX_ROOT" != "$FRONTEND_DIR/dist" ]; then
echo "⚠️ WARNING: Nginx root doesn't match expected path"
echo " Expected: $FRONTEND_DIR/dist"
echo " Found: $NGINX_ROOT"
fi
else
echo "⚠️ Could not read nginx configuration"
fi
echo ""
echo "========================================="
echo "✅ Frontend deployment fixed!"
echo "========================================="
echo ""
echo "Frontend should now be accessible at:"
echo " http://192.168.11.130"
echo ""
echo "Next steps:"
echo " 1. Clear your browser cache (Ctrl+Shift+R)"
echo " 2. Refresh the page"
echo " 3. You should see the React app, not the placeholder"
echo ""

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
}