forked from hotakasaito/step-elastic-beanstalk-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·122 lines (97 loc) · 3.9 KB
/
run.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
#!/bin/bash
set +e
cd $HOME
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_APP_NAME" ]
then
fail "Missing or empty option APP_NAME, please check wercker.yml"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_ENV_NAME" ]
then
fail "Missing or empty option ENV_NAME, please check wercker.yml"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_KEY" ]
then
fail "Missing or empty option KEY, please check wercker.yml"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_SECRET" ]
then
fail "Missing or empty option SECRET, please check wercker.yml"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_ARTIFACT" ]
then
fail "Missing or empty option ARTIFACT, please check wercker.yml"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_REGION" ]
then
warn "Missing or empty option REGION, defaulting to us-west-2"
WERCKER_ELASTIC_BEANSTALK_DEPLOY_REGION="us-west-2"
fi
if [ ! -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_PLATFORM" ]
then
warn "Missing or empty option PLATFORM, defaulting to '64bit Amazon Linux 2016.03 v2.1.3 running Docker 1.11.1'"
WERCKER_ELASTIC_BEANSTALK_DEPLOY_PLATFORM="64bit Amazon Linux 2016.03 v2.1.3 running Docker 1.11.1"
fi
if [ -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_DEBUG" ]
then
warn "Debug mode turned on, this can dump potentially dangerous information to log files."
fi
AWSEB_CREDENTIAL_FILE="$HOME/.elasticbeanstalk/aws_credential_file"
AWSEB_EB_CONFIG_FILE="$WERCKER_SOURCE_DIR/.elasticbeanstalk/config.yml"
export AWS_CREDENTIAL_FILE=$AWSEB_CREDENTIAL_FILE
export AWS_ACCESS_KEY_ID=$WERCKER_ELASTIC_BEANSTALK_DEPLOY_KEY
export AWS_SECRET_ACCESS_KEY=$WERCKER_ELASTIC_BEANSTALK_DEPLOY_SECRET
echo 'Synchronizing References in apt-get...'
sudo apt-get update
echo 'Installing pip...'
sudo apt-get install -y python-pip libpython-all-dev
echo 'Installing awscli...'
sudo pip install awsebcli==3.7.3
echo 'eb version show...'
eb --version
test -d "$WERCKER_SOURCE_DIR/.elasticbeanstalk/" || mkdir -p "$WERCKER_SOURCE_DIR/.elasticbeanstalk/" || fail "Unable to make directory."
debug "Change back to the source dir."
cd $WERCKER_SOURCE_DIR
debug "Setting up credentials..."
test -d $(dirname $AWSEB_CREDENTIAL_FILE) || mkdir $(dirname $AWSEB_CREDENTIAL_FILE)
cat <<EOT > $AWSEB_CREDENTIAL_FILE
AWSAccessKeyId=$WERCKER_ELASTIC_BEANSTALK_DEPLOY_KEY
AWSSecretKey=$WERCKER_ELASTIC_BEANSTALK_DEPLOY_SECRET
EOT
debug "Setting up eb config..."
cat <<EOF > $AWSEB_EB_CONFIG_FILE
branch-defaults:
default:
environment: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_ENV_NAME
$WERCKER_GIT_BRANCH:
environment: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_ENV_NAME
global:
application_name: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_APP_NAME
default_platform: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_PLATFORM
default_region: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_REGION
profile: null
artifact: $WERCKER_ELASTIC_BEANSTALK_DEPLOY_ARTIFACT
EOF
if [ -n "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_DEBUG" ]
then
debug "Dumping config file."
cat $AWSEB_CREDENTIAL_FILE
cat $AWSEB_EB_CONFIG_FILE
fi
debug "making eb using environment $WERCKER_ELASTIC_BEANSTALK_DEPLOY_ENV_NAME in $WERCKER_ELASTIC_BEANSTALK_DEPLOY_REGION"
/usr/local/bin/eb use --region $WERCKER_ELASTIC_BEANSTALK_DEPLOY_REGION $WERCKER_ELASTIC_BEANSTALK_DEPLOY_ENV_NAME || fail "EB is not working or is not set up correctly."
debug "Checking if eb exists and can connect."
/usr/local/bin/eb status || fail "EB is not working or is not set up correctly."
DEPLOY_LABEL="$WERCKER_GIT_BRANCH/$WERCKER_GIT_COMMIT"
DEPLOY_MESSAGE="wercker-deploy of commit: $DEPLOY_LABEL"
debug "Pushing to AWS eb servers version: $DEPLOY_LABEL"
if [ "true" = "$WERCKER_ELASTIC_BEANSTALK_DEPLOY_NOHUP" ];
then
nohup /usr/local/bin/eb deploy -m "$DEPLOY_MESSAGE" $WERCKER_ELASTIC_BEANSTALK_DEPLOY_OPTS &
else
/usr/local/bin/eb deploy -m "$DEPLOY_MESSAGE" $WERCKER_ELASTIC_BEANSTALK_DEPLOY_OPTS
fi
if [ $? -ne 0 ]
then
fail "unable to push to EB"
fi
success 'Successfully pushed to Amazon Elastic Beanstalk'