Files
solace-bg-dubai/deployment/proxmox/deploy-indexer.sh
defiQUG c94eb595f8
Some checks failed
CI / lint-and-test (push) Has been cancelled
Initial commit: add .gitignore and README
2026-02-09 21:51:53 -08:00

168 lines
4.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy Event Indexer Container on Proxmox VE
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="$SCRIPT_DIR/config/dapp.conf"
# Load configuration
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
fi
# Default values
VMID="${VMID_INDEXER:-3003}"
HOSTNAME="${HOSTNAME:-solace-indexer}"
IP_ADDRESS="${INDEXER_IP:-192.168.11.63}"
MEMORY="${INDEXER_MEMORY:-2048}"
CORES="${INDEXER_CORES:-2}"
DISK="${INDEXER_DISK:-30}"
PROJECT_ROOT="${PROJECT_ROOT:-/home/intlc/projects/solace-bg-dubai}"
echo "=========================================="
echo "Deploying Event Indexer Container"
echo "=========================================="
echo "VMID: $VMID"
echo "Hostname: $HOSTNAME"
echo "IP: $IP_ADDRESS"
echo "Memory: ${MEMORY}MB"
echo "Cores: $CORES"
echo "Disk: ${DISK}GB"
echo ""
# Check if running on Proxmox host
if ! command -v pct &> /dev/null; then
echo "ERROR: This script must be run on Proxmox host (pct command not found)"
exit 1
fi
# Check if container already exists
if pct list | grep -q "^\s*$VMID\s"; then
echo "Container $VMID already exists. Skipping creation."
echo "To recreate, delete the container first: pct destroy $VMID"
else
echo "Creating container $VMID..."
pct create "$VMID" \
"${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}" \
--storage "${PROXMOX_STORAGE:-local-lvm}" \
--hostname "$HOSTNAME" \
--memory "$MEMORY" \
--cores "$CORES" \
--rootfs "${PROXMOX_STORAGE:-local-lvm}:${DISK}" \
--net0 "bridge=${PROXMOX_BRIDGE:-vmbr0},name=eth0,ip=${IP_ADDRESS}/24,gw=${GATEWAY:-192.168.11.1},type=veth" \
--unprivileged "${CONTAINER_UNPRIVILEGED:-1}" \
--swap "${CONTAINER_SWAP:-512}" \
--onboot "${CONTAINER_ONBOOT:-1}" \
--timezone "${CONTAINER_TIMEZONE:-UTC}" \
--features nesting=1,keyctl=1
echo "Container $VMID created successfully"
fi
# Start container
echo "Starting container $VMID..."
pct start "$VMID" || true
# Wait for container to be ready
echo "Waiting for container to be ready..."
sleep 5
for i in {1..30}; do
if pct exec "$VMID" -- test -f /etc/os-release 2>/dev/null; then
break
fi
sleep 1
done
# Install Node.js and pnpm
echo "Installing Node.js and pnpm..."
pct exec "$VMID" -- bash -c "
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y curl
# Install Node.js 18
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs
# Install pnpm
npm install -g pnpm
# Install PostgreSQL client
apt-get install -y postgresql-client
"
# Create application directory
echo "Setting up application directory..."
pct exec "$VMID" -- bash -c "
mkdir -p /opt/solace-indexer
chown -R 1000:1000 /opt/solace-indexer
"
# Copy indexer code to container (uses backend codebase)
echo "Copying indexer code to container..."
if [[ -d "$PROJECT_ROOT/backend" ]]; then
pct push "$VMID" "$PROJECT_ROOT/backend" /opt/solace-indexer
else
echo "WARNING: Backend directory not found at $PROJECT_ROOT/backend"
echo "You will need to copy the code manually or clone the repository"
fi
# Install dependencies and build
echo "Installing dependencies..."
pct exec "$VMID" -- bash -c "
cd /opt/solace-indexer
export NODE_ENV=production
pnpm install --frozen-lockfile
pnpm run build
"
# Create systemd service
echo "Creating systemd service..."
pct exec "$VMID" -- bash -c "
cat > /etc/systemd/system/solace-indexer.service <<'EOF'
[Unit]
Description=Solace Treasury Event Indexer
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/solace-indexer
Environment=NODE_ENV=production
EnvironmentFile=/opt/solace-indexer/.env.indexer
ExecStart=/usr/bin/node /opt/solace-indexer/dist/indexer/indexer.js
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable solace-indexer
"
# Create log directory
pct exec "$VMID" -- bash -c "
mkdir -p /var/log/indexer
chmod 755 /var/log/indexer
"
echo ""
echo "=========================================="
echo "Indexer Container Deployment Complete"
echo "=========================================="
echo "Container: $VMID ($HOSTNAME)"
echo "IP Address: $IP_ADDRESS"
echo ""
echo "Next steps:"
echo "1. Copy backend/.env.indexer to container: pct push $VMID backend/.env.indexer /opt/solace-indexer/.env.indexer"
echo "2. Update .env.indexer with database connection, RPC URL, and contract address"
echo "3. Start the service: pct exec $VMID -- systemctl start solace-indexer"
echo "4. Check status: pct exec $VMID -- systemctl status solace-indexer"
echo "5. View logs: pct exec $VMID -- journalctl -u solace-indexer -f"