Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- Config, docs, scripts, and backup manifests - Submodule refs unchanged (m = modified content in submodules) Made-with: Cursor
183 lines
6.7 KiB
Bash
Executable File
183 lines
6.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Create LXC 7804 (gov-portals-dev) and deploy the four Gov Portals (DBIS, ICCC, OMNL, XOM)
|
|
# Serving at dbis/iccc/omnl/xom.xom-dev.phoenix.sankofa.nexus via NPMplus
|
|
#
|
|
# Usage:
|
|
# From proxmox repo root, with SSH to Proxmox host:
|
|
# bash scripts/deployment/deploy-gov-portals-to-7804.sh [--create-only|--deploy-only]
|
|
#
|
|
# Prerequisites:
|
|
# - SSH to Proxmox host (default: r630-01)
|
|
# - gov-portals-monorepo cloned at /home/intlc/projects/gov-portals-monorepo (or GOV_PORTALS_SOURCE)
|
|
# - Gitea token in .env for clone (or public clone)
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true
|
|
[ -f "$PROJECT_ROOT/.env" ] && set +u && source "$PROJECT_ROOT/.env" 2>/dev/null || true && set -u
|
|
|
|
# Gov Portals dev VM (7804) - Sankofa/Phoenix range
|
|
VMID_GOV_PORTALS=7804
|
|
IP_GOV_PORTALS_DEV="${IP_GOV_PORTALS_DEV:-192.168.11.54}"
|
|
HOSTNAME_GOV_PORTALS="gov-portals-dev"
|
|
PROXMOX_NODE="${PROXMOX_NODE:-r630-01}"
|
|
PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.11}"
|
|
STORAGE="${STORAGE:-local-lvm}"
|
|
TEMPLATE="${TEMPLATE:-local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst}"
|
|
GATEWAY="${GATEWAY:-192.168.11.1}"
|
|
NETWORK="${NETWORK:-vmbr0}"
|
|
|
|
# Source of gov-portals-monorepo (local path to rsync, or git URL)
|
|
GOV_PORTALS_SOURCE="${GOV_PORTALS_SOURCE:-/home/intlc/projects/gov-portals-monorepo}"
|
|
CREATE_ONLY=false
|
|
DEPLOY_ONLY=false
|
|
[[ "${1:-}" == "--create-only" ]] && CREATE_ONLY=true
|
|
[[ "${1:-}" == "--deploy-only" ]] && DEPLOY_ONLY=true
|
|
|
|
log() { echo "[$(date +%H:%M:%S)] $*"; }
|
|
run_ssh() { ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new root@$PROXMOX_HOST "$@"; }
|
|
run_ct() { run_ssh "pct exec $VMID_GOV_PORTALS -- $@"; }
|
|
|
|
# Create LXC 7804
|
|
create_container() {
|
|
if run_ssh "pct list 2>/dev/null | grep -q '^$VMID_GOV_PORTALS '"; then
|
|
log "Container $VMID_GOV_PORTALS already exists"
|
|
return 0
|
|
fi
|
|
log "Creating LXC $VMID_GOV_PORTALS ($HOSTNAME_GOV_PORTALS) on $PROXMOX_NODE..."
|
|
run_ssh "pct create $VMID_GOV_PORTALS $TEMPLATE \
|
|
--hostname $HOSTNAME_GOV_PORTALS \
|
|
--memory 2048 \
|
|
--cores 2 \
|
|
--rootfs $STORAGE:20 \
|
|
--net0 name=eth0,bridge=$NETWORK,ip=$IP_GOV_PORTALS_DEV/24,gw=$GATEWAY \
|
|
--description 'Gov Portals dev - DBIS, ICCC, OMNL, XOM' \
|
|
--start 1 \
|
|
--onboot 1 \
|
|
--unprivileged 1 \
|
|
--features nesting=1,keyctl=1"
|
|
log "Waiting for container to boot..."
|
|
sleep 10
|
|
}
|
|
|
|
# Deploy apps inside container
|
|
deploy_inside() {
|
|
log "Deploying gov-portals inside container..."
|
|
|
|
# Install Node 20, pnpm
|
|
run_ct "bash -lc 'command -v node >/dev/null 2>&1 || (curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs)'" 2>/dev/null || true
|
|
run_ct "bash -lc 'command -v pnpm >/dev/null 2>&1 || npm install -g pnpm'" 2>/dev/null || true
|
|
|
|
# Prepare deploy dir
|
|
run_ct "mkdir -p /srv/gov-portals"
|
|
run_ct "rm -rf /srv/gov-portals/.git /srv/gov-portals/DBIS /srv/gov-portals/ICCC /srv/gov-portals/OMNL /srv/gov-portals/XOM /srv/gov-portals/node_modules /srv/gov-portals/*/node_modules 2>/dev/null || true"
|
|
|
|
# Rsync monorepo (from host running this script)
|
|
if [ -d "$GOV_PORTALS_SOURCE" ]; then
|
|
log "Rsyncing gov-portals-monorepo to container..."
|
|
rsync -az --delete \
|
|
--exclude 'node_modules' \
|
|
--exclude '.next' \
|
|
--exclude '.git' \
|
|
"$GOV_PORTALS_SOURCE/" \
|
|
"root@$PROXMOX_HOST:/tmp/gov-portals-rsync/" 2>/dev/null || {
|
|
log "Rsync to Proxmox host failed - will try git clone inside container"
|
|
}
|
|
if run_ssh "test -d /tmp/gov-portals-rsync/packages"; then
|
|
run_ssh "pct push $VMID_GOV_PORTALS /tmp/gov-portals-rsync /srv/gov-portals --recursive" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
# Ensure we have submodules - clone if rsync didn't work
|
|
run_ct "bash -c '
|
|
cd /srv/gov-portals 2>/dev/null || mkdir -p /srv/gov-portals && cd /srv/gov-portals
|
|
if [ ! -f package.json ]; then
|
|
apt-get update -qq && apt-get install -y -qq git
|
|
git clone --recurse-submodules https://gitea.d-bis.org/Gov_Web_Portals/gov-portals-monorepo.git .
|
|
fi
|
|
if [ -d .git ] && [ ! -d DBIS/.git ]; then
|
|
git submodule update --init --recursive
|
|
fi
|
|
'"
|
|
|
|
# Install deps and build each portal
|
|
run_ct "bash -c '
|
|
cd /srv/gov-portals
|
|
export PATH=\"/usr/bin:/usr/local/bin:\$PATH\"
|
|
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
|
|
|
|
for portal in DBIS ICCC OMNL XOM; do
|
|
if [ -d \"\$portal\" ]; then
|
|
echo \"Building \$portal...\"
|
|
(cd \"\$portal\" && pnpm run build) 2>/dev/null || true
|
|
fi
|
|
done
|
|
'"
|
|
|
|
# Create systemd services or PM2 - use simple node/next start
|
|
log "Creating startup script and systemd service..."
|
|
run_ct "bash -c '
|
|
cat > /srv/gov-portals/start-portals.sh << \"SCRIPT\"
|
|
#!/usr/bin/env bash
|
|
cd /srv/gov-portals
|
|
export NODE_ENV=production
|
|
PORT=3001 node DBIS/node_modules/next/dist/bin/next start -p 3001 &
|
|
PORT=3002 node ICCC/node_modules/next/dist/bin/next start -p 3002 &
|
|
PORT=3003 node OMNL/node_modules/next/dist/bin/next start -p 3003 &
|
|
PORT=3004 node XOM/node_modules/next/dist/bin/next start -p 3004 &
|
|
wait
|
|
SCRIPT
|
|
chmod +x /srv/gov-portals/start-portals.sh
|
|
'"
|
|
|
|
# Create systemd services for each portal
|
|
run_ct "bash -c '
|
|
for spec in DBIS:3001 ICCC:3002 OMNL:3003 XOM:3004; do
|
|
portal=\${spec%%:*}
|
|
port=\${spec##*:}
|
|
cat > /etc/systemd/system/gov-portal-\${portal}.service << EOF
|
|
[Unit]
|
|
Description=Gov Portal \$portal
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
WorkingDirectory=/srv/gov-portals/\$portal
|
|
Environment=NODE_ENV=production
|
|
Environment=PORT=\$port
|
|
ExecStart=/usr/bin/node /srv/gov-portals/\$portal/node_modules/next/dist/bin/next start -p \$port
|
|
Restart=on-failure
|
|
RestartSec=5
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
systemctl daemon-reload
|
|
systemctl enable gov-portal-\${portal}
|
|
systemctl restart gov-portal-\${portal} 2>/dev/null || systemctl start gov-portal-\${portal}
|
|
done
|
|
'" 2>/dev/null || log "Services may need manual start - run: pct exec 7804 -- systemctl start gov-portal-DBIS gov-portal-ICCC gov-portal-OMNL gov-portal-XOM"
|
|
|
|
log "Deployment complete. Portals should be starting on ports 3001-3004."
|
|
}
|
|
|
|
# Main
|
|
if [ "$DEPLOY_ONLY" = true ]; then
|
|
deploy_inside
|
|
elif [ "$CREATE_ONLY" = true ]; then
|
|
create_container
|
|
else
|
|
create_container
|
|
deploy_inside
|
|
fi
|
|
|
|
echo ""
|
|
echo "Gov Portals dev (7804) at $IP_GOV_PORTALS_DEV"
|
|
echo "Next: Run add-gov-portals-xom-dev-proxy-hosts.sh to add NPMplus proxy hosts"
|
|
echo " dbis.xom-dev.phoenix.sankofa.nexus → :3001"
|
|
echo " iccc.xom-dev.phoenix.sankofa.nexus → :3002"
|
|
echo " omnl.xom-dev.phoenix.sankofa.nexus → :3003"
|
|
echo " xom.xom-dev.phoenix.sankofa.nexus → :3004"
|