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"