forked from FNNDSC/pfcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·353 lines (338 loc) · 12.4 KB
/
make.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
#!/bin/bash
#
# NAME
#
# make.sh
#
# SYNPOSIS
#
# make.sh [-h] [-i] [-s] [-N] [-U] \
# [-O <swarm|kubernetes>] \
# [-F <swift|filesystem|fslink|zipfile>] \
# [-S <storeBase>] \
# [local|fnndsc[:dev]]
#
# DESC
#
# 'make.sh' sets up a pfcon development instance running either on Swarm or Kubernetes.
# It can also optionally create a pattern of directories and symbolic links that
# reflect the declarative environment on the orchestrator's service configuration file.
#
# TYPICAL CASES:
#
# Run full pfcon instantiation operating out-of-network on Swarm:
#
# unmake.sh ; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh
#
# Run full pfcon instantiation operating in-network on Swarm using Swift storage:
#
# unmake.sh -N -F swift; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh -N -F swift
#
# Run full pfcon instantiation operating in-network on Swarm using mounted filesystem storage:
#
# unmake.sh -N -F filesystem; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh -N -F filesystem
#
# Run full pfcon instantiation operating in-network on Swarm using mounted filesystem
# with ChRIS links storage:
#
# unmake.sh -N -F fslink; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh -N -F fslink
#
# Skip the intro:
#
# unmake.sh ; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh -s
#
#
# Run full pfcon instantiation operating out-of-network on Kubernetes:
#
# unmake.sh -O kubernetes; sudo rm -fr CHRIS_REMOTE_FS; rm -fr CHRIS_REMOTE_FS; make.sh -O kubernetes
#
# ARGS
#
#
# -h
#
# Optional print usage help.
#
# -O <swarm|kubernetes>
#
# Explicitly set the orchestrator. Default is swarm.
#
# -S <storeBase>
#
# Explicitly set the STOREBASE dir to <storeBase>. This is the remote ChRIS
# filesystem where pfcon and plugins share data.
#
# -i
#
# Optional do not automatically attach interactive terminal to pfcon container.
#
# -N
#
# Optional set pfcon to operate in-network mode (using a swift storage instead of
# a zip file).
#
# -F <swift|filesystem|fslink|zipfile>
#
# Explicitly set the storage environment. This option must be swift, fslink or filesystem
# for pfcon operating in-network mode. For pfcon operating in out-of-network mode
# it must be set to zipfile (default).
#
# -U
#
# Optional skip the UNIT tests.
#
# -s
#
# Optional skip intro steps.
#
# [local|fnndsc[:dev]] (optional, default = 'fnndsc')
#
# If specified, denotes the container "family" to use.
#
# If a colon suffix exists, then this is interpreted to further
# specify the TAG, i.e :dev in the example above.
#
# The 'fnndsc' family are the containers as hosted on docker hub.
# Using 'fnndsc' will always attempt to pull the latest container first.
#
# The 'local' family are containers that are assumed built on the local
# machine and assumed to exist. The 'local' containers are used when
# the 'pfcon/pman' services are being locally developed/debugged.
#
#
source ./decorate.sh
source ./cparse.sh
declare -i STEP=0
ORCHESTRATOR=swarm
STORAGE_ENV=zipfile
HERE=$(pwd)
print_usage () {
echo "Usage: ./make.sh [-h] [-i] [-s] [-N] [-F <swift|filesystem|fslink|zipfile>] [-U] [-O <swarm|kubernetes>] [-S <storeBase>] [local|fnndsc[:dev]]"
exit 1
}
while getopts ":hsiNUF:O:S:" opt; do
case $opt in
h) print_usage
;;
s) b_skipIntro=1
;;
i) b_norestartinteractive_pfcon_dev=1
;;
N) b_pfconInNetwork=1
;;
F) STORAGE_ENV=$OPTARG
if ! [[ "$STORAGE_ENV" =~ ^(swift|filesystem|fslink|zipfile)$ ]]; then
echo "Invalid value for option -- F"
print_usage
fi
;;
U) b_skipUnitTests=1
;;
O) ORCHESTRATOR=$OPTARG
if ! [[ "$ORCHESTRATOR" =~ ^(swarm|kubernetes)$ ]]; then
echo "Invalid value for option -- O"
print_usage
fi
;;
S) STOREBASE=$OPTARG
;;
\?) echo "Invalid option -- $OPTARG"
print_usage
;;
:) echo "Option requires an argument -- $OPTARG"
print_usage
;;
esac
done
shift $(($OPTIND - 1))
export SWIFTREPO=fnndsc
export PMANREPO=fnndsc
export TAG=
if (( $# == 1 )) ; then
REPO=$1
export TAG=$(echo $REPO | awk -F \: '{print $2}')
if (( ${#TAG} )) ; then
TAG=":$TAG"
fi
fi
declare -a A_CONTAINER=(
"fnndsc/docker-swift-onlyone^SWIFTREPO"
"fnndsc/pman^PMANREPO"
"fnndsc/pl-simplefsapp"
)
title -d 1 "Setting global exports..."
if [ -z ${STOREBASE+x} ]; then
if [[ ! -d CHRIS_REMOTE_FS ]] ; then
mkdir CHRIS_REMOTE_FS
fi
STOREBASE=$HERE/CHRIS_REMOTE_FS
else
if [[ ! -d $STOREBASE ]] ; then
mkdir -p $STOREBASE
fi
fi
if (( b_pfconInNetwork )) ; then
echo -e "PFCON_INNETWORK=True" | ./boxes.sh
if [[ $STORAGE_ENV == 'zipfile' ]]; then
echo -e "Need to pass '-F <swift|filesystem|fslink|>' when PFCON_INNETWORK=True" | ./boxes.sh
exit 1
fi
else
echo -e "PFCON_INNETWORK=False" | ./boxes.sh
fi
echo -e "ORCHESTRATOR=$ORCHESTRATOR" | ./boxes.sh
echo -e "exporting STORAGE_ENV=$STORAGE_ENV" | ./boxes.sh
export STORAGE_ENV=$STORAGE_ENV
echo -e "exporting STOREBASE=$STOREBASE " | ./boxes.sh
export STOREBASE=$STOREBASE
export SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo -e "exporting SOURCEDIR=$SOURCEDIR " | ./boxes.sh
windowBottom
if (( ! b_skipIntro )) ; then
title -d 1 "Pulling non-'local/' core containers where needed..."
for CORE in ${A_CONTAINER[@]} ; do
cparse $CORE " " "REPO" "CONTAINER" "MMN" "ENV"
if [[ $REPO != "local" ]] ; then
echo "" | ./boxes.sh
CMD="docker pull ${REPO}/$CONTAINER"
printf "${LightCyan}%-40s${Green}%40s${Yellow}\n" \
"docker pull" "${REPO}/$CONTAINER" | ./boxes.sh
windowBottom
sleep 1
echo $CMD | sh | ./boxes.sh -c
fi
done
fi
windowBottom
title -d 1 "Building :dev"
cd $HERE
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
CMD="docker compose -f swarm/docker-compose_dev_innetwork.yml build"
else
CMD="docker compose -f swarm/docker-compose_dev_innetwork_fs.yml build"
fi
else
CMD="docker compose -f swarm/docker-compose_dev.yml build"
fi
echo "$CMD" | ./boxes.sh
echo $CMD | sh | ./boxes.sh -c
windowBottom
title -d 1 "Changing permissions to 755 on" "$HERE"
cd $HERE
echo "chmod -R 755 $HERE" | ./boxes.sh
chmod -R 755 $HERE
windowBottom
title -d 1 "Checking that STOREBASE directory" "$STOREBASE is empty..."
chmod -R 777 $STOREBASE
b_FSOK=1
type -all tree >/dev/null 2>/dev/null
if (( ! $? )) ; then
tree $STOREBASE | ./boxes.sh
report=$(tree $STOREBASE | tail -n 1)
if [[ "$report" != "0 directories, 0 files" ]] ; then
b_FSOK=0
fi
else
report=$(find $STOREBASE 2>/dev/null)
lines=$(echo "$report" | wc -l)
if (( lines != 1 )) ; then
b_FSOK=0
fi
echo "lines is $lines"
fi
if (( ! b_FSOK )) ; then
printf "The STOREBASE directory $STOREBASE must be empty!\n" | ./boxes.sh ${Red}
printf "Please manually clean it and re-run.\n" | ./boxes.sh ${Yellow}
printf "\nThis script will now exit with code '1'.\n\n" | ./boxes.sh ${Yellow}
exit 1
fi
printf "${LightCyan}%40s${LightGreen}%40s\n" \
"Tree state" "[ OK ]" | ./boxes.sh
windowBottom
title -d 1 "Starting pfcon containerized dev environment on $ORCHESTRATOR"
if [[ $ORCHESTRATOR == swarm ]]; then
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
echo "docker stack deploy -c swarm/docker-compose_dev_innetwork.yml pfcon_dev_stack" | ./boxes.sh ${LightCyan}
docker stack deploy -c swarm/docker-compose_dev_innetwork.yml pfcon_dev_stack
else
echo "docker stack deploy -c swarm/docker-compose_dev_innetwork_fs.yml pfcon_dev_stack" | ./boxes.sh ${LightCyan}
docker stack deploy -c swarm/docker-compose_dev_innetwork_fs.yml pfcon_dev_stack
fi
else
echo "docker stack deploy -c swarm/docker-compose_dev.yml pfcon_dev_stack" | ./boxes.sh ${LightCyan}
docker stack deploy -c swarm/docker-compose_dev.yml pfcon_dev_stack
fi
elif [[ $ORCHESTRATOR == kubernetes ]]; then
if (( b_pfconInNetwork )) ; then
echo "envsubst < kubernetes/pfcon_dev_innetwork.yaml | kubectl apply -f -" | ./boxes.sh ${LightCyan}
envsubst < kubernetes/pfcon_dev_innetwork.yaml | kubectl apply -f -
else
echo "envsubst < kubernetes/pfcon_dev.yaml | kubectl apply -f -" | ./boxes.sh ${LightCyan}
envsubst < kubernetes/pfcon_dev.yaml | kubectl apply -f -
fi
fi
windowBottom
title -d 1 "Waiting until pfcon stack containers are running on $ORCHESTRATOR"
echo "This might take a few minutes... please be patient." | ./boxes.sh ${Yellow}
for i in {1..30}; do
sleep 5
if [[ $ORCHESTRATOR == swarm ]]; then
pfcon_dev=$(docker ps -f name=pfcon_dev_stack_pfcon.1 -q)
elif [[ $ORCHESTRATOR == kubernetes ]]; then
pfcon_dev=$(kubectl get pods --selector="app=pfcon,env=development" --field-selector=status.phase=Running --output=jsonpath='{.items[*].metadata.name}')
fi
if [ -n "$pfcon_dev" ]; then
echo "Success: pfcon container is up" | ./boxes.sh ${Green}
break
fi
done
if [ -z "$pfcon_dev" ]; then
echo "Error: couldn't start pfcon container" | ./boxes.sh ${Red}
exit 1
fi
windowBottom
if (( ! b_skipUnitTests )) ; then
title -d 1 "Running pfcon tests..."
sleep 5
if [[ $ORCHESTRATOR == swarm ]]; then
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
docker exec $pfcon_dev pytest tests/test_resources_innetwork.py --color=yes
elif [[ $STORAGE_ENV == 'filesystem' ]]; then
docker exec $pfcon_dev pytest tests/test_resources_innetwork_fs.py --color=yes
elif [[ $STORAGE_ENV == 'fslink' ]]; then
docker exec $pfcon_dev pytest tests/test_resources_innetwork_fslink.py --color=yes
fi
else
docker exec $pfcon_dev pytest tests/test_resources.py --color=yes
fi
elif [[ $ORCHESTRATOR == kubernetes ]]; then
if (( b_pfconInNetwork )) ; then
kubectl exec $pfcon_dev -- pytest tests/test_resources_innetwork.py --color=yes
else
kubectl exec $pfcon_dev -- pytest tests/test_resources.py --color=yes
fi
fi
status=$?
title -d 1 "pfcon test results"
if (( $status == 0 )) ; then
printf "%40s${LightGreen}%40s${NC}\n" \
"pfcon tests" "[ success ]" | ./boxes.sh
else
printf "%40s${Red}%40s${NC}\n" \
"pfcon tests" "[ failure ]" | ./boxes.sh
fi
windowBottom
fi
if (( ! b_norestartinteractive_pfcon_dev )) ; then
title -d 1 "Attaching interactive terminal (ctrl-c to detach)"
if [[ $ORCHESTRATOR == swarm ]]; then
docker logs $pfcon_dev
docker attach --detach-keys ctrl-c $pfcon_dev
elif [[ $ORCHESTRATOR == kubernetes ]]; then
kubectl logs $pfcon_dev
kubectl attach $pfcon_dev -i -t
fi
fi