forked from FNNDSC/ChRIS_ultron_backEnd
-
Notifications
You must be signed in to change notification settings - Fork 8
/
plugin_add.sh
executable file
·326 lines (309 loc) · 14.8 KB
/
plugin_add.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
#!/bin/bash
#
# NAME
#
# plugin_add.sh
#
# SYNPOSIS
#
# plugin_add.sh [-t dev|deploy] \
# [-s <step>] [-j] \
# <commaSeparatedListOfPluginSpecsToAdd>
#
# DESC
#
# 'plugin_add.sh' adds new plugins to an existing and instantiated
# CUBE.
#
# Notes on pluginList
#
# The plugin list is a comma separated list, each element conforming to a
# cparse specification, e.g.:
#
# fnndsc/pl-pfdicom_tagextract^moc
#
# templatized as:
#
# [<repo>/]<container>[^<env>]
#
##
# ARGS
#
# [-t dev|deploy]
#
# Choose either 'dev' or 'deploy' targets. This affects the choice of
# underlying docker-compose yaml to process as well as the name of the
# chris service.
#
# Default is 'dev'.
#
# [-s <step>]
#
# Start STEP counter at <step>. This is useful for cases when
# this script is called from another staged script and contintuity
# requires a <step> offset.
#
# [-j]
#
# Show JSON representation. If specified, also "print" a given plugin
# JSON representation during the store registration phase.
#
source ./decorate.sh
source ./cparse.sh
DOCKER_COMPOSE_FILE=docker-compose_dev.yml
CHRIS=chris_dev
TARGET=dev
declare -i STEP=0
declare -i b_json=0
HERE=$(pwd)
LINE="------------------------------------------------"
if [[ -f .env ]] ; then
source .env
fi
while getopts "f:s:j" opt; do
case $opt in
s) STEP=$OPTARG
STEP=$(( STEP -1 )) ;;
t) TARGET=$OPTARG ;;
j) b_json=1 ;;
esac
done
case $TARGET in
dev) DOCKER_COMPOSE_FILE=docker-compose_dev.yml
CHRIS=chris_dev
;;
deploy) DOCKER_COMPOSE_FILE=docker-compose.yml
CHRIS=chris
;;
*) DOCKER_COMPOSE_FILE=docker-compose_dev.yml
CHRIS=chris_dev
;;
esac
declare -a a_PLUGINRepoEnv=()
declare -a a_storePluginUser=()
declare -a a_storePluginOK=()
shift $(($OPTIND - 1))
L_PLUGINS=$*
IFS=',' read -ra a_PLUGINRepoEnv <<< "$L_PLUGINS"
title -d 1 "Creating array of <REPO>/<CONTAINER> from plugin list..."
for plugin in "${a_PLUGINRepoEnv[@]}" ; do
cparse $plugin "REPO" "CONTAINER" "MMN" "ENV"
tcprint Yellow "Processing env [$ENV] for " LightCyan "$REPO/$CONTAINER" "40" "-40"
a_storePluginUser+=("$REPO/$CONTAINER")
done
a_storePluginUser=($(printf "%s\n" "${a_storePluginUser[@]}" | sort -u | tr '\n' ' '))
windowBottom
title -d 1 "Removing any duplicate <REPO>/<CONTAINER> from plugin list..."
a_storePluginUser=($(printf "%s\n" "${a_storePluginUser[@]}" | sort -u | tr '\n' ' '))
numElements=${#a_storePluginUser[@]}
tcprint "Yellow" "Unique hits " LightCyan "$numElements" "40" "-40"
for plugin in "${a_storePluginUser[@]}" ; do
tcprint Yellow "Image " LightCyan $plugin "40" "-40"
done
windowBottom
title -d 1 "Checking on container plugins " \
"and pulling latest versions where needed..."
declare -i b_pullSuccess=0
declare -i b_pullFail=0
for plugin in "${a_storePluginUser[@]}" ; do
cparse $plugin "REPO" "CONTAINER" "MMN" "ENV"
if [[ $REPO == "fnndsc" ]] ; then
printf "${LightBlueBG}${White}[ dockerhub ]${NC}::${LightCyan}%-35s${Yellow}%19s${blink}${LightGreen}%-11s${NC}\n" \
"$REPO/$CONTAINER" "latest<--" "[ pulling ]" | ./boxes.sh
windowBottom
CMD="docker pull $REPO/$CONTAINER"
echo $CMD | sh >& dc.out >/dev/null
status=$?
if (( status == 0 )) ; then
b_pullSuccess=$(( b_pullSuccess+=1 ))
report="[ success ]"
reportColor=LightGreen
a_storePluginOK+=("$plugin")
echo -en "\033[3A\033[2K"
printf "${LightBlueBG}${White}[ dockerhub ]${NC}::${LightCyan}%-35s${Yellow}%19s${LightGreenBG}${White}%-11s${NC}\n" \
"$REPO/$CONTAINER" "latest<--" "$report" | ./boxes.sh
else
b_pullFail=$(( b_pullFail+=1 ))
report="[ failed ]"
reportColor=LightRed
echo -en "\033[3A\033[2K"
printf "${LightBlueBG}${White}[ dockerhub ]${NC}::${LightCyan}%-35s${Yellow}%19s${RedBG}${White}%-11s${NC}\n"\
"$REPO/$CONTAINER" "latest<--" "$report" | ./boxes.sh
fi
cat dc.out | sed 's/[[:alnum:]]+:/\n&/g' | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh
fi
done
if (( b_pullSuccess > 0 )) ; then
printf "${LightCyan}%16s${LightGreen}%-64s${NC}\n" \
"$b_pullSuccess" \
" images successfully pulled" | ./boxes.sh
echo "" | ./boxes.sh
fi
if (( b_pullFail > 0 )) ; then
printf "${LightRed}%16s${Brown}%-64s${NC}\n" \
"$b_pullFail" \
" images were not successfully pulled." | ./boxes.sh
boxcenter " "
boxcenter "The attempt to pull some containers resulted in a " ${LightRed}
boxcenter "failure. There are many possible reasons for this " ${LightRed}
boxcenter "but the first thing to verify is that the image " ${LightRed}
boxcenter "names passed are correct. You can also directly " ${LightRed}
boxcenter "try and pull the failed images with " ${LightRed}
boxcenter " "
boxcenter "docker pull <imageName> " ${White}
boxcenter " "
boxcenter "Note that if you do NOT have sudoless docker " ${Yellow}
boxcenter "configured, you should run this script using " ${Yellow}
boxcenter " "
boxcenter "sudo ./plugin_add.sh ..." ${White}
boxcenter " "
fi
windowBottom
title -d 1 "Uploading plugin representations to the ChRIS store..."
declare -i i=1
declare -i b_uploadSuccess=0
declare -i b_already=0
declare -i b_uploadFail=0
echo "" | ./boxes.sh
echo "" | ./boxes.sh
for plugin in "${a_PLUGINRepoEnv[@]}"; do
echo -en "\033[2A\033[2K"
cparse $plugin "REPO" "CONTAINER" "MMN" "ENV"
CMD="docker run --rm $REPO/$CONTAINER ${MMN} --json 2> /dev/null"
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${blink}${LightGreen}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON representation<--" "[ getting ]" | ./boxes.sh
windowBottom
PLUGIN_REP=$(docker run --rm $REPO/$CONTAINER ${MMN} --json 2>/dev/null)
echo -en "\033[3A\033[2K"
if (( b_json )) ; then
echo "$PLUGIN_REP" | python -m json.tool |\
sed 's/[[:alnum:]]+:/\n&/g' | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh ${LightGreen}
fi
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${LightGreen}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON representation<--" "[ acquired ]" | ./boxes.sh
windowBottom
echo -en "\033[3A\033[2K"
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${blink}${LightGreen}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON representation<--" "[ pushing ]" | ./boxes.sh
windowBottom
docker-compose -f ${DOCKER_COMPOSE_FILE} \
exec chris_store python plugins/services/manager.py add "$CONTAINER" \
cubeadmin https://github.com/FNNDSC "$REPO/$CONTAINER" \
--descriptorstring "$PLUGIN_REP" >& dc.out >/dev/null
status=$?
echo -en "\033[3A\033[2K"
# cat dc.out | sed 's/[[:alnum:]]+:/\n&/g' | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh
if (( status == 0 )) ; then
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${LightGreenBG}${White}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON in ChRIS store<--" "[ success ]" | ./boxes.sh
b_uploadSuccess=$(( b_uploadSuccess+=1 ))
elif (( status == 1 )) ; then
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${PurpleBG}${White}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON in ChRIS store<--" "[ already ]" | ./boxes.sh
b_already=$(( b_already+=1 ))
elif (( status == 2 )) ; then
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%28s${RedBG}${White}%12s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "JSON in ChRIS store<--" "[ error ]" | ./boxes.sh
b_uploadFail=$(( b_uploadFail+=1 ))
fi
((i++))
windowBottom
done
echo -en "\033[2A\033[2K"
echo "" | ./boxes.sh
if (( b_uploadSuccess > 0 )) ; then
printf "${LightCyan}%16s${LightGreen}%-64s${NC}\n" \
"$b_uploadSuccess" \
" representation(s) successfully uploaded to ChRIS Store" | ./boxes.sh
echo "" | ./boxes.sh
fi
if (( b_already > 0 )) ; then
printf "${LightCyan}%16s${Yellow}%-64s${NC}\n" \
"$b_already" \
" representation(s) were already in the ChRIS Store" | ./boxes.sh
boxcenter "An 'already' state simply means the representation" ${LightPurple}
boxcenter "is already in the ChRIS Store -- most likely due" ${LightPurple}
boxcenter "a prior attempt at registration. Also, note that" ${LightPurple}
boxcenter "if the same plugin is processed ultimately to many" ${LightPurple}
boxcenter "compute environments, an 'already' state will be" ${LightPurple}
boxcenter "triggered. This state is harmless and merely is a" ${LightPurple}
boxcenter "warning. " ${LightPurple}
echo "" | ./boxes.sh
fi
if (( b_uploadFail > 0 )) ; then
printf "${LightRed}%16s${Brown}%-64s${NC}\n" \
"$b_uploadFail" \
" representation(s) did not upload to ChRIS Store." | ./boxes.sh
boxcenter "The attempt to upload some plugin representations " ${LightRed}
boxcenter "had a complete failure. This could mean that the " ${LightRed}
boxcenter "plugin itself did not exist or download, or if it " ${LightRed}
boxcenter "did, the plugin might not correctly service the " ${LightRed}
boxcenter "'--json' flag to create a representation. " ${LightRed}
echo "" | ./boxes.sh
fi
windowBottom
title -d 1 "Automatically registering some plugins from the ChRIS store" \
"with associated compute environment in ChRIS..."
declare -i i=1
declare -i b_registerSuccess=0
declare -i b_registerFail=0
echo "" | ./boxes.sh
echo "" | ./boxes.sh
for plugin in "${a_PLUGINRepoEnv[@]}"; do
cparse $plugin "REPO" "CONTAINER" "MMN" "ENV"
echo -en "\033[2A\033[2K"
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%23s${blink}${LightGreen}%-17s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "[ChRIS]::$ENV<--" "[ adding ]" | ./boxes.sh
windowBottom
computeDescription="${ENV} description"
docker-compose -f ${DOCKER_COMPOSE_FILE} \
exec ${CHRIS} python plugins/services/manager.py \
add "$ENV" "http://pfcon.remote:30005/api/v1/" \
--description "$ENV Description" >& dc.out >/dev/null
status=$?
echo -en "\033[3A\033[2K"
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%23s${LightGreen}%-17s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "[ChRIS]::$ENV<--" "[ added success ]" | ./boxes.sh
cat dc.out | ./boxes.sh
echo -en "\033[1A\033[2K"
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%23s${blink}${LightGreen}%-17s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "[ChRIS]::$ENV<--" "[ registering ]" | ./boxes.sh
windowBottom
docker-compose -f ${DOCKER_COMPOSE_FILE} \
exec ${CHRIS} python plugins/services/manager.py \
register $ENV --pluginname "$CONTAINER" >& dc.out >/dev/null
status=$?
echo -en "\033[3A\033[2K"
if (( $status == 0 )) ; then
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%23s${GreenBG}${White}%-17s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "[ChRIS]::$ENV<--" "[ register OK ]" | ./boxes.sh
b_registerSuccess=$(( b_registerSuccess+=1 ))
else
printf "${Yellow}%5s${LightCyan}%-35s${Yellow}%23s${RedBG}${White}%-17s${NC}\n" \
"$i: " "$REPO/$CONTAINER" "[ChRIS]::$ENV<--" "[ register fail ]" | ./boxes.sh
b_registerFail=$(( b_registerFail+=1 ))
fi
cat dc.out | ./boxes.sh
((i++))
windowBottom
done
echo -en "\033[2A\033[2K"
echo "" | ./boxes.sh
if (( b_registerSuccess )) ; then
printf "${LightCyan}%18s${LightGreen}%-62s${NC}\n" \
"$b_registerSuccess" \
" plugin(s)+env(s) successfully registered to ChRIS" | ./boxes.sh
echo "" | ./boxes.sh
fi
if (( b_registerFail )) ; then
printf "${Red}%18s${Brown}%-62s${NC}\n" \
"$b_registerFail" \
" plugin(s)+env(s) failed to register to ChRIS." | ./boxes.sh
boxcenter "Plugins that failed to register to ChRIS will not" ${LightRed}
boxcenter "be available for use in the system. Please check" ${LightRed}
boxcenter "the plugin download and/or store registration" ${LightRed}
boxcenter "steps for possible insights. " ${LightRed}
echo "" | ./boxes.sh
fi
echo "" | ./boxes.sh
windowBottom