Files
proxmox/scripts/dbis/deploy-dbis-frontend-to-container.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

85 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy dbis-frontend build to Proxmox container (VMID 10130)
# Builds locally, pushes dist to container, reloads nginx.
# Usage: ./scripts/dbis/deploy-dbis-frontend-to-container.sh
# Env: DBIS_FRONTEND_DEPLOY_PATH, VITE_API_BASE_URL (for build), DEBUG=1 (verbose)
# Version: 2026-01-31
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "${SCRIPT_DIR}/../lib/load-project-env.sh"
VMID="${VMID_DBIS_FRONTEND:-10130}"
FRONTEND_DIR="${DBIS_CORE_DIR:-${PROJECT_ROOT}/dbis_core}/frontend"
DIST_DIR="${FRONTEND_DIR}/dist"
PROXMOX_HOST="$(get_host_for_vmid "$VMID")"
SSH_OPTS="-o ConnectTimeout=30 -o ServerAliveInterval=60 -o ServerAliveCountMax=3"
[[ "${DEBUG:-0}" = "1" ]] && set -x
[[ ! -d "$FRONTEND_DIR" ]] && err_exit "Frontend dir not found: $FRONTEND_DIR"
command -v npm &>/dev/null || err_exit "npm not found (required for build)"
# Pre-flight: SSH connectivity
ssh $SSH_OPTS -o BatchMode=yes "root@${PROXMOX_HOST}" "exit" 2>/dev/null || err_exit "Cannot SSH to $PROXMOX_HOST (check keys/network)"
# Pre-flight: container exists
ssh $SSH_OPTS "root@${PROXMOX_HOST}" "pct status $VMID" &>/dev/null || err_exit "Container $VMID not found on $PROXMOX_HOST"
echo "=== Deploy DBIS Frontend to Container $VMID ==="
echo "Host: $PROXMOX_HOST | Frontend: $FRONTEND_DIR"
# Build (VITE_API_BASE_URL can be set for API URL; see dbis_core/frontend/.env.example)
echo "Building frontend..."
(cd "$FRONTEND_DIR" && npm run build) || err_exit "Build failed"
[[ ! -d "$DIST_DIR" ]] && err_exit "dist not found after build"
TMP_TAR="/tmp/dbis_frontend_$$.tar.gz"
tar czf "$TMP_TAR" -C "$DIST_DIR" .
trap "rm -f $TMP_TAR" EXIT
# Path: DBIS_FRONTEND_DEPLOY_PATH env override, else auto-detect
if [[ -n "${DBIS_FRONTEND_DEPLOY_PATH:-}" ]]; then
CONTAINER_DEPLOY_PATH="$DBIS_FRONTEND_DEPLOY_PATH"
else
CONTAINER_DEPLOY_PATH="$(
ssh $SSH_OPTS "root@${PROXMOX_HOST}" "
if pct exec $VMID -- mkdir -p /opt/dbis-core/frontend/dist 2>/dev/null; then
echo /opt/dbis-core/frontend/dist
else
pct exec $VMID -- mkdir -p /tmp/dbis-frontend/dist 2>/dev/null
echo /tmp/dbis-frontend/dist
fi
" 2>/dev/null || echo "/tmp/dbis-frontend/dist"
)"
fi
echo "Deploy path: $CONTAINER_DEPLOY_PATH"
echo "Pushing to container $VMID..."
scp $SSH_OPTS "$TMP_TAR" "root@${PROXMOX_HOST}:/tmp/dbis_frontend_deploy.tar.gz"
ssh $SSH_OPTS "root@${PROXMOX_HOST}" "
pct push $VMID /tmp/dbis_frontend_deploy.tar.gz /tmp/dbis_frontend_deploy.tar.gz
pct exec $VMID -- bash -c 'rm -rf \"${CONTAINER_DEPLOY_PATH}\" && mkdir -p \"${CONTAINER_DEPLOY_PATH}\" && tar xzf /tmp/dbis_frontend_deploy.tar.gz -C \"${CONTAINER_DEPLOY_PATH}\" && rm -f /tmp/dbis_frontend_deploy.tar.gz'
if pct exec $VMID -- systemctl reload nginx 2>/dev/null || pct exec $VMID -- systemctl restart nginx 2>/dev/null; then
: nginx reloaded
else
pct exec $VMID -- pkill -f 'python3 -m http.server' 2>/dev/null || true
if pct exec $VMID -- bash -c "cd ${CONTAINER_DEPLOY_PATH} && nohup python3 -m http.server 80 >/tmp/http.log 2>&1 & sleep 1"; then
echo 'Started python3 http.server on port 80'
else
echo "Note: nginx not running; configure a web server to serve $CONTAINER_DEPLOY_PATH"
fi
fi
rm -f /tmp/dbis_frontend_deploy.tar.gz
"
FRONTEND_URL="http://${IP_DBIS_FRONTEND:-192.168.11.130}"
echo "Done. Frontend: $FRONTEND_URL"
# Post-deploy health check
curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 "$FRONTEND_URL" 2>/dev/null | grep -q "200\|301\|302" && echo "Health check: OK" || echo "Health check: (run curl $FRONTEND_URL to verify)"