Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·88 lines (72 loc) · 2.38 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·88 lines (72 loc) · 2.38 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
#!/bin/bash
set -e
echo "Deploying Smart Note Organizer..."
echo ""
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is required but not installed"
echo "Install with: brew install jq (macOS) or apt-get install jq (Linux)"
exit 1
fi
# Deploy infrastructure
echo "Deploying AWS infrastructure..."
cd infra
CDK_OUTPUT=$(mktemp)
cdk deploy --require-approval never --outputs-file "$CDK_OUTPUT"
cd ..
echo ""
echo "Infrastructure deployed"
echo ""
# Parse outputs
if [ ! -f "$CDK_OUTPUT" ]; then
echo "Error: CDK outputs not found"
exit 1
fi
API_URL=$(jq -r '.[] | .ApiUrl' "$CDK_OUTPUT")
BUCKET_NAME=$(jq -r '.[] | .BucketName' "$CDK_OUTPUT")
FRONTEND_URL=$(jq -r '.[] | .FrontendUrl' "$CDK_OUTPUT")
COGNITO_URL=$(jq -r '.[] | .CognitoLoginUrl' "$CDK_OUTPUT")
CLIENT_ID=$(jq -r '.[] | .UserPoolClientId' "$CDK_OUTPUT")
DISTRIBUTION_ID=$(jq -r '.[] | .DistributionId' "$CDK_OUTPUT")
# Clean up temporary file
rm "$CDK_OUTPUT"
if [ "$API_URL" = "null" ] || [ "$BUCKET_NAME" = "null" ] || [ "$DISTRIBUTION_ID" = "null" ]; then
echo "Error: Could not read required values from CDK outputs"
exit 1
fi
echo "Configuration:"
echo " API URL: $API_URL"
echo " Frontend URL: $FRONTEND_URL"
echo " Cognito URL: $COGNITO_URL"
echo " Bucket: $BUCKET_NAME"
echo ""
# Update appsettings.json
APPSETTINGS_PATH="src/SmartNoteOrganizer.UI/wwwroot/appsettings.json"
echo "Updating $APPSETTINGS_PATH..."
jq --arg apiUrl "$API_URL" \
--arg cognitoUrl "$COGNITO_URL" \
--arg clientId "$CLIENT_ID" \
--arg appUrl "$FRONTEND_URL" \
'.Api.BaseUrl = $apiUrl | .Auth.CognitoUrl = $cognitoUrl | .Auth.ClientId = $clientId | .Auth.AppUrl = $appUrl' \
"$APPSETTINGS_PATH" > "$APPSETTINGS_PATH.tmp"
mv "$APPSETTINGS_PATH.tmp" "$APPSETTINGS_PATH"
echo "Configuration updated"
echo ""
# Build frontend
echo "Building Blazor WebAssembly app with AOT..."
cd src/SmartNoteOrganizer.UI
dotnet publish -c Release
# Upload to S3
echo ""
echo "Uploading to S3..."
aws s3 sync bin/Release/net10.0/publish/wwwroot/ s3://$BUCKET_NAME/ --delete
# Invalidate CloudFront cache
echo ""
echo "Invalidating CloudFront cache..."
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/*" --no-cli-pager
echo ""
echo "Deployment complete"
echo ""
echo "Access your app at: $FRONTEND_URL"
echo ""
echo "Note: CloudFront cache invalidation may take a few minutes to complete"