-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·107 lines (95 loc) · 2.48 KB
/
deploy.sh
File metadata and controls
executable file
·107 lines (95 loc) · 2.48 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# fail on error
set -e
#CONFIG
APP_NAME="webmonitor"
CURRENT_VERSION="$(mix run --eval 'IO.puts Mix.Project.config[:version]' | tail -1)"
SERVER_HOST="webmonitorhq.com"
SERVER_HOME="/opt/www/$APP_NAME"
SERVER_ROOT="/opt/www/$APP_NAME/app"
SERVER_TMP_FILENAME="$SERVER_HOME/$APP_NAME-$CURRENT_VERSION.tar.gz"
RELEASE_TAR="./rel/$APP_NAME/releases/$CURRENT_VERSION/$APP_NAME.tar.gz"
# helpers --------------------
run() {
echo "local: $@"
/bin/bash -c "$@"
}
build() {
# build the release
echo "building release for version $CURRENT_VERSION ..."
run "MIX_ENV=prod mix do clean, release.clean, compile, phoenix.digest, release"
}
init(){
# init code
echo "initializing remote code"
echo "implode release"
run "mix release.clean --implode --no-confirm"
build
echo "copying tarball"
run "scp ${RELEASE_TAR} ${APP_NAME}@${SERVER_HOST}:${SERVER_TMP_FILENAME}"
cat <<EOS | ssh -T "$APP_NAME@$SERVER_HOST" 'cat - > /tmp/deploy.sh; /bin/bash -l /tmp/deploy.sh'
#!/bin/bash
set -e # fail on first error
run() {
echo "remote: \$@"
/bin/bash -c "\$@"
}
# code that runs on the server
# create the app directory
run "mkdir -p $SERVER_ROOT"
# copy the first version of the code
cd $SERVER_ROOT
run "tar -xvf $SERVER_TMP_FILENAME"
# start the app
run "bin/$APP_NAME start"
# make sure it is up by running ping
run "bin/$APP_NAME ping"
EOS
# TODO: create the systemctl file
}
upgrade(){
build
# upgrade code
echo "upgrading remote code"
echo "copying tarball"
run "scp ${RELEASE_TAR} ${APP_NAME}@${SERVER_HOST}:${SERVER_TMP_FILENAME}"
echo "running the upgrade script"
cat <<EOS | ssh -T "$APP_NAME@$SERVER_HOST" 'cat - > /tmp/deploy.sh; /bin/bash -l /tmp/deploy.sh'
#!/bin/bash
set -e # fail on first error
run() {
echo "remote: \$@"
/bin/bash -c "\$@"
}
# code that runs on the server
# copy the first version of the code
run "mkdir -p $SERVER_ROOT/releases/$CURRENT_VERSION"
run "mv $SERVER_TMP_FILENAME $SERVER_ROOT/releases/$CURRENT_VERSION/$APP_NAME.tar.gz"
# start the app
cd $SERVER_ROOT
#run "source /opt/www/webmonitor/env && RELX_REPLACE_OS_VARS=true bin/$APP_NAME rpc Elixir.Release.Tasks migrate"
run "bin/$APP_NAME upgrade $CURRENT_VERSION"
run "bin/$APP_NAME reboot" # TODO: temporary fix
# make sure it is up by running ping
run "bin/$APP_NAME ping"
EOS
}
help(){
echo 'Elixir Deployer'
echo 'Usage:'
echo './deploy.sh init'
echo './deploy.sh upgrade'
}
case $1 in
init )
init
;;
upgrade )
upgrade
;;
help )
help
;;
* )
help
esac