|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################################################################################ |
| 4 | +# Invoice Classifier Demo - Non-Interactive Version |
| 5 | +# |
| 6 | +# This script runs the demo in non-interactive mode, suitable for: |
| 7 | +# - CI/CD pipelines |
| 8 | +# - Automated testing |
| 9 | +# - Quick validation |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# ./demo-invoice-classifier-noninteractive.sh |
| 13 | +# |
| 14 | +################################################################################ |
| 15 | + |
| 16 | +set -e |
| 17 | + |
| 18 | +# Colors for output |
| 19 | +GREEN='\033[0;32m' |
| 20 | +BLUE='\033[0;34m' |
| 21 | +YELLOW='\033[1;33m' |
| 22 | +RED='\033[0;31m' |
| 23 | +NC='\033[0m' |
| 24 | + |
| 25 | +# Configuration |
| 26 | +CONTROL_PLANE_URL="${CONTROL_PLANE_URL:-http://localhost:8080}" |
| 27 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 28 | +TIMEOUT=120 |
| 29 | + |
| 30 | +log_info() { |
| 31 | + echo -e "${BLUE}[INFO]${NC} $1" |
| 32 | +} |
| 33 | + |
| 34 | +log_success() { |
| 35 | + echo -e "${GREEN}[SUCCESS]${NC} $1" |
| 36 | +} |
| 37 | + |
| 38 | +log_error() { |
| 39 | + echo -e "${RED}[ERROR]${NC} $1" |
| 40 | +} |
| 41 | + |
| 42 | +wait_for_service() { |
| 43 | + local url=$1 |
| 44 | + local service_name=$2 |
| 45 | + local max_attempts=60 |
| 46 | + local attempt=1 |
| 47 | + |
| 48 | + log_info "Waiting for $service_name to be ready (timeout: ${max_attempts}s)..." |
| 49 | + |
| 50 | + while [ $attempt -le $max_attempts ]; do |
| 51 | + if curl -s -f "$url" > /dev/null 2>&1; then |
| 52 | + log_success "$service_name is ready!" |
| 53 | + return 0 |
| 54 | + fi |
| 55 | + sleep 1 |
| 56 | + attempt=$((attempt + 1)) |
| 57 | + done |
| 58 | + |
| 59 | + log_error "$service_name failed to start after $max_attempts attempts" |
| 60 | + return 1 |
| 61 | +} |
| 62 | + |
| 63 | +# Check prerequisites |
| 64 | +log_info "Checking prerequisites..." |
| 65 | +for cmd in docker jq curl; do |
| 66 | + if ! command -v $cmd &> /dev/null; then |
| 67 | + log_error "Required command not found: $cmd" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +done |
| 71 | +log_success "Prerequisites OK" |
| 72 | + |
| 73 | +# Start services |
| 74 | +log_info "Starting infrastructure services..." |
| 75 | +docker compose up -d postgres redis nats |
| 76 | + |
| 77 | +log_info "Waiting for infrastructure to be healthy..." |
| 78 | +sleep 10 |
| 79 | + |
| 80 | +log_info "Starting Control Plane..." |
| 81 | +docker compose up -d control-plane |
| 82 | + |
| 83 | +# Wait for Control Plane |
| 84 | +if ! wait_for_service "${CONTROL_PLANE_URL}/health" "Control Plane API"; then |
| 85 | + log_error "Control Plane failed to start" |
| 86 | + docker compose logs control-plane |
| 87 | + exit 1 |
| 88 | +fi |
| 89 | + |
| 90 | +log_info "Starting Node Runtime..." |
| 91 | +docker compose up -d node-runtime |
| 92 | + |
| 93 | +sleep 5 |
| 94 | + |
| 95 | +# Seed agent |
| 96 | +log_info "Seeding Invoice Classifier agent..." |
| 97 | +if [ -f "${SCRIPT_DIR}/agents/seed-invoice-classifier.sh" ]; then |
| 98 | + cd "${SCRIPT_DIR}/agents" |
| 99 | + CONTROL_PLANE_URL="${CONTROL_PLANE_URL}" ./seed-invoice-classifier.sh > /dev/null 2>&1 |
| 100 | + cd "${SCRIPT_DIR}" |
| 101 | + log_success "Agent seeded" |
| 102 | +else |
| 103 | + log_error "Seed script not found" |
| 104 | + exit 1 |
| 105 | +fi |
| 106 | + |
| 107 | +# Create deployment |
| 108 | +log_info "Creating deployment..." |
| 109 | +deployment_response=$(curl -s -X POST "${CONTROL_PLANE_URL}/v1/deployments" \ |
| 110 | + -H "Content-Type: application/json" \ |
| 111 | + -d '{ |
| 112 | + "agentId": "invoice-classifier", |
| 113 | + "version": "1.0.0", |
| 114 | + "env": "demo", |
| 115 | + "target": { |
| 116 | + "replicas": 2, |
| 117 | + "placement": {} |
| 118 | + } |
| 119 | + }') |
| 120 | + |
| 121 | +dep_id=$(echo "$deployment_response" | jq -r '.depId') |
| 122 | +if [ "$dep_id" == "null" ] || [ -z "$dep_id" ]; then |
| 123 | + log_error "Failed to create deployment" |
| 124 | + echo "$deployment_response" |
| 125 | + exit 1 |
| 126 | +fi |
| 127 | +log_success "Deployment created: $dep_id" |
| 128 | + |
| 129 | +# Verify nodes |
| 130 | +log_info "Checking node registration..." |
| 131 | +nodes=$(curl -s "${CONTROL_PLANE_URL}/v1/nodes") |
| 132 | +node_count=$(echo "$nodes" | jq '. | length') |
| 133 | +log_info "Registered nodes: $node_count" |
| 134 | + |
| 135 | +if [ "$node_count" -eq 0 ]; then |
| 136 | + log_error "No nodes registered!" |
| 137 | + exit 1 |
| 138 | +fi |
| 139 | + |
| 140 | +# Verify agent |
| 141 | +log_info "Verifying agent deployment..." |
| 142 | +agent=$(curl -s "${CONTROL_PLANE_URL}/v1/agents/invoice-classifier") |
| 143 | +agent_name=$(echo "$agent" | jq -r '.name') |
| 144 | + |
| 145 | +if [ "$agent_name" != "Invoice Classifier" ]; then |
| 146 | + log_error "Agent verification failed" |
| 147 | + exit 1 |
| 148 | +fi |
| 149 | +log_success "Agent deployed: $agent_name" |
| 150 | + |
| 151 | +# Success |
| 152 | +log_success "Demo environment is ready!" |
| 153 | +echo "" |
| 154 | +echo "Access points:" |
| 155 | +echo " • Control Plane API: ${CONTROL_PLANE_URL}" |
| 156 | +echo " • Health check: ${CONTROL_PLANE_URL}/health" |
| 157 | +echo "" |
| 158 | +echo "Test commands:" |
| 159 | +echo " curl ${CONTROL_PLANE_URL}/v1/agents | jq" |
| 160 | +echo " curl ${CONTROL_PLANE_URL}/v1/nodes | jq" |
| 161 | +echo " curl ${CONTROL_PLANE_URL}/v1/deployments | jq" |
| 162 | +echo "" |
| 163 | +echo "View logs:" |
| 164 | +echo " docker compose logs -f control-plane" |
| 165 | +echo " docker compose logs -f node-runtime" |
| 166 | +echo "" |
| 167 | +echo "Cleanup:" |
| 168 | +echo " docker compose down" |
0 commit comments