-
Notifications
You must be signed in to change notification settings - Fork 26
/
unmake.sh
executable file
·163 lines (157 loc) · 5.1 KB
/
unmake.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
#!/bin/bash
#
# NAME
#
# unmake.sh
#
# SYNPOSIS
#
# unmake.sh [-h] [-N] \
# [-F <swift|filesystem|fslink|zipfile>] \
# [-O <swarm|kubernetes>] \
# [-S <storeBase>]
#
#
# DESC
#
# 'unmake.sh' destroys a pfcon development instance running on Swarm or Kubernetes.
#
# TYPICAL CASES:
#
# Destroy pfcon dev instance on Swarm:
#
# unmake.sh
#
# Destroy pfcon dev instance operating in-network on Swarm using Swift storage:
#
# unmake.sh -N -F swift
#
# Destroy pfcon dev instance operating in-network on Swarm using mounted filesystem
# with ChRIS links storage:
#
# unmake.sh -N -F fslink
#
# Destroy pfcon dev instance operating in-network on Swarm using mounted filesystem storage:
#
# unmake.sh -N -F filesystem
#
# Destroy pfcon dev instance on Kubernetes:
#
# unmake.sh -O kubernetes
#
# ARGS
#
#
# -h
#
# -N
#
# Explicitly set pfcon to operate in-network mode (using a swift storage instead of
# a zip file).
#
# Optional print usage help.
#
# -F <swift|filesystem|fslink|zipfile>
#
# Explicitly set the storage environment. This option must be swift or filesystem
# for pfcon operating in-network mode. For pfcon operating in out-of-network mode
# it must be set to zipfile (default).
#
# -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.
#
#
source ./decorate.sh
declare -i STEP=0
ORCHESTRATOR=swarm
STORAGE_ENV=zipfile
print_usage () {
echo "Usage: ./unmake.sh [-h] [-N] [-F <swift|filesystem|fslink|zipfile>] [-O <swarm|kubernetes>] [-S <storeBase>]"
exit 1
}
while getopts ":hNF:O:S:" opt; do
case $opt in
h) print_usage
;;
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
;;
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))
title -d 1 "Setting global exports..."
if [ -z ${STOREBASE+x} ]; then
STOREBASE=$(pwd)/CHRIS_REMOTE_FS
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
title -d 1 "Destroying pfcon containerized dev environment on $ORCHESTRATOR"
if [[ $ORCHESTRATOR == swarm ]]; then
echo "docker stack rm pfcon_dev_stack" | ./boxes.sh ${LightCyan}
docker stack rm pfcon_dev_stack
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
echo "docker volume rm -f pfcon_dev_stack_swift_storage_dev"
sleep 15
docker volume rm pfcon_dev_stack_swift_storage_dev
fi
fi
elif [[ $ORCHESTRATOR == kubernetes ]]; then
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
echo "kubectl delete -f kubernetes/pfcon_dev_innetwork.yaml" | ./boxes.sh ${LightCyan}
kubectl delete -f kubernetes/pfcon_dev_innetwork.yaml
echo "Removing swift_storage folder $SOURCEDIR/swift_storage" | ./boxes.sh
rm -fr $SOURCEDIR/swift_storage
else
echo "kubectl delete -f kubernetes/pfcon_dev_innetwork_fs.yaml" | ./boxes.sh ${LightCyan}
kubectl delete -f kubernetes/pfcon_dev_innetwork_fs.yaml
fi
else
echo "kubectl delete -f kubernetes/pfcon_dev.yaml" | ./boxes.sh ${LightCyan}
kubectl delete -f kubernetes/pfcon_dev.yaml
fi
fi
echo "Removing STOREBASE tree $STOREBASE" | ./boxes.sh
rm -fr $STOREBASE
windowBottom