-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate-deploy
executable file
·121 lines (109 loc) · 3.88 KB
/
update-deploy
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
#!/bin/bash
readonly DEPLOYCONFIGFILE=config/deploy.yml
readonly COMPOSERLOCATION=/usr/local/composer/composer.phar
# A simple bash script to update and deploy a site.
# Runs `composer update` and `bundle update`, then pushes the changes to master.
# Finally it deploys master to preview, acceptance and production (if available).
# Created by Michiel Verkoijen on 2015-10-30
# Filename: ~/update-deploy
# Check if deploy.yaml can be found otherwise exit immediately.
if [ ! -f $DEPLOYCONFIGFILE ]; then
echo "`tput setaf 1`Warning: Deploy file $DEPLOYCONFIGFILE not found`tput setaf 7`"
tput op
echo "Please make sure you are running this script from the right location and try again."
exit
fi
# YAML parser from https://gist.github.com/epiloque/8cf512c6d64641bde388
parse_yaml() {
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_]*'
fs="$(echo @|tr @ '\034')"
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
awk -F"$fs" '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
}
}' | sed 's/_=/+=/g'
}
echo "Parsing your deploy.yml file..."
eval $(parse_yaml $DEPLOYCONFIGFILE "deploy_")
if [ -z ${deploy_production_domain+x} ]; then
echo "`tput setaf 1`Warning: Cannot determine production server from deploy.yml file.`tput setaf 7`"
tput op
echo "Script stopped prematurely."
exit
else
readonly PRODUCTIONSERVER=$deploy_production_domain
fi
if ping -c1 -W1 $PRODUCTIONSERVER &> /dev/null; then
echo "`tput setaf 2`Production server ($PRODUCTIONSERVER) can be reached`tput setaf 7`"
tput op
else
echo "`tput setaf 1`Warning: production server ($PRODUCTIONSERVER) cannot be reached`tput setaf 7`"
tput op
echo "Script terminated prematurely!"
exit;
fi
git pull origin master
bundle update
php $COMPOSERLOCATION update --no-dev
read -p "Continue to commit, push and deploy? " -n 1
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "Updates made. Nothing committed, pushed or deployed"
exit 1
else
echo ""
echo "Push changes for this Git repository"
git add -A
git commit -a -m "Bundle and composer updates."
git push origin master
fi
# Deploy to preview if we can determine the server and connect to it
if [ -z ${deploy_preview_domain+x} ]; then
echo "`tput setaf 1`Warning: Cannot determine preview server from deploy.yml file.`tput setaf 7`"
tput op
else
readonly PREVIEWSERVER=$deploy_preview_domain
if ping -c1 -W1 $PREVIEWSERVER &> /dev/null; then
echo "`tput setaf 2`Deploy to preview server ($PREVIEWSERVER)`tput setaf 7`"
tput op
vd deploy preview
else
echo "`tput setaf 1`Preview server ($PREVIEWSERVER) is down`tput setaf 7`"
tput op
fi
fi
# Deploy to acceptance if we can determine the server and connect to it
if [ -z ${deploy_acceptance_domain+x} ]; then
echo "`tput setaf 1`Warning: Cannot determine acceptance server from deploy.yml file.`tput setaf 7`"
tput op
else
readonly ACCEPTANCESERVER=$deploy_acceptance_domain
if ping -c1 -W1 $ACCEPTANCESERVER &> /dev/null; then
echo "`tput setaf 2`Deploy to acceptance server ($ACCEPTANCESERVER)`tput setaf 7`"
tput op
vd deploy acceptance
else
echo "`tput setaf 1`Acceptance server ($ACCEPTANCESERVER) is down`tput setaf 7`"
tput op
fi
fi
# Deploy to production if we can connect to it (double check just to be sure)
if ping -c1 -W1 $PRODUCTIONSERVER &> /dev/null; then
echo "`tput setaf 2`Deploy to production server ($PRODUCTIONSERVER)`tput setaf 7`"
tput op
vd deploy production
else
echo "`tput setaf 1`Production server ($PRODUCTIONSERVER) is down`tput setaf 7`"
tput op
fi