forked from aikar/timings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·84 lines (75 loc) · 1.63 KB
/
Copy pathdeploy
File metadata and controls
executable file
·84 lines (75 loc) · 1.63 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
#!/bin/bash
# Aikar timings deploy script
#install location for prod
prod="prod"
timestamp() {
date +"%F_%H.%M.%S"
}
backup="$(timestamp)"
c() {
if [ $2 ]; then
echo -e "\e[$1;$2m"
else
echo -e "\e[$1m"
fi
}
ce() {
echo -e "\e[m"
}
if [ ! -d ".git" ]; then
echo "Please run from dev checkout";
return 1;
fi
echo "$(c 32)You are in git branch$(ce)"
git branch || exit
echo
echo "$(c 32)Current branch:$(ce)"
echo
git log -n 1 | cat -
echo
echo "$(c 32)Current production:$(ce)"
echo
git log -n 1 production | cat -
echo
read -p "$(c 32) Are you sure you want to deploy this? Press $(c 1 33)y/n $(ce)" -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "$(c 1 31)Aborted$(ce)"
exit;
fi
echo "$(c 33)Resetting production branch to here..$(ce)"
(
git branch -f production || exit 1
git push origin production -f || exit 1
) || (
echo "$(c 1 31) Failed to push up to github$(ce)"
exit 1
) || exit
echo "$(c 33)Branched and pushed up to github$(ce)..$(ce)"
(
cd .. || exit 1
mkdir -p prod_backups || exit 1
cp -r $prod prod_backups/$backup || exit 1
) || (
echo "$(c 1 31) Failed to backup$(ce)"
exit 1
) || exit
echo "$(c 33)Backed up locally$(ce).."
(
cd ../$prod
git fetch origin || exit 1
git checkout production || exit 1
git branch -f production_backup || exit 1
git reset --hard origin/production || exit 1
git checkout production || exit 1
) || (
cd ..
echo "Moving to failed"
mkdir failed
mv $prod failed/$backup
echo "Copying backup"
cp -r prod_backups/$backup $prod || exit 1
echo "$(c 1 31) Something went wrong on rollout, restored backup"
exit 1
) || exit 1
echo "$(c 32)==== Production rollout complete ====$(ce)"