diff --git a/scripts/deployment/phoenix-deploy-dbis-portal-live-from-workspace.sh b/scripts/deployment/phoenix-deploy-dbis-portal-live-from-workspace.sh index b4eae43b..090b94b4 100755 --- a/scripts/deployment/phoenix-deploy-dbis-portal-live-from-workspace.sh +++ b/scripts/deployment/phoenix-deploy-dbis-portal-live-from-workspace.sh @@ -40,6 +40,7 @@ TMP_DIR="$(mktemp -d)" BUILD_CONTEXT="$TMP_DIR/gov-portals" ARCHIVE="$TMP_DIR/gov-portals-dbis-live.tgz" REMOTE_ARCHIVE="/tmp/gov-portals-dbis-live-${PHOENIX_DEPLOY_SHA:-manual}-$$.tgz" +REMOTE_STAGE_DIR="/srv/gov-portals-new-${PHOENIX_DEPLOY_SHA:-manual}-$$" cleanup() { rm -rf "$TMP_DIR" @@ -83,17 +84,20 @@ echo "Pushing archive into CT $VMID_GOV_PORTALS" ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "root@$PROXMOX_HOST" \ "pct push $VMID_GOV_PORTALS '$REMOTE_ARCHIVE' '$REMOTE_ARCHIVE'" -echo "Extracting, building, and restarting DBIS inside CT $VMID_GOV_PORTALS" +echo "Extracting and building DBIS in a staged directory inside CT $VMID_GOV_PORTALS" ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "root@$PROXMOX_HOST" \ "pct exec $VMID_GOV_PORTALS -- bash -s" <&2; exit 1; } -cd "\$CT_APP_DIR" +cd "\$REMOTE_STAGE_DIR" "\$PNPM_BIN" install --frozen-lockfile "\$PNPM_BIN" --filter portal-dbis build +PREVIOUS_DIR="" +if [ -e "\$CT_APP_DIR" ]; then + PREVIOUS_DIR="\${CT_APP_DIR}-previous-\$(date +%Y%m%d%H%M%S)" + mv "\$CT_APP_DIR" "\$PREVIOUS_DIR" +fi +mv "\$REMOTE_STAGE_DIR" "\$CT_APP_DIR" + cat > "/etc/systemd/system/\$SERVICE_NAME.service" </dev/null +if ! curl -fsS --max-time 15 "http://127.0.0.1:\$DBIS_PORT/" >/dev/null; then + if [ -n "\$PREVIOUS_DIR" ] && [ -d "\$PREVIOUS_DIR" ]; then + rm -rf "\$CT_APP_DIR" + mv "\$PREVIOUS_DIR" "\$CT_APP_DIR" + systemctl restart "\$SERVICE_NAME" || true + fi + exit 1 +fi CT_SCRIPT ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "root@$PROXMOX_HOST" "rm -f '$REMOTE_ARCHIVE'" >/dev/null 2>&1 || true