-
Notifications
You must be signed in to change notification settings - Fork 0
/
dupper.hjson
228 lines (208 loc) · 5.88 KB
/
dupper.hjson
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
{
ports:
[
"35729:35729", // live reload
"3000:3000", // mean stack
"9418:9418", // gut daemon
"2222:22", // ssh
"8080:8080" // node-inspector
],
env:
[
"NODE_ENV=development",
"PORT=3000"
],
dependencies:
[
{
name: "linux-dependencies",
cmd:
'''
apt-get -y install curl wget libfontconfig
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
apt-get -y install mongodb nodejs daemon
'''
},
{
name: "nodejs-dependencies",
cmd:
'''
npm install -g bower gulp node-inspector
cd $REPO_ROOT
npm install
''',
watch: "package.json"
},
{
name: "bower-dependencies",
cmd:
'''
cd $REPO_ROOT
bower install --allow-root
''',
watch: "bower.json"
},
{
name: "sync-dependencies",
cmd:
'''
apt-get -y install curl sudo inotify-tools openssh-server
curl -sSL https://get.dupper.co/dev/index | sh
'''
}
],
commands: {
start: [{
server:
'''
# Check Mogodb service and start if not running
service mongodb status > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
service mongodb start
fi
# Start Gulp as Daemon
PORT=3000 daemon --name="gulp" --output=gulp.out -F /var/run/gulp.pid -D $REPO_ROOT -X /usr/bin/gulp
echo "MEAN stack ..... [ STARTING ]"
# Check for Server start
timeout 20 bash -c -- "while true; do wget -q --retry-connrefused \
--waitretry=1 --read-timeout=20 --timeout=15 -t 0 --continue localhost:3000 >/dev/null 2>&1; \
if [ $? = 0 ]; then break; fi; sleep 2s; done"
# Report status
_exit_code=$?
if [[ $_exit_code -eq 0 ]]
then
echo -e "MEAN stack ..... [ STARTED ]"
else
echo -e "MEAN stack ..... [ TIMEOUT ]"
fi
# Pass Status to client
_export _exit_code
'''
},{
client:
'''
# Open browser on Mac if server started successfully.
if [[ $_exit_code -eq 0 ]]
then
os="$(uname -s)"
if [[ $os == "Darwin" ]]; then
echo -e "Opening Browser"
open http://$SERVER_IP:3000/
fi
fi
'''
}],
stop: [{
server:
'''
# Get group ID of Gulp daemon process
pgid=$(ps --no-headers -o pgid $(cat /var/run/gulp.pid))
pgid=$(echo $pgid | tr -d '[[:space:]]')
# Kill all group processes
pkill -1 -g $pgid
echo "MEAN stack ..... [ STOPPING ]"
# Check for termination and report status
timeout 5 bash -c -- "while true; do [ -f /var/run/gulp.pid ]; \
if [ $? -eq 0 ]; then break; fi; sleep 2s; done"
_exit_code=$?
if [[ $_exit_code -eq 0 ]]
then
echo -e "MEAN stack ..... [ STOPPED ]"
else
echo -e "MEAN stack ..... [ TIMEOUT ]"
fi
'''
}],
logs: [{
server:
'''
[ -f $REPO_ROOT/gulp.out ] && tail -n 1000 $REPO_ROOT/gulp.out
'''
}],
debug: [{
server:
'''
# Start debugger in background detached from terminal
[ -f /var/run/gulp.pid ]
exit_code=$?
_export exit_code
if [[ $exit_code -ne 0 ]]
then
echo "MEAN stack not running, start using below command:"
echo "Usage:"
echo " dupper exec $REPO_NAME start"
exit 1
fi
# Start debugger in background detached from terminal
daemon --name="node-inspector" --output=node-inspector.out -F /var/run/node-inspector.pid -D $REPO_ROOT -X /usr/bin/node \
/usr/bin/node-inspector -- --web-port=8080 --web-host=0.0.0.0
exit_code="$?"
_export exit_code
'''
},{
client:
'''
os="$(uname -s)"
if [[ $os == "Darwin" ]]; then
[ $exit_code -eq 0 ] && open http://$SERVER_IP:8080/
fi
'''
}],
sync: [{
server:
'''
if [ ! -f $HOME/.ssh/devenv ]
then
mkdir -p $HOME/.ssh
ssh-keygen -q -t rsa -N "" -f "$HOME/.ssh/devenv"
cat "$HOME/.ssh/devenv.pub" >> $HOME/.ssh/authorized_keys
fi
PRIVATEKEY="$(cat $HOME/.ssh/devenv)"
_export PRIVATEKEY
cp $REPO_ROOT/.gitignore $REPO_ROOT/.gutignore
ulimit -n 9999
service ssh status > /dev/null 2>&1
if [[ $? -ne 0 ]]
then
service ssh start
fi
'''
},{
client:
'''
_verbose=0
_path=""
while [ "$#" -gt 0 ]
do
opt="$1"
shift
case "$opt" in
--verbose|-v)
_verbose=1
;;
*)
if [[ -z $_path ]]
then
_path="$opt"
fi
;;
esac
done
if [[ $_path == "" ]]
then
echo "Usage: dupper exec $REPO_NAME devenv [--verbose | -v] PATH"
exit 1
fi
command -v "dev" > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
curl -sSL https://get.dupper.co/dev/index | sh
fi
mkdir -p $HOME/.ssh
echo "$PRIVATEKEY" > $HOME/.ssh/devenv
mkdir -p $_path
dev sync $([[ $_verbose -eq 1 ]] && echo "-v") -i $HOME/.ssh/devenv root@$SERVER_IP:2222:$REPO_ROOT $_path
'''
}]
}
}