-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsimple-deploy.sh
executable file
·64 lines (50 loc) · 2.29 KB
/
simple-deploy.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
#!/bin/bash
set -e
# # the stack name must be unique enough
STACK_NAME="DifySimpleDeployStack"
ZIP_FILE_PATH="/tmp/dify-on-aws-files.zip"
echo "⏱️ Preparing CloudFormation stack $STACK_NAME..."
npm ci
npm run synth
aws cloudformation deploy --stack-name $STACK_NAME --template-file deploy.yaml --capabilities CAPABILITY_IAM
describeStack=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --output json)
bucketName=$(echo $describeStack | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "BucketName") | .OutputValue')
projectName=$(echo $describeStack | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "ProjectName") | .OutputValue')
progressUrlBase=$(echo $describeStack | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "ProgressUrlBase") | .OutputValue')
logGroupName=$(echo $describeStack | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "LogGroupName") | .OutputValue')
echo "Found S3 bucket: ${bucketName}, CodeBuild project: ${projectName}"
echo
echo "Preparation completed. Now proceed to deploy Dify on AWS."
echo yes
REPLY="no"
while [ "$REPLY" != "yes" ]
do
# prompt user to confirm if the configuration is ready
echo "Are you sure you want to deploy? Please check the configuration parameters in bin/cdk.ts."
read -p "If you are ready, type 'yes': " -r
echo
done
echo "⏱️ Staging files..."
# create archive of current files
rm -f "$ZIP_FILE_PATH"
git ls-files | xargs zip -q "$ZIP_FILE_PATH"
aws s3 cp "$ZIP_FILE_PATH" s3://${bucketName}/code.zip
echo "⏱️ Starting deployment..."
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..."
echo "You can check the progress here: $progressUrlBase/$buildId"
echo
echo "⏱️ Tailing logs from CloudWatch log group $logGroupName"
aws logs tail --follow $logGroupName --format short --since 30s
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"