Files
breakpilot-compliance/scripts/deploy.sh
Sharang Parnerkar 8ec8af4c2d
Some checks failed
Build + Deploy / build-admin-compliance (push) Failing after 45s
Build + Deploy / build-backend-compliance (push) Successful in 13s
Build + Deploy / build-ai-sdk (push) Successful in 40s
Build + Deploy / build-developer-portal (push) Successful in 12s
Build + Deploy / build-tts (push) Successful in 11s
Build + Deploy / build-document-crawler (push) Successful in 14s
Build + Deploy / build-dsms-gateway (push) Successful in 12s
Build + Deploy / trigger-orca (push) Has been skipped
CI/CD / loc-budget (push) Successful in 21s
CI/CD / guardrail-integrity (push) Has been skipped
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Successful in 48s
CI/CD / test-python-backend-compliance (push) Failing after 38s
CI/CD / test-python-document-crawler (push) Successful in 31s
CI/CD / test-python-dsms-gateway (push) Successful in 27s
CI/CD / sbom-scan (push) Has been skipped
CI/CD / validate-canonical-controls (push) Successful in 19s
chore: remove all gitea remote references; single origin push only
There is only one remote (origin). Removed all occurrences of:
  - git push gitea / git push origin main && git push gitea main
  - "Pushing to gitea (external)" in deploy.sh
  - # gitea: git@gitea.meghsakha.com:... remote comment in docs-src/index.md
  - "Push auf gitea triggert" → "Push auf origin triggert" in docs
  - Clone URL updated to ssh://git@coolify.meghsakha.com:22222/... in
    README.md and CONTRIBUTING.md

Web UI URLs (gitea.meghsakha.com/...) are unchanged — those are still valid.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 16:16:12 +02:00

