-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathautomata
executable file
·110 lines (93 loc) · 2.61 KB
/
automata
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
#!/bin/bash
APP="elyxel"
REMOTE_USER="root"
SERVER="alpha"
BUILD_DIR="/srv/build/${APP}"
DEPLOY_DIR="/srv/current/${APP}"
############
VERSION=`awk '/version: \"(.*)\"/{ print $2 }' ./mix.exs | cut -d '"' -f2`
deploy() {
echo -e "Deploying Version ${VERSION}\n"
### Clean
echo -e "--> Cleaning local source tree\n"
mix clean
rm -rf priv/images
rm -rf priv/static/*
# ... add any other files here you feel should be removed
### Copy current code
echo -e "--> Uploading sources\n"
rsync -azq --exclude='.git/' --exclude="_build/" --exclude="deps/" --exclude="app/node_modules" ./ ${REMOTE_USER}@${SERVER}:${BUILD_DIR}
### Build on remote
echo -e "--> Building on remote\n"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && mix deps.get --only prod"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && MIX_ENV=prod mix compile"
echo -e "--> Compiling assets on remote\n"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR}/app && npm install"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && brunch build --production"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && MIX_ENV=prod mix phoenix.digest"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && MIX_ENV=prod mix release"
echo -e "--> Moving release to deployment dir\n"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && cp -R rel/${APP}/releases/${VERSION}/${APP}.tar.gz ${DEPLOY_DIR}"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && tar -xf ${APP}.tar.gz"
}
migrate() {
echo -e "--> Running migrations\n"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${BUILD_DIR} && MIX_ENV=prod mix ecto.migrate"
}
upgrade() {
echo -e "Upgrading to version ${VERSION}\n"
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && bin/${APP} upgrade ${VERSION}"
}
downgrade() {
echo -e "Not yet implemented"
}
start() {
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && bin/${APP} start"
}
stop() {
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && bin/${APP} stop"
}
restart() {
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && bin/${APP} restart"
}
console() {
ssh ${REMOTE_USER}@${SERVER} -- "cd ${DEPLOY_DIR} && bin/${APP} remote_console"
}
clean() {
echo -e "--> Cleaning build dir on remote\n"
ssh ${REMOTE_USER}@${SERVER} -- "rm -rf ${BUILD_DIR}/*"
}
case "$1" in
deploy)
deploy
;;
migrate)
migrate
;;
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
upgrade)
upgrade
;;
downgrade)
downgrade
;;
console)
console
;;
clean)
clean
;;
*)
echo "Usage: $0 {deploy|migrate|upgrade|downgrade|stop|start|restart|clean}" >&2
exit 1
;;
esac