forked from rabbitmq/rabbitmq-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·72 lines (59 loc) · 1.48 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
#!/usr/bin/env bash
set -e
REMOTE_HOST="$1"
VERSION="${2:-www}"
ENVIRONMENTS=(
Production:rabbit-web.vpc.pivotal.io
Staging:rabbit-web-stage.haas-40.pez.pivotal.io
)
main() {
debug
select_environment
ensure_deploying_live_to_production
deploy
}
debug() {
[ -z "$DEBUG" ] || set -x
}
select_environment() {
if [ -z "$REMOTE_HOST" ]
then
echo "Which environment do you want to deploy to?"
select environment in "${ENVIRONMENTS[@]}"
do
ENVIRONMENT="$environment"
export ENVIRONMENT
REMOTE_HOST="${environment#*:}"
break
done
fi
}
ensure_deploying_live_to_production() {
if [[ "$ENVIRONMENT" =~ Production ]] && [[ "$(current_git_branch)" != "live" ]]
then
read -rp "Are you sure you want to deploy '$(current_git_branch)' to $ENVIRONMENT ? (y|n) " -n 1
echo
if ! [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Good answer, only 'live' should be deployed to production"
exit 1
fi
fi
}
current_git_branch() {
git rev-parse --abbrev-ref HEAD
}
deploy() {
TMP_DIR=/tmp/to_deploy_${VERSION}
show_commands_as_they_run
# shellcheck disable=SC2029
ssh "$REMOTE_HOST" mkdir -p "$TMP_DIR"
rsync -qcrz --delete --perms --chmod=a+rwX --exclude "*.pyc" --exclude "__pycache__" --exclude "release-notes/*.md" code conf site wordpress-theme "$REMOTE_HOST":"$TMP_DIR"
# shellcheck disable=SC2029
ssh -t "$REMOTE_HOST" sudo "$TMP_DIR/code/deploy-remote $VERSION"
}
show_commands_as_they_run() {
echo
set -x
}
main