forked from aws-samples/bedrock-claude-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.sh
executable file
·141 lines (124 loc) · 4.85 KB
/
bin.sh
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
#!/bin/bash
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! !!!"
echo "!!! IMPORTANT NOTICE !!!"
echo "!!! !!!"
echo "!!! If you are using Bedrock Claude Chat with a version prior to v1.x !!!"
echo "!!! (e.g., v0.4.x), please follow the migration guide before proceeding. !!!"
echo "!!! !!!"
echo "!!! Migrating from an older version requires specific steps to ensure !!!"
echo "!!! your data is properly preserved and migrated. Failure to follow !!!"
echo "!!! the migration guide may result in DATA LOSS. !!!"
echo "!!! !!!"
echo "!!! Please refer to the migration guide at: !!!"
echo "!!! https://github.com/aws-samples/bedrock-claude-chat/blob/v1/docs/migration/V0_TO_V1.md !!!"
echo "!!! !!!"
echo "!!! If you are a new user or already using v1.x, !!!"
echo "!!! you can safely proceed with the installation. !!!"
echo "!!! !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
while true; do
read -p "Are you a new user starting with v1.x or later? (y/N): " answer
case ${answer:0:1} in
y|Y )
echo "Starting deployment..."
break
;;
n|N )
echo "This script is intended for new users or v1.x user only. If you are using previous version, please refer migration guide."
exit 1
;;
* )
echo "Please enter y or n."
;;
esac
done
# Default parameters
ALLOW_SELF_REGISTER="true"
IPV4_RANGES=""
IPV6_RANGES=""
DISABLE_IPV6="false"
ALLOWED_SIGN_UP_EMAIL_DOMAINS=""
BEDROCK_REGION="ap-southeast-2"
VERSION="v1"
# Parse command-line arguments for customization
while [[ "$#" -gt 0 ]]; do
case $1 in
--disable-self-register) ALLOW_SELF_REGISTER="false" ;;
--disable-ipv6) DISABLE_IPV6="true" ;;
--ipv4-ranges) IPV4_RANGES="$2"; shift ;;
--ipv6-ranges) IPV6_RANGES="$2"; shift ;;
--bedrock-region) BEDROCK_REGION="$2"; shift ;;
--allowed-signup-email-domains) ALLOWED_SIGN_UP_EMAIL_DOMAINS="$2"; shift ;;
--version) VERSION="$2"; shift ;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
shift
done
# Validate the template
aws cloudformation validate-template --template-body file://deploy.yml > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Template validation failed"
exit 1
fi
StackName="CodeBuildForDeploy"
# Deploy the CloudFormation stack
aws cloudformation deploy \
--stack-name $StackName \
--template-file deploy.yml \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
AllowSelfRegister=$ALLOW_SELF_REGISTER \
DisableIpv6=$DISABLE_IPV6 \
Ipv4Ranges="$IPV4_RANGES" \
Ipv6Ranges="$IPV6_RANGES" \
AllowedSignUpEmailDomains="$ALLOWED_SIGN_UP_EMAIL_DOMAINS" \
BedrockRegion="$BEDROCK_REGION" \
Version="$VERSION"
echo "Waiting for the stack creation to complete..."
echo "NOTE: this stack contains CodeBuild project which will be used for cdk deploy."
spin='-\|/'
i=0
while true; do
status=$(aws cloudformation describe-stacks --stack-name $StackName --query 'Stacks[0].StackStatus' --output text 2>/dev/null)
if [[ "$status" == "CREATE_COMPLETE" || "$status" == "UPDATE_COMPLETE" || "$status" == "DELETE_COMPLETE" ]]; then
break
elif [[ "$status" == "ROLLBACK_COMPLETE" || "$status" == "DELETE_FAILED" || "$status" == "CREATE_FAILED" ]]; then
echo "Stack creation failed with status: $status"
exit 1
fi
printf "\r${spin:i++%${#spin}:1}"
sleep 1
done
echo -e "\nDone.\n"
outputs=$(aws cloudformation describe-stacks --stack-name $StackName --query 'Stacks[0].Outputs')
projectName=$(echo $outputs | jq -r '.[] | select(.OutputKey=="ProjectName").OutputValue')
if [[ -z "$projectName" ]]; then
echo "Failed to retrieve the CodeBuild project name"
exit 1
fi
echo "Starting CodeBuild project: $projectName..."
buildId=$(aws codebuild start-build --project-name $projectName --query 'build.id' --output text)
if [[ -z "$buildId" ]]; then
echo "Failed to start CodeBuild project"
exit 1
fi
echo "Waiting for the CodeBuild project to complete..."
while true; do
buildStatus=$(aws codebuild batch-get-builds --ids $buildId --query 'builds[0].buildStatus' --output text)
if [[ "$buildStatus" == "SUCCEEDED" || "$buildStatus" == "FAILED" || "$buildStatus" == "STOPPED" ]]; then
break
fi
sleep 10
done
echo "CodeBuild project completed with status: $buildStatus"
buildDetail=$(aws codebuild batch-get-builds --ids $buildId --query 'builds[0].logs.{groupName: groupName, streamName: streamName}' --output json)
logGroupName=$(echo $buildDetail | jq -r '.groupName')
logStreamName=$(echo $buildDetail | jq -r '.streamName')
echo "Build Log Group Name: $logGroupName"
echo "Build Log Stream Name: $logStreamName"
echo "Fetch CDK deployment logs..."
logs=$(aws logs get-log-events --log-group-name $logGroupName --log-stream-name $logStreamName)
frontendUrl=$(echo "$logs" | grep -o 'FrontendURL = [^ ]*' | cut -d' ' -f3 | tr -d '\n,')
echo "Frontend URL: $frontendUrl"