-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathINIT_DEV.sh
executable file
·309 lines (267 loc) · 6.05 KB
/
INIT_DEV.sh
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/usr/bin/env bash
# ____ _ _ ____ ____ ____ ____ _ _
# (_ _)( \( )(_ _)(_ _) ( _ \( ___)( \/ )
# _)(_ ) ( _)(_ )( )(_) ))__) \ /
# (____)(_)\_)(____) (__) (____/(____) \/
#################InitDev.sh####################
## Variable Init
# Jsdoc
export JSDOC="./node_modules/jsdoc/jsdoc.js"
export JSDOCCONF="conf/jsdoc_conf.json"
# Pm2
export PM2="./node_modules/pm2/bin/pm2"
export PM2DEV="./node_modules/pm2/bin/pm2-dev"
# Mocha test suite
export MOCHA="./node_modules/mocha/bin/mocha"
export TESTM="./test/controllers/"
export TESTR="./test/routes"
export TESTS="./test/schemas/"
# Istanbul reporter
export NYC="./node_modules/nyc/bin/nyc.js"
# coin_board app
export APPCONF="./conf/webfront.pm2conf.json"
export WVSERV="webview.service"
export WSSERV="websocket.service"
export CBSERV="CoinBoardBot.service"
export SHOW="./node_modules/pm2/bin/pm2 start conf/webfront.pm2conf.json --only webview.service"
export LOG="./node_modules/pm2/bin/pm2 logs"
#External ressources
export TICKERURL="https://raw.githubusercontent.com/crypti/cryptocurrencies/master/"
export TICKER="cryptocurrencies.json"
#Color
BLD="\033[40m"
CL="\033[0m"
RD="\033[101m"
function usage ()
{
echo -e "
## $BLD COINBO4RD $CL devtool
$BLD Usage :$CL INIT_DEV [-c] [-d] [-r] [-t] [-h/-u]
-c:$BLD.Setup$CL your nodejs dev environnement$BLD**$CL
-d:$BLD.Generate$CL html doc with jsdoc
-o:$BLD.Launch docker$CL .onion service instance of app
-p:$BLD.Init$CL params and Cook your Dockerfile for first time
-rb:$BLD.Rebuild Dockerfile if alpine host
-r:$BLD.reset$CL database tmpdata and restart app in test mode
-s:$BLD.run$CL app with pm2 (production env)
-t:$BLD.run$CL app in dev mode (watch for file change)
-rl:$BLD.reload$CL app following changes (watch in pm2 is broken)
-lt:$BLD.test$CL app with mocha (test files in test/ dir)
-h:$BLD.show$CL this help text and exit
Notes : Accept only$BLD one$CL arg.
$BLD[-b]$CL options currently supported system are fedora / centos and
ubuntu / debian.
** : run only once
";
}
function nodesetup ()
{
echo "
* Let's deploy a Nodejs dev environnement *
Enter the install command for your favorite apt-get method :
"
read -r aptget && sudo "$aptget" "nodejs" "npm" && sudo npm install -g yarn && \
yarn install && cd "coin_board" && yarn install && mkdir tmpdata log &&
echo "
Et ...
Voila!
Tips : Please run this app with ./INIT_DEV.sh -rl development local
"
}
function app_initshop()
{
sudo adduser --system \
--shell /bin/bash \
--group --gecos "docker onion usr" \
fofo && \
sudo chown -R "fofo:$USER" conf/onion/kingdom && \
sudo chmod -R 700 conf/onion/kingdom && \
docker build -t beefonion:latest .
}
function app_alpinecooking()
{
sudo apk add paxctl && \
sudo paxctl -cm $(which node) && \
docker build -t beefonion:latest .
}
function app_startkitchen()
{
export NGLOG="$(pwd)/log/nginxlogs"
export KINGDOM="$(pwd)/conf/onion/kingdom"
export KVIEW="$KINGDOM/v"
export KSOCK="$KINGDOM/s"
export KALT="$KINGDOM/altsdom"
docker run -it --net host \
--name="beefDotonion" \
-v "$NLOG:/var/log/nginx" \
-v "$KVIEW:/var/lib/tor/hidnview" \
-v "$KSOCK:/var/lib/tor/hidnws" \
-v "$KALT:/var/lib/tor/altd" \
coinboardonionservice/deployhiddenservice:latest bash
}
function app_cleankitchen()
{
echo 'CleanKitchen : Removing all volumes'
docker volume rm $(docker volume ls -qf dangling=true)
echo 'CleanKitchen : Removing all orphaned images'
docker rmi $(docker images | grep '^<none>' | awk '{print $3}')
}
function app_startDev ()
{
export NODE_ENV="$1"
export SERV_ENV="$2"
#Init random key gen for uid
echo 'RANDOM' > log.txt;
# order matters !
mongod -f conf/mongodb.conf &
"$PM2" start "$APPCONF" --only "$WSSERV" --update-env;
"$PM2" start "$APPCONF" --only "$WVSERV" --update-env;
"$PM2" start "$APPCONF" --only "$CBSERV" --update-env;
}
function app_startStaging ()
{
export NODE_ENV="$1"
export SERV_ENV="$2"
#Init random key gen for uid
echo 'RANDOM' > log.txt;
if [[ "$APP" == "view" ]];
then pm2 start "$APPCONF" --only "$WVSERV" --update-env;
fi
if [[ "$APP" == "ws" ]];
then
pm2 start "$APPCONF" --only "$WSSERV" --update-env;
mkdir -p DTAFOOD/prices DTAFOOD/infos;
fi
pm2 logs
}
function reset_db ()
{
rm -rf tmpdata && mkdir tmpdata
wget "$TICKERURL/$TICKER" \
-O "tmpdata/$TICKER" && app_startDev
}
function app_kill ()
{
"$PM2" kill
killall -9 mongod;
}
function app_reload ()
{
app_kill; app_startDev "$1" "$2"
}
# Note the test order, register_route-test is first cause it create
# the 'mockuser' entry in unittests db before other test
function app_tests ()
{
NODE_ENV='development'
TEST='ok'
MONGO='mongodb://localhost:27017/unittests'
mongod -f conf/mongodb.conf &
mongo < test/before_db.js
"$NYC" --reporter=lcov "$MOCHA" \
"$TESTM" \
"$TESTR/register_route-test.js" "$TESTR/login_route-test.js" \
"$TESTR/index_route-test.js" "$TESTR/profile_route-test.js" \
"$TESTR/datajunk_route-test.js" \
"$TESTS" \
--exit
"$NYC" report
}
function genddoc ()
{
rm -rf ~/Downloads/docs
"$JSDOC" -c "$JSDOCCONF";
echo -e "
** Documentation generation ok !
(logs on jsdoc.log)
Please open your favorite web browser to$BLD doc/index.html$CL
"
mv docs ~/Downloads/
}
### Scrit init
# exit if failure
set +e
while [[ $# -gt 0 ]]
do
case "n$1" in
'n-h')
usage
exit 0
;;
'n-u')
usage
exit 0
;;
'n-b')
dbsetup
exit 0
;;
'n-c')
set +e;
nodesetup
exit 0
;;
'n-gd')
genddoc
exit 0
;;
'n-o')
app_startkitchen
exit 0
;;
'n-p')
app_initshop
exit 0
;;
'n-r')
reset_db
exit 0
;;
'n-l')
$LOG
exit 0;
;;
'n-s')
$SHOW
exit 0
;;
'n-t')
app_startDev "$2" "$3"
exit 0
;;
'n-k')
app_kill
exit 0
;;
'n-ck')
app_cleankitchen
exit 0
;;
'n-rb')
app_alpinecooking
exit 0
;;
'n-rl')
app_reload "$2" "$3"
exit 0
;;
'n-lt')
app_tests
exit 0
;;
'n-staging')
app_startStaging "$2" "$3"
exit 0
;;
*)
echo "$0 : unkown [$1] arg given (see usage)"
exit 1
;;
esac
echo -e "\n\tDone !\n"
shift
done
echo "
Missing args, see -h or -u for usage
"
exit 1