161 lines
5.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# =========================================================
# BreakPilot Compliance — Deploy Script
# =========================================================
# Pushes to both remotes, rebuilds changed services on
# Mac Mini, and monitors Coolify production health.
#
# Usage: ./scripts/deploy.sh
# =========================================================
set -euo pipefail
# --- Configuration ---
PROJECT="breakpilot-compliance"
PROJECT_DIR="/Users/benjaminadmin/Projekte/${PROJECT}"
COMPOSE_FILE="${PROJECT_DIR}/docker-compose.yml"
DOCKER="/usr/local/bin/docker"
MAC_MINI="macmini"
# Coolify health endpoints
HEALTH_ENDPOINTS=(
"https://api-dev.breakpilot.ai/health"
"https://sdk-dev.breakpilot.ai/health"
)
HEALTH_INTERVAL=20
HEALTH_TIMEOUT=300 # 5 minutes
# Map top-level directory to docker-compose service name
dir_to_service() {
case "$1" in
admin-compliance) echo "admin-compliance" ;;
backend-compliance) echo "backend-compliance" ;;
ai-compliance-sdk) echo "ai-compliance-sdk" ;;
developer-portal) echo "developer-portal" ;;
compliance-tts-service) echo "compliance-tts-service" ;;
document-crawler) echo "document-crawler" ;;
dsms-node) echo "dsms-node" ;;
dsms-gateway) echo "dsms-gateway" ;;
docs-src) echo "docs" ;;
*) echo "" ;;
esac
}
ALL_SERVICES="admin-compliance backend-compliance ai-compliance-sdk developer-portal compliance-tts-service document-crawler dsms-node dsms-gateway docs"
# --- Helpers ---
info() { printf "\033[1;34m[INFO]\033[0m %s\n" "$*"; }
ok() { printf "\033[1;32m[OK]\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*"; }
fail() { printf "\033[1;31m[FAIL]\033[0m %s\n" "$*"; }
# --- Step 1: Push to origin ---
info "Pushing to origin..."
git push origin main
ok "Pushed to origin."
# --- Step 2: Detect changed services ---
info "Detecting changed services since last deploy..."
# Get the commit before the push (what Mac Mini currently has)
REMOTE_HEAD=$(ssh "${MAC_MINI}" "git -C ${PROJECT_DIR} rev-parse HEAD" 2>/dev/null || echo "")
LOCAL_HEAD=$(git rev-parse HEAD)
CHANGED_SERVICES=""
if [ -z "${REMOTE_HEAD}" ] || [ "${REMOTE_HEAD}" = "${LOCAL_HEAD}" ]; then
info "Cannot determine remote HEAD or already equal. Checking last commit diff..."
CHANGED_DIRS=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | cut -d'/' -f1 | sort -u)
else
CHANGED_DIRS=$(git diff --name-only "${REMOTE_HEAD}" "${LOCAL_HEAD}" 2>/dev/null | cut -d'/' -f1 | sort -u)
fi
for dir in ${CHANGED_DIRS}; do
svc=$(dir_to_service "${dir}")
if [ -n "${svc}" ]; then
CHANGED_SERVICES="${CHANGED_SERVICES} ${svc}"
fi
done
# Also check if docker-compose.yml itself changed
if echo "${CHANGED_DIRS}" | grep -q "^docker-compose"; then
info "docker-compose.yml changed — will rebuild all services."
CHANGED_SERVICES="${ALL_SERVICES}"
fi
# Deduplicate
CHANGED_SERVICES=$(echo "${CHANGED_SERVICES}" | tr ' ' '\n' | sort -u | tr '\n' ' ' | xargs)
if [ -z "${CHANGED_SERVICES}" ]; then
warn "No service directories changed. Nothing to rebuild on Mac Mini."
info "Orca will still deploy from the origin push."
else
info "Changed services: ${CHANGED_SERVICES}"
# --- Step 3: Pull code on Mac Mini ---
info "Pulling latest code on Mac Mini..."
ssh "${MAC_MINI}" "git -C ${PROJECT_DIR} pull --no-rebase origin main"
ok "Code pulled on Mac Mini."
# --- Step 4: Rebuild + restart changed services ---
info "Building changed services on Mac Mini: ${CHANGED_SERVICES}"
ssh "${MAC_MINI}" "${DOCKER} compose -f ${COMPOSE_FILE} build ${CHANGED_SERVICES}"
ok "Build complete."
info "Restarting changed services on Mac Mini: ${CHANGED_SERVICES}"
ssh "${MAC_MINI}" "${DOCKER} compose -f ${COMPOSE_FILE} up -d --no-deps ${CHANGED_SERVICES}"
ok "Services restarted on Mac Mini."
fi
# --- Step 5: Monitor Coolify health in background ---
info "Monitoring Coolify production health in background (every ${HEALTH_INTERVAL}s, max ${HEALTH_TIMEOUT}s)..."
(
elapsed=0
all_healthy=false
while [ ${elapsed} -lt ${HEALTH_TIMEOUT} ]; do
sleep ${HEALTH_INTERVAL}
elapsed=$((elapsed + HEALTH_INTERVAL))
healthy_count=0
for endpoint in "${HEALTH_ENDPOINTS[@]}"; do
if curl -sf --max-time 5 "${endpoint}" >/dev/null 2>&1; then
healthy_count=$((healthy_count + 1))
fi
done
if [ ${healthy_count} -eq ${#HEALTH_ENDPOINTS[@]} ]; then
all_healthy=true
break
fi
printf "\033[1;34m[HEALTH]\033[0m %d/%d endpoints healthy (%ds elapsed)\n" \
${healthy_count} ${#HEALTH_ENDPOINTS[@]} ${elapsed}
done
echo ""
if ${all_healthy}; then
printf "\033[1;32m========================================\033[0m\n"
printf "\033[1;32m Coolify deploy complete! \033[0m\n"
printf "\033[1;32m All health endpoints are healthy. \033[0m\n"
printf "\033[1;32m Test at: https://admin-dev.breakpilot.ai\033[0m\n"
printf "\033[1;32m========================================\033[0m\n"
else
printf "\033[1;31m========================================\033[0m\n"
printf "\033[1;31m Coolify deploy may have failed! \033[0m\n"
printf "\033[1;31m Not all endpoints healthy after %ds. \033[0m\n" ${HEALTH_TIMEOUT}
printf "\033[1;31m Check Coolify logs. \033[0m\n"
printf "\033[1;31m========================================\033[0m\n"
fi
) &
HEALTH_PID=$!
# --- Step 6: Report ---
echo ""
ok "Local deploy to Mac Mini: done."
info "Coolify health monitor running in background (PID ${HEALTH_PID})."
info "You will see a status banner when Coolify is ready (or after ${HEALTH_TIMEOUT}s timeout)."
echo ""