-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
122 lines (100 loc) · 3.96 KB
/
Copy pathdeploy.sh
File metadata and controls
122 lines (100 loc) · 3.96 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
#!/bin/bash
# Customise the application deployment by modifying the variabels below.
# set -x
export APPNAME="changeme" #must be lowercase alphaonly.
export STACKTYPE="spring"
export S3BUCKET="changeme-$APPNAME"
export EC2KeyPairName="CHANGEME"
export DBPASSWORD="changeme" #18 digets alphanumerical
# Check for the basics, jq, aws, svn, access keys...
YUM_CMD=$(command -v yum)
APT_GET_CMD=$(command -v apt)
if [[ -n $YUM_CMD ]]; then
sudo yum install -y jq subversion awscli
elif [[ -n $APT_GET_CMD ]]; then
sudo apt-get install -y jq subversion awscli
else
echo "Could not install package."
exit 1
fi
if command -v jq >/dev/null 2>&1 ; then
echo "found: $(jq --version)"
else
if [[ -n $YUM_CMD ]]; then
sudo yum install -y jq
elif [[ -n $APT_GET_CMD ]]; then
sudo apt-get install -y jq
else
echo "Could not install jq."
exit 1
fi
fi
if command -v aws >/dev/null 2>&1 ; then
echo "found: $(aws --version)"
else
if [[ -n $YUM_CMD ]]; then
sudo yum install -y aws
elif [[ -n $APT_GET_CMD ]]; then
sudo apt-get install -y aws
else
echo "Could not install aws cli."
exit 1
fi
fi
if ! grep aws_access_key_id ~/.aws/credentials -q "aws_secret_access_key" ~/.aws/credentials
then echo "aws appears to be misconfigured, please run aws configure"
exit 0
fi
if ! grep aws_secret_access_key ~/.aws/credentials -q "aws_secret_access_key" ~/.aws/credentials
then echo "aws appears to be misconfigured, please run aws configure"
exit 0
fi
# Dynamic Vars, Don't change.
__FILENAME="$APPNAME.zip"
__SEEDURL="https://s3.amazonaws.com/$S3BUCKET/$__FILENAME"
__PIPELINEBUCKET="$(aws s3 ls | grep "$APPNAME-pipe" | cut -d ' ' -f3)"
export __FILENAME __SEEDURL __PIPELINEBUCKET
# The application specific pipeline bucket must not exist when deploying the app. Delete stack will not clean up S3. This will warn if a manuel delete is needed.
if [ "${#__PIPELINEBUCKET}" -gt 0 ]
then
echo "$__PIPELINEBUCKET"
echo "Error: Found a previous S3 bucket for Application: s3://$__PIPELINEBUCKET. Delete via console, or choose a new APPNAME."
else
echo "Deploying Application: $APPNAME"
# Start CLean.
[[ -f $__FILENAME ]] && rm $__FILENAME
[[ -d src ]] && rm -rf src
# Ensure buckets in place.
aws s3api create-bucket --bucket $S3BUCKET --acl public-read
# Move cloudformation templates, and reposource archive to S3.
aws s3 sync templates/ s3://$S3BUCKET --acl public-read
# Archive everything and upload to S3. This archive will be the base for the seedrepo.
zip -r $__FILENAME . > /dev/null
aws s3 cp $__FILENAME s3://$S3BUCKET --acl public-read
# Clean up again.
[[ -f $__FILENAME ]] && rm $__FILENAME
[[ -d src ]] && rm -rf src
# Deploy the Application.
echo "Please wait while the application deploys, Status can be seen from cloudformation console."
aws cloudformation deploy --template-file templates/deploy.yml --stack-name $APPNAME --capabilities CAPABILITY_NAMED_IAM --parameter-overrides \
StackType=$STACKTYPE \
EC2KeyPairName=$EC2KeyPairName \
DatabasePassword=$DBPASSWORD \
seedURL=$__SEEDURL \
TemplateBucket=$S3BUCKET
fi
SSHCloneURL=$(aws cloudformation describe-stacks --stack-name $APPNAME | jq .Stacks[].Outputs | jq -r '.[] | select(.OutputKey=="SSHCloneURL") | .OutputValue')
EnvironmentURL=$(aws cloudformation describe-stacks --stack-name $APPNAME | jq .Stacks[].Outputs | jq -r '.[] | select(.OutputKey=="EnvironmentURL") | .OutputValue')
echo "##########################"
echo "Customise your application"
echo "##########################"
echo ""
echo "SSHCloneURL: $SSHCloneURL"
echo ""
echo "Clone your new repo, modify buildspec, and commit your changes."
echo "########################################"
echo "Verify Code Pipeline / Elastic Beanstalk"
echo "########################################"
echo ""
echo "If your application built successfully, it should be auto deployed to Beanstalk. Use the environment URL to test."
echo "EnvironmentURL: $EnvironmentURL"