-
Notifications
You must be signed in to change notification settings - Fork 35
/
jenkins-mobius-build.sh
63 lines (52 loc) · 1.76 KB
/
jenkins-mobius-build.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
#!/bin/bash
set -e
docker pull ubuntu:14.04
file="Dockerrun.aws.json"
tag="master-${BUILD_NUMBER}"
repo="staffjoy/mobius"
s3Bucket="staffjoy-deploy"
s3Path="mobius/$tag/"
s3Key="$s3Path$file"
# Add version
sed -i "s/TAG/$tag/" $file
docker build -t $repo:$tag .
# Run tests
docker run -t $repo:$tag /bin/bash -c 'cd /src/ && make test'
docker push $repo:$tag
# Add the Dockerrun to S3 so that beanstalk can access it
aws s3 cp $file s3://$s3Bucket/$s3Path
# Create version
aws elasticbeanstalk create-application-version \
--application-name staffjoy-mobius \
--version-label "$tag" \
--source-bundle "{\"S3Bucket\":\"$s3Bucket\",\"S3Key\":\"$s3Key\"}"
# Deploy to stage
aws elasticbeanstalk update-environment \
--environment-name "mobius-stage" \
--version-label "$tag"
# Polling to see whether deploy is done
deploystart=$(date +%s)
timeout=1000 # Seconds to wait before error
threshhold=$((deploystart + timeout))
while true; do
# Check for timeout
timenow=$(date +%s)
if [[ "$timenow" > "$threshhold" ]]; then
echo "Timeout - $timeout seconds elapsed"
exit 1
fi
# See what's deployed
version=`aws elasticbeanstalk describe-environments --application-name "staffjoy-mobius" --environment-name "mobius-stage" --query "Environments[*].VersionLabel" --output text`
status=`aws elasticbeanstalk describe-environments --application-name "staffjoy-mobius" --environment-name "mobius-stage" --query "Environments[*].Status" --output text`
if [ "$version" != "$tag" ]; then
echo "Tag not updated (currently $version). Waiting."
sleep 10
continue
fi
if [ "$status" != "Ready" ]; then
echo "System not Ready -it's $status. Waiting."
sleep 10
continue
fi
break
done