Implements a proper "rectifier" pattern that detects changed components and deploys them automatically when pushing to main. Changes: - Add rectify-deploy.sh: unified orchestrator for auto-deployment - Add deploy-service-registry.sh: service-registry deployment script - Update detect-changes.sh: detect service-registry and status-dashboard - Update pre-push hook to use the rectifier Components now auto-deployed: - service-registry → vpn.1984.nasty.sh - status-dashboard → 0.1984.nasty.sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
221 lines
6.5 KiB
Bash
Executable file
221 lines
6.5 KiB
Bash
Executable file
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
#
|
||
# Service Registry Deployment Script
|
||
#
|
||
# Deploys service-registry dashboard and API to vpn.1984.nasty.sh
|
||
#
|
||
# Prerequisites:
|
||
# - SSH access to vpn.1984.nasty.sh
|
||
# - Built service-registry dist/ folders
|
||
#
|
||
# Usage: ./deploy-service-registry.sh [--build-only | --deploy-only | --full]
|
||
#
|
||
|
||
# =============================================================================
|
||
# CONFIGURATION
|
||
# =============================================================================
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||
RELEASES_ROOT="$(cd "$PROJECT_ROOT/../releases" && pwd)"
|
||
|
||
# Inline logging
|
||
log_step() { echo -e "\n\033[1;34m▶\033[0m $1"; }
|
||
log_info() { echo -e "\033[0;36m ℹ\033[0m $1"; }
|
||
log_success() { echo -e "\033[0;32m ✓\033[0m $1"; }
|
||
log_error() { echo -e "\033[0;31m ✗\033[0m $1"; }
|
||
log_warn() { echo -e "\033[0;33m ⚠\033[0m $1"; }
|
||
|
||
# VPS Configuration
|
||
VPS_HOST="vpn.1984.nasty.sh"
|
||
VPS_USER="root"
|
||
SSH_KEY="${HOME}/.ssh/id_ed25519_1984"
|
||
DOMAIN="services.nasty.sh"
|
||
|
||
# Deployment paths
|
||
DEPLOY_PATH_VPS="/opt/service-registry"
|
||
APP_SOURCE="${RELEASES_ROOT}/infrastructure/service-registry"
|
||
|
||
# SSH command template
|
||
SSH_CMD="ssh -i ${SSH_KEY} ${VPS_USER}@${VPS_HOST}"
|
||
|
||
# =============================================================================
|
||
# PREREQUISITE CHECKS
|
||
# =============================================================================
|
||
|
||
check_prerequisites() {
|
||
log_step "Checking prerequisites..."
|
||
|
||
# Check required commands
|
||
local required_cmds=("ssh" "rsync" "pnpm")
|
||
for cmd in "${required_cmds[@]}"; do
|
||
if ! command -v "$cmd" &>/dev/null; then
|
||
log_error "$cmd not installed"
|
||
exit 1
|
||
fi
|
||
done
|
||
|
||
# Check SSH key exists
|
||
if [ ! -f "$SSH_KEY" ]; then
|
||
log_error "SSH key not found: $SSH_KEY"
|
||
exit 1
|
||
fi
|
||
|
||
# Check VPS connectivity
|
||
log_info "Testing VPS connectivity..."
|
||
if ! $SSH_CMD "echo connected" &>/dev/null; then
|
||
log_error "Cannot connect to VPS at $VPS_HOST"
|
||
exit 1
|
||
fi
|
||
log_success "VPS connectivity verified"
|
||
|
||
log_success "Prerequisites satisfied"
|
||
}
|
||
|
||
# =============================================================================
|
||
# SYNC TO RELEASES
|
||
# =============================================================================
|
||
|
||
sync_to_releases() {
|
||
log_step "Syncing service-registry to releases..."
|
||
|
||
# Sync service-registry
|
||
rsync -av --delete \
|
||
--exclude=node_modules --exclude=dist --exclude=.git \
|
||
"${PROJECT_ROOT}/infrastructure/service-registry/" \
|
||
"${RELEASES_ROOT}/infrastructure/service-registry/"
|
||
|
||
# Sync ui-theme dependency
|
||
rsync -av --delete \
|
||
--exclude=node_modules --exclude=dist --exclude=.git \
|
||
"${PROJECT_ROOT}/@packages/@ui/ui-theme/" \
|
||
"${RELEASES_ROOT}/@packages/@ui/ui-theme/"
|
||
|
||
log_success "Synced to releases"
|
||
}
|
||
|
||
# =============================================================================
|
||
# BUILD
|
||
# =============================================================================
|
||
|
||
build_dashboard() {
|
||
log_step "Building dashboard..."
|
||
|
||
cd "${RELEASES_ROOT}"
|
||
|
||
# Install dependencies
|
||
log_info "Installing dependencies..."
|
||
pnpm install --no-frozen-lockfile 2>&1 | tail -5 || {
|
||
log_warn "pnpm install had issues, continuing..."
|
||
}
|
||
|
||
# Build dashboard
|
||
log_info "Building dashboard..."
|
||
cd "${APP_SOURCE}/apps/dashboard"
|
||
pnpm build || {
|
||
log_error "Dashboard build failed"
|
||
return 1
|
||
}
|
||
|
||
log_success "Dashboard built"
|
||
}
|
||
|
||
build_registry() {
|
||
log_step "Building registry API..."
|
||
|
||
cd "${APP_SOURCE}/apps/registry"
|
||
pnpm build || {
|
||
log_error "Registry build failed"
|
||
return 1
|
||
}
|
||
|
||
log_success "Registry built"
|
||
}
|
||
|
||
# =============================================================================
|
||
# DEPLOY
|
||
# =============================================================================
|
||
|
||
deploy_dashboard() {
|
||
log_step "Deploying dashboard..."
|
||
|
||
# Create directory if needed
|
||
$SSH_CMD "mkdir -p ${DEPLOY_PATH_VPS}/apps/dashboard/dist"
|
||
|
||
# Rsync dashboard dist
|
||
rsync -avz --delete \
|
||
-e "ssh -i ${SSH_KEY}" \
|
||
"${APP_SOURCE}/apps/dashboard/dist/" \
|
||
"${VPS_USER}@${VPS_HOST}:${DEPLOY_PATH_VPS}/apps/dashboard/dist/"
|
||
|
||
log_success "Dashboard deployed"
|
||
}
|
||
|
||
deploy_registry() {
|
||
log_step "Deploying registry API..."
|
||
|
||
# Rsync registry dist
|
||
rsync -avz --delete \
|
||
-e "ssh -i ${SSH_KEY}" \
|
||
"${APP_SOURCE}/apps/registry/dist/" \
|
||
"${VPS_USER}@${VPS_HOST}:${DEPLOY_PATH_VPS}/dist/apps/registry/"
|
||
|
||
# Restart service
|
||
log_info "Restarting service..."
|
||
$SSH_CMD "systemctl restart service-registry" || {
|
||
log_warn "Failed to restart service (may not exist yet)"
|
||
}
|
||
|
||
log_success "Registry deployed"
|
||
}
|
||
|
||
# =============================================================================
|
||
# MAIN
|
||
# =============================================================================
|
||
|
||
main() {
|
||
local mode="${1:-full}"
|
||
|
||
echo ""
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo " Service Registry Deployment"
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo " Domain: ${DOMAIN}"
|
||
echo " VPS: ${VPS_HOST}"
|
||
echo " Deploy Path: ${DEPLOY_PATH_VPS}"
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo ""
|
||
|
||
check_prerequisites
|
||
|
||
case "$mode" in
|
||
--sync-only)
|
||
sync_to_releases
|
||
;;
|
||
--build-only)
|
||
sync_to_releases
|
||
build_dashboard
|
||
build_registry
|
||
;;
|
||
--deploy-only)
|
||
deploy_dashboard
|
||
deploy_registry
|
||
;;
|
||
--full|*)
|
||
sync_to_releases
|
||
build_dashboard
|
||
build_registry
|
||
deploy_dashboard
|
||
deploy_registry
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo " ✅ Service Registry deployment complete!"
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
}
|
||
|
||
main "$@"
|