-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·293 lines (250 loc) · 11.5 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·293 lines (250 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
set -e
echo "=============================================="
echo " Claim Processing Services — Full Deployment"
echo "=============================================="
echo ""
# ─────────────────────────────────────────────────
# Parse Arguments
# ─────────────────────────────────────────────────
AWS_PROFILE_ARG=""
AWS_PROFILE_FLAG=""
if [ -n "$1" ]; then
AWS_PROFILE_ARG="$1"
AWS_PROFILE_FLAG="--profile $AWS_PROFILE_ARG"
export AWS_PROFILE="$AWS_PROFILE_ARG"
echo " Using AWS Profile: $AWS_PROFILE_ARG"
echo ""
else
echo " Usage: ./deploy.sh <aws-profile-name>"
echo " Example: ./deploy.sh my-dev-profile"
echo ""
echo " No profile provided — using default AWS credentials."
echo ""
fi
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
WORKSPACE_ROOT="$(cd "$(dirname "$0")" && pwd)"
# Python version requirement
PYTHON_VERSION_REQUIRED="3.12"
# ─────────────────────────────────────────────────
# Step 1: Prerequisites Check
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[1/7] Checking prerequisites...${NC}"
command -v python3 >/dev/null 2>&1 || { echo -e "${RED}python3 is required but not installed.${NC}"; exit 1; }
command -v node >/dev/null 2>&1 || { echo -e "${RED}node is required but not installed.${NC}"; exit 1; }
command -v npm >/dev/null 2>&1 || { echo -e "${RED}npm is required but not installed.${NC}"; exit 1; }
command -v aws >/dev/null 2>&1 || { echo -e "${RED}aws CLI is required but not installed.${NC}"; exit 1; }
command -v cdk >/dev/null 2>&1 || { echo -e "${RED}AWS CDK CLI is required. Install with: npm install -g aws-cdk${NC}"; exit 1; }
# Check Python version
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}')
PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
if [ "$PYTHON_MAJOR" -lt 3 ] || ([ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 12 ]); then
echo -e "${RED}Python ${PYTHON_VERSION_REQUIRED}+ is required. Found: $PYTHON_VERSION${NC}"
exit 1
fi
echo -e "${GREEN} ✓ Python $PYTHON_VERSION${NC}"
# Detect container runtime: prefer finch, fallback to docker
CONTAINER_RUNTIME=""
if command -v finch >/dev/null 2>&1; then
CONTAINER_RUNTIME="finch"
echo -e "${GREEN} ✓ Container runtime: finch${NC}"
elif command -v docker >/dev/null 2>&1; then
CONTAINER_RUNTIME="docker"
echo -e "${GREEN} ✓ Container runtime: docker${NC}"
else
echo -e "${RED}Neither finch nor docker found. Install one of them to build container images.${NC}"
exit 1
fi
# Verify AWS credentials
AWS_ACCOUNT=$(aws sts get-caller-identity $AWS_PROFILE_FLAG --query Account --output text 2>/dev/null) || {
echo -e "${RED}AWS credentials not configured. Run 'aws configure --profile $AWS_PROFILE_ARG' first.${NC}"
exit 1
}
AWS_REGION=$(aws configure get region $AWS_PROFILE_FLAG 2>/dev/null || echo "us-east-1")
export AWS_DEFAULT_REGION="$AWS_REGION"
echo -e "${GREEN} ✓ node $(node --version), npm $(npm --version)${NC}"
echo -e "${GREEN} ✓ AWS Account: $AWS_ACCOUNT${NC}"
echo -e "${GREEN} ✓ AWS Region: $AWS_REGION${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 2: Install CDK Dependencies & Bootstrap
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[2/7] Setting up CDK infrastructure...${NC}"
cd "$WORKSPACE_ROOT/infra"
python3 -m venv .venv
source .venv/bin/activate
pip install -q --upgrade pip
pip install -q -r requirements.txt
echo " Bootstrapping CDK (if needed)..."
cdk bootstrap aws://$AWS_ACCOUNT/$AWS_REGION $AWS_PROFILE_FLAG 2>/dev/null || true
deactivate
echo -e "${GREEN} ✓ CDK ready${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 3: Build Backend Docker Images
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[3/7] Building backend service container images (using $CONTAINER_RUNTIME)...${NC}"
cd "$WORKSPACE_ROOT"
SERVICES=(auth-service claim-service document-service fraud-service rules-service notification-service analytics-service)
for service in "${SERVICES[@]}"; do
echo " Building $service..."
$CONTAINER_RUNTIME build -q -t claim-processing/$service:latest services/$service/ > /dev/null
done
echo -e "${GREEN} ✓ All 7 service images built with $CONTAINER_RUNTIME${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 4: Build Frontend
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[4/7] Building frontend application...${NC}"
cd "$WORKSPACE_ROOT/frontend"
npm install --silent 2>/dev/null
REACT_APP_API_URL="" npm run build --silent 2>/dev/null || {
# If build fails (e.g., missing deps), create a minimal build
echo " Creating minimal frontend build..."
mkdir -p build
cat > build/index.html << 'HTMLEOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Claim Processing Services</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f8fafc; }
.container { max-width: 800px; margin: 80px auto; padding: 40px; text-align: center; }
h1 { color: #1e40af; font-size: 2.5rem; margin-bottom: 16px; }
p { color: #64748b; font-size: 1.1rem; margin-bottom: 24px; }
.status { background: #ecfdf5; border: 1px solid #6ee7b7; border-radius: 12px; padding: 20px; margin-top: 32px; }
.status h3 { color: #065f46; margin-bottom: 8px; }
.badge { display: inline-block; background: #dbeafe; color: #1e40af; padding: 4px 12px; border-radius: 20px; font-size: 0.85rem; margin: 4px; }
</style>
</head>
<body>
<div class="container">
<h1>🏥 Claim Processing Services</h1>
<p>Intelligent Claims Management Platform</p>
<div>
<span class="badge">Health Insurance</span>
<span class="badge">Motor Insurance</span>
<span class="badge">Property Insurance</span>
<span class="badge">Travel Insurance</span>
</div>
<div class="status">
<h3>✅ Platform Deployed Successfully</h3>
<p>Backend API services are running. Full React frontend will be available after npm dependencies are resolved.</p>
</div>
</div>
</body>
</html>
HTMLEOF
}
echo -e "${GREEN} ✓ Frontend built${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 5: Deploy CDK Stacks
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[5/7] Deploying CDK stacks (this may take 10-15 minutes)...${NC}"
cd "$WORKSPACE_ROOT/infra"
source .venv/bin/activate
# Set CDK to use the detected container runtime for Docker image assets
if [ "$CONTAINER_RUNTIME" = "finch" ]; then
export CDK_DOCKER="finch"
fi
cdk deploy --all --require-approval never $AWS_PROFILE_FLAG --outputs-file "$WORKSPACE_ROOT/cdk-outputs.json" 2>&1 | while IFS= read -r line; do
if [[ "$line" == *"✅"* ]] || [[ "$line" == *"Stack"* ]]; then
echo " $line"
fi
done
deactivate
echo -e "${GREEN} ✓ All CDK stacks deployed${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 6: Get Outputs
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[6/7] Retrieving deployment outputs...${NC}"
# Try to get CloudFront URL from CDK outputs
FRONTEND_URL=""
API_URL=""
if [ -f "$WORKSPACE_ROOT/cdk-outputs.json" ]; then
FRONTEND_URL=$(python3 -c "
import json
with open('$WORKSPACE_ROOT/cdk-outputs.json') as f:
outputs = json.load(f)
for stack, values in outputs.items():
for key, val in values.items():
if 'FrontendUrl' in key or 'frontend' in key.lower():
print(val)
break
" 2>/dev/null || echo "")
API_URL=$(python3 -c "
import json
with open('$WORKSPACE_ROOT/cdk-outputs.json') as f:
outputs = json.load(f)
for stack, values in outputs.items():
for key, val in values.items():
if 'ApiUrl' in key or 'ApiEndpoint' in key:
print(val)
break
" 2>/dev/null || echo "")
fi
# Fallback: query CloudFormation directly
if [ -z "$FRONTEND_URL" ]; then
FRONTEND_URL=$(aws cloudformation describe-stacks $AWS_PROFILE_FLAG \
--stack-name claim-processing-frontend \
--query 'Stacks[0].Outputs[?contains(OutputKey,`FrontendUrl`)].OutputValue' \
--output text 2>/dev/null || echo "")
fi
if [ -z "$FRONTEND_URL" ]; then
# Try to get CloudFront distribution domain
FRONTEND_URL=$(aws cloudfront list-distributions $AWS_PROFILE_FLAG \
--query "DistributionList.Items[?Comment=='Claim Processing - Frontend SPA'].DomainName" \
--output text 2>/dev/null || echo "")
if [ -n "$FRONTEND_URL" ]; then
FRONTEND_URL="https://$FRONTEND_URL"
fi
fi
if [ -z "$API_URL" ]; then
API_URL=$(aws cloudformation describe-stacks $AWS_PROFILE_FLAG \
--stack-name claim-processing-api-gateway \
--query 'Stacks[0].Outputs[?contains(OutputKey,`ApiUrl`)].OutputValue' \
--output text 2>/dev/null || echo "")
fi
echo -e "${GREEN} ✓ Outputs retrieved${NC}"
echo ""
# ─────────────────────────────────────────────────
# Step 7: Summary
# ─────────────────────────────────────────────────
echo -e "${YELLOW}[7/7] Deployment complete!${NC}"
echo ""
echo "=============================================="
echo -e "${GREEN} ✅ DEPLOYMENT SUCCESSFUL${NC}"
echo "=============================================="
echo ""
if [ -n "$FRONTEND_URL" ]; then
echo -e " 🌐 ${GREEN}Frontend URL:${NC} $FRONTEND_URL"
else
echo -e " 🌐 ${YELLOW}Frontend URL:${NC} Check AWS Console → CloudFront → Distributions"
fi
if [ -n "$API_URL" ]; then
echo -e " 🔗 ${GREEN}API URL:${NC} $API_URL"
else
echo -e " 🔗 ${YELLOW}API URL:${NC} Check AWS Console → API Gateway"
fi
echo ""
echo " 📋 Services deployed:"
for service in "${SERVICES[@]}"; do
echo " • $service"
done
echo ""
echo " 📖 Next steps:"
echo " 1. Open the Frontend URL in your browser"
echo " 2. Register a new account"
echo " 3. File your first insurance claim!"
echo ""
echo "=============================================="