-
Notifications
You must be signed in to change notification settings - Fork 36
/
deploy
executable file
·90 lines (80 loc) · 2.02 KB
/
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
#!/bin/bash
# Aikar timings deploy script
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 -a production prod_backups/$backup || exit 1
echo "$(c 33)Backed up locally to$(ce) prod_backups/$backup"
ln -sfn prod_backups/$backup prod
) || (
echo "$(c 1 31) Failed to backup$(ce)"
exit 1
) || exit
(
git checkout production || exit 1
echo "$(c 33)Updating Dependencies$(ce)"
yarn install || exit 1
echo "$(c 33)Building$(ce)"
node_modules/.bin/gulp build:release || exit 1
echo "$(c 33)Done! Let's launch it.$(ce)"
rm -rf ../production || exit 1
echo "$(c 33)Copying$(ce)"
cp -a . ../production || exit 1
echo "$(c 33)Restoring production configuration$(ce)"
cp ../prod_backups/$backup/config.dev.ini ../production/ || exit 1
rm -f ../production/.git # remove .git reference so its not linked to dev
git checkout master
cd ../
echo "$(c 33)Restoring Symlink to new production$(ce)"
ln -sfn production prod || exit 1
) || (
echo "$(c 1 31) Building failed! Leaving symlink at$(ce) prod_backups/$backup"
exit 1
) || exit 1
echo "$(c 32)==== Production rollout complete ====$(ce)"
#rebuild dev
node_modules/.bin/gulp build || echo "Dev rebuild failed"