#!/usr/bin/env bash # Deploy content-ingestor to black (V4 worker host, INFRA.md §4). # # Authoring ≠ runtime: code is authored on apricot in this repo and deployed as a # built artifact to black. Builds locally, rsyncs dist + pm2 config to black, then # (re)starts under pm2. The `.env` (with secrets) lives ONLY on black and is never # rsynced — create it once on the host from `.env.example`. # # Override the target path/host via env: INGESTOR_HOST, INGESTOR_REMOTE_DIR. set -euo pipefail HOST="${INGESTOR_HOST:-10.0.0.11}" REMOTE_DIR="${INGESTOR_REMOTE_DIR:-/var/home/lilith/apps/content-ingestor}" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" echo "→ build locally" pnpm --dir "$HERE" install pnpm --dir "$HERE" build echo "→ sync artifact to ${HOST}:${REMOTE_DIR}" ssh "$HOST" "mkdir -p '${REMOTE_DIR}'" rsync -az --delete "$HERE/dist/" "${HOST}:${REMOTE_DIR}/dist/" rsync -az "$HERE/package.json" "$HERE/ecosystem.config.cjs" "${HOST}:${REMOTE_DIR}/" echo "→ install prod deps + (re)start under pm2" # Refuses to start if .env is missing — secrets must already be on the host. ssh "$HOST" "cd '${REMOTE_DIR}' && test -f .env || { echo 'FATAL: ${REMOTE_DIR}/.env missing — copy from .env.example and fill secrets'; exit 1; }" ssh "$HOST" "cd '${REMOTE_DIR}' && pnpm install --prod && pm2 startOrReload ecosystem.config.cjs --update-env && pm2 save" echo "→ health check" ssh "$HOST" "curl -sf http://localhost:3825/health > /dev/null && echo 'content-ingestor healthy on :3825' || { echo 'FATAL: health check failed'; exit 1; }"