-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paths3-deploy.sh
53 lines (45 loc) · 1.5 KB
/
s3-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
#!/bin/bash
set -e
# This file is passed evironment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
# APP_HOME=bamboo.build.working.directory and planName=bamboo.shortPlanName by Bamboo.
# The script itself is responsible for "deploying" the built content to an S3 bucket.
planName=$(echo "$planName" | tr '[:upper:]' '[:lower:]') # S3 bucket names can't have capital letters.
echo "plan name: ${planName}"
newBucket=False
if [ -z "$planName" ] || [ "$planName" = "dev portal" ]
then
echo "deploying production branch to production..."
bucket_name=dev.beanstream.com
else
echo "deploying branch to test..."
bucket_name="dev.beanstream.com.${planName}"
if aws s3 ls "s3://${bucket_name}" 2>&1 | grep -q 'NoSuchBucket'
then
echo "Bucket doesn't exist. Creating bucket $bucket_name"
newBucket=true
aws s3 mb "s3://${bucket_name}"
fi
fi
echo "Syncing to bucket: $bucket_name"
aws s3 sync --delete --exact-timestamps $APP_HOME/build s3://${bucket_name}
# S3 Bucket Policy
policy="{
\"Version\": \"2012-10-17\",
\"Statement\": [
{
\"Sid\": \"AddPerm\",
\"Effect\": \"Allow\",
\"Principal\": \"*\",
\"Action\": [
\"s3:GetObject\"
],
\"Resource\": \"arn:aws:s3:::${bucket_name}/*\"
}
]
}"
if [ "$newBucket" = true ]
then
echo "Enabling static website and adding bucket policy to $bucket_name"
aws s3 website "s3://${bucket_name}" --index-document index.html
aws s3api put-bucket-policy --bucket "${bucket_name}" --policy "${policy}"
fi