-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·519 lines (386 loc) · 11.7 KB
/
install.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/bash
BASE_PATH=$(dirname "${BASH_SOURCE}")
BASE_PATH=$(cd "${BASE_PATH}"; pwd)
# turn on extglob
shopt -s extglob
cmdname=$(basename $0)
echoerr() { echo "$@" 1>&2; }
usage() {
cat << USAGE >&2
Usage:
$cmdname <component>
-d | --dev
Development mode installation; install master branch of all repos instead
of official releases
-r RELEASE | --release=RELEASE
Release tag to use for installation; without this option specified, a list
of releases will be printed and the installation stops
-k GIT_OAUTH_TOKEN | --token=GIT_OAUTH_TOKEN
OAuth token to use to authenticate
-h | --help Print help
-t | --test Install test HySDS component, e.g. $HOME/mozart-test instead of $HOME/mozart
COMPONENT <component>: mozart | grq | metrics | verdi
USAGE
exit 1
}
link_repo() {
cd $1
PACKAGE=$2
PACKAGE_DIR=${PACKAGE}-*
ln -sf $PACKAGE_DIR $PACKAGE
}
install_repo() {
cd $1
PACKAGE=$2
PACKAGE_DIR=${PACKAGE}-*
link_repo $1 $2
cd $OPS/$PACKAGE
pip install -e .
if [ "$?" -ne 0 ]; then
echo "Failed to run 'pip install -e .' for $PACKAGE."
exit 1
fi
}
clone_dev_repo() {
cd $1
PACKAGE=$2
GIT_URL=$3
BRANCH=$4
if [ ! -z ${BRANCH} ]; then
git clone --single-branch -b $BRANCH $GIT_URL $PACKAGE
else
git clone $GIT_URL $PACKAGE
fi
if [ "$?" -ne 0 ]; then
echo "Failed to clone $GIT_URL."
exit 1
fi
}
install_dev_repo() {
cd $1
PACKAGE=$2
GIT_URL=$3
BRANCH=$4
if [ ! -z ${BRANCH} ]; then
clone_dev_repo $1 $PACKAGE $GIT_URL $BRANCH
else
clone_dev_repo $1 $PACKAGE $GIT_URL
fi
cd $OPS/$PACKAGE
pip install -e .
if [ "$?" -ne 0 ]; then
echo "Failed to run 'pip install -e .' for $PACKAGE."
exit 1
fi
}
install_hysds_ui() {
OPS=$1
PACKAGE=$2
cd $OPS/$PACKAGE
npm install --silent
if [ "$?" -ne 0 ]; then
echo "Failed to run 'npm install --silent' for $PACKAGE."
exit 1
fi
}
move_and_link_repo() {
cd $1
PACKAGE=$2
NEW_DIR=$3
PACKAGE_DIR=${PACKAGE}-*
mv $PACKAGE_DIR $NEW_DIR/
cd $NEW_DIR
ln -sf $PACKAGE_DIR $PACKAGE
}
# unset environment variables
unset DIR_POST
unset DEV
unset RELEASE
unset GIT_OAUTH_TOKEN
# process arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--help|-h)
usage
shift 1
;;
--test|-t)
DIR_POST="-test"
shift 1
;;
-d)
DEV=1
shift 1
;;
--dev)
DEV=1
shift 1
;;
-r)
RELEASE="$2"
if [[ $RELEASE == "" ]]; then break; fi
shift 2
;;
--release=*)
RELEASE="${1#*=}"
shift 1
;;
-k)
GIT_OAUTH_TOKEN="$2"
if [[ $GIT_OAUTH_TOKEN == "" ]]; then break; fi
shift 2
;;
--token=*)
GIT_OAUTH_TOKEN="${1#*=}"
shift 1
;;
mozart|metrics|verdi)
COMPONENT="$1"
HYSDS_DIR="$1"
shift 1
;;
grq)
COMPONENT="$1"
HYSDS_DIR="sciflo"
shift 1
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
# check if both -d and -r were specified
if [ ! -z ${DEV+x} ] && [ ! -z ${RELEASE+x} ]; then
echoerr "Error: Cannot specify -r/--release and -d/--dev options together."
usage
fi
# check component is defined
if [[ "$COMPONENT" == "" ]]; then
echoerr "Error: you need to provide the HySDS component."
usage
fi
# installation dir for HySDS
INSTALL_DIR=$HOME/${HYSDS_DIR}${DIR_POST}
echo "HySDS install directory set to $INSTALL_DIR"
# source bash profile to ensure virtualenv is found
if [ -e "$HOME/.bash_profile" ]; then
source $HOME/.bash_profile
fi
# create virtualenv if not found
# Specify --no-setuptools option to create virtual environment without installing
# setuptools in the event we have to pin to a specific version
if [ ! -e "$INSTALL_DIR/bin/activate" ]; then
virtualenv --system-site-packages $INSTALL_DIR
echo "Created virtualenv at $INSTALL_DIR."
fi
# source virtualenv
source $INSTALL_DIR/bin/activate
# Combining installs in case we have to pin setuptools in the future
pip install -U pip setuptools
# Need to install backoff due to download_assets needing it
pip install backoff
# to force re-install of dependencies, use --ignore-installed
if [ ! -e "$INSTALL_DIR/bin/supervisord" ]; then
pip install supervisor
fi
# create etc directory
if [ ! -d "$INSTALL_DIR/etc" ]; then
mkdir $INSTALL_DIR/etc
fi
# create log directory
if [ ! -d "$INSTALL_DIR/log" ]; then
mkdir $INSTALL_DIR/log
fi
# create run directory
if [ ! -d "$INSTALL_DIR/run" ]; then
mkdir $INSTALL_DIR/run
fi
# set github API urls
if [[ "$GIT_OAUTH_TOKEN" == "" ]]; then
GIT_URL="https://github.com"
API_URL="https://api.github.com"
else
GIT_URL="https://${GIT_OAUTH_TOKEN}@github.com"
API_URL="https://${GIT_OAUTH_TOKEN}@api.github.com"
fi
# set hysds-framework API url
REL_API_URL="${API_URL}/repos/hysds/hysds-framework/releases"
# get all releases
declare -A rels
for i in `${BASE_PATH}/query_releases.py $REL_API_URL`; do
rel_id=`echo $i | awk 'BEGIN{FS="|"}{print $1}'`
rel_tag=`echo $i | awk 'BEGIN{FS="|"}{print $2}'`
rels[$rel_tag]+=$rel_id
done
# print release if not specified
if [ -z ${DEV+x} ] && [ -z ${RELEASE+x} ]; then
echo "No release specified or development mode not set."
echo "Use -d | --dev to install development mode or use -r RELEASE | --release=RELEASE"
echo "to install a specific release. Listing available releases:"
for tag in "${!rels[@]}"; do
echo "$tag"
done | sort
exit 0
fi
# create ops directory
OPS="$INSTALL_DIR/ops"
if [ ! -d "$OPS" ]; then
mkdir $OPS
fi
cd $OPS
# install dev environment
if [[ "$DEV" == 1 ]]; then
# clone prov_es package
install_dev_repo $OPS prov_es https://github.com/hysds/prov_es.git
# clone osaka package
pip install -U pyasn1
pip install -U pyasn1-modules
pip install -U python-dateutil
install_dev_repo $OPS osaka https://github.com/hysds/osaka.git
# clone hysds_commons package
install_dev_repo $OPS hysds_commons https://github.com/hysds/hysds_commons.git
# clone hysds package
cd $OPS
PACKAGE=hysds
clone_dev_repo $OPS $PACKAGE https://github.com/hysds/hysds.git
cd $OPS/$PACKAGE
pip install -e .
if [ "$?" -ne 0 ]; then
echo "Failed to run 'pip install -e .' for $PACKAGE."
exit 1
fi
# clone sciflo package
install_dev_repo $OPS sciflo https://github.com/hysds/sciflo.git
# clone chimera package
install_dev_repo $OPS chimera https://github.com/hysds/chimera.git
# clone mozart package
install_dev_repo $OPS mozart https://github.com/hysds/mozart.git
# clone sdscli package
install_dev_repo $OPS sdscli https://github.com/sdskit/sdscli.git
# clone grq2 package
install_dev_repo $OPS grq2 https://github.com/hysds/grq2.git
# clone pele package
install_dev_repo $OPS pele https://github.com/hysds/pele.git
# clone hysds_ui package
clone_dev_repo $OPS hysds_ui https://github.com/hysds/hysds_ui.git
# clone spyddder-man package
clone_dev_repo $OPS spyddder-man https://github.com/hysds/spyddder-man.git
# clone lightweight-jobs package
clone_dev_repo $OPS lightweight-jobs https://github.com/hysds/lightweight-jobs.git
# clone container-builder package
clone_dev_repo $OPS container-builder https://github.com/hysds/container-builder.git
# clone s3-bucket-listing package
clone_dev_repo $OPS s3-bucket-listing https://github.com/hysds/s3-bucket-listing.git
# clone hysds-dockerfiles package
clone_dev_repo $OPS hysds-dockerfiles https://github.com/hysds/hysds-dockerfiles.git
# clone hysds-cloud-functions package
clone_dev_repo $OPS hysds-cloud-functions https://github.com/hysds/hysds-cloud-functions.git
# download latest develop verdi image
if [[ "$COMPONENT" == "mozart" ]]; then
${BASE_PATH}/download_latest.py $API_URL hysds hysds-dockerfiles -o ${INSTALL_DIR}/pkgs -r "^hysds-verdi-develop"
fi
else
# print release if not specified
if [[ "$RELEASE" == "" ]]; then
echo "No release specified. Use -r RELEASE | --release=RELEASE to install a specific release."
echo "Listing available releases:"
for tag in "${!rels[@]}"; do
echo "$tag"
done | sort
exit 0
fi
# verify release exists
if [[ "${rels[$RELEASE]}" == "" ]]; then
echoerr "Error: release $RELEASE doesn't exist."
usage
fi
# download all assets for a release and untar
declare -A assets
for i in `${BASE_PATH}/query_releases.py $REL_API_URL -r $RELEASE`; do
as_name=`echo $i | awk 'BEGIN{FS="|"}{print $1}'`
as_url=`echo $i | awk 'BEGIN{FS="|"}{print $2}'`
# skip verdi docker image
if [[ "$as_name" =~ ^hysds-verdi && "$COMPONENT" != "mozart" ]]; then
continue
fi
assets[$as_name]+=$as_url
if [[ "$GIT_OAUTH_TOKEN" == "" ]]; then
#echo wget --max-redirect=10 --header="Accept: application/octet-stream" \
# -O $as_name $as_url
${BASE_PATH}/download_asset.py $as_url $as_name
else
#echo wget --max-redirect=10 --header="Accept: application/octet-stream" \
# --header="Authorization: token $GIT_OAUTH_TOKEN" \
# -O $as_name $as_url
${BASE_PATH}/download_asset.py $as_url $as_name --token $GIT_OAUTH_TOKEN
fi
if [ "$?" -ne 0 ]; then
echo "Failed to download asset $as_url."
exit 1
fi
# move hysds-verdi release to pkgs
if [[ $as_name == hysds-verdi* ]]; then
mkdir -p $INSTALL_DIR/pkgs
mv hysds-verdi*.tar.gz $INSTALL_DIR/pkgs/
continue
fi
tar xvfz $as_name
done
rm -rf *.tar.gz
# export latest prov_es package
install_repo $OPS prov_es
# export latest osaka package
pip install -U pyasn1
pip install -U pyasn1-modules
pip install -U python-dateutil
install_repo $OPS osaka
# export latest hysds_commons package
install_repo $OPS hysds_commons
# export latest hysds package
cd $OPS
PACKAGE=hysds
PACKAGE_DIR=${PACKAGE}-!(dockerfiles*|cloud-functions*|ops-bot*)
ln -sf $PACKAGE_DIR $PACKAGE
cd $OPS/$PACKAGE
pip install -e .
if [ "$?" -ne 0 ]; then
echo "Failed to run 'pip install -e .' for $PACKAGE."
exit 1
fi
# export latest sciflo package
install_repo $OPS sciflo
# export latest chimera package
install_repo $OPS chimera
# export latest mozart package
install_repo $OPS mozart
# export latest sdscli package
install_repo $OPS sdscli
# export latest grq2 package
install_repo $OPS grq2
# export latest pele package
install_repo $OPS pele
# export latest hysds_ui package
link_repo $OPS hysds_ui
# export latest spyddder-man package
link_repo $OPS spyddder-man
# export latest lightweight-jobs package
link_repo $OPS lightweight-jobs
# export latest container-builder package
link_repo $OPS container-builder
# export latest s3-bucket-listing package
link_repo $OPS s3-bucket-listing
# export latest hysds-dockerfiles package
link_repo $OPS hysds-dockerfiles
# export latest hysds-cloud-functions package
link_repo $OPS hysds-cloud-functions
fi
# additional tasks if installing mozart component
if [[ "$COMPONENT" == "mozart" ]]; then
# download hysds core packages and docker registry image if mozart
${BASE_PATH}/download_latest.py $API_URL hysds lightweight-jobs -o ${INSTALL_DIR}/pkgs -r "^container-hysds_lightweight-jobs-v1"
${BASE_PATH}/download_latest.py $API_URL hysds hysds-dockerfiles -o ${INSTALL_DIR}/pkgs -r "^docker-registry"
${BASE_PATH}/download_latest.py $API_URL hysds hysds-dockerfiles -o ${INSTALL_DIR}/pkgs -r "^logstash-"
# build hysds_ui
install_hysds_ui $OPS hysds_ui
fi