-
Notifications
You must be signed in to change notification settings - Fork 100
/
unmake.sh
executable file
·211 lines (201 loc) · 6.41 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
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
#!/bin/bash
#
# NAME
#
# unmake.sh
#
# SYNPOSIS
#
# unmake.sh [-h]
# [-O <swarm|kubernetes>]
# [-F <swift|fslink|filesystem>] \
# [-S <storeBase>]
#
#
# DESC
#
# 'unmake.sh' destroys a chris development instance with remote ancillary services
# pfcon/pman running on Swarm or Kubernetes.
#
# TYPICAL CASES:
#
# Destroy chris_dev instance with remote ancillary services running on Swarm with Swift storage:
#
# unmake.sh
#
# Destroy chris_dev instance running with filesystem storage:
#
# unmake.sh -F filesystem
#
# Destroy chris_dev instance running with fslink storage:
#
# unmake.sh -F fslink
#
#
# Destroy chris_dev instance with remote ancillary services running on Kubernetes:
#
# unmake.sh -O kubernetes
#
# ARGS
#
#
# -h
#
# Optional print usage help.
#
# -O <swarm|kubernetes>
#
# Explicitly set the orchestrator. Default is swarm.
#
# -F <swift|fslink|filesystem>]
#
# Explicitly set the storage environment. Default is swift.
#
# -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=swift
dc_check () {
STATUS=$1
if [[ $STATUS != "0" ]] ; then
echo -en "\033[2A\033[2K"
cat dc.out | sed -E 's/(.{80})/\1\n/g' | ./boxes.sh LightRed
else
echo -en "\033[2A\033[2K"
cat dc.out | ./boxes.sh White
fi
}
print_usage () {
echo "Usage: ./unmake.sh [-h] [-O <swarm|kubernetes>] [-F <swift|fslink|filesystem>]
[-S <storeBase>]"
exit 1
}
while getopts ":hO:F:S:" opt; do
case $opt in
h) print_usage
;;
O) ORCHESTRATOR=$OPTARG
if ! [[ "$ORCHESTRATOR" =~ ^(swarm|kubernetes)$ ]]; then
echo "Invalid value for option -- O"
print_usage
fi
;;
F) STORAGE_ENV=$OPTARG
if ! [[ "$STORAGE_ENV" =~ ^(swift|fslink|filesystem)$ ]]; then
echo "Invalid value for option -- F"
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"
boxcenter "-= ORCHESTRATOR =-"
boxcenter "$ORCHESTRATOR" LightCyan
boxcenter ""
boxcenter "exporting STORAGE_ENV=$STORAGE_ENV "
export STORAGE_ENV=$STORAGE_ENV
boxcenter ""
if [ -z ${STOREBASE+x} ]; then
STOREBASE=$(pwd)/CHRIS_REMOTE_FS
fi
boxcenter "-= STOREBASE =-"
if (( ${#STOREBASE} > 80 )) ; then
STOREBASEdisp="...${STOREBASE: -77}"
else
STOREBASEdisp=$STOREBASE
fi
echo "$STOREBASEdisp" | ./boxes.sh LightCyan
export STOREBASE=$STOREBASE
if [[ $ORCHESTRATOR == kubernetes ]]; then
echo -e "exporting REMOTENETWORK=false " | ./boxes.sh
export REMOTENETWORK=false
windowBottom
fi
windowBottom
title -d 1 "Destroying remote pfcon containerized environment on " \
"-= $ORCHESTRATOR =-"
if [[ $ORCHESTRATOR == swarm ]]; then
echo "$ docker stack rm pfcon_stack" | ./boxes.sh LightCyan
windowBottom
docker stack rm pfcon_stack &> dc.out
elif [[ $ORCHESTRATOR == kubernetes ]]; then
echo "$ kubectl delete -f kubernetes/remote.yaml" | ./boxes.sh LightCyan
windowBottom
kubectl delete -f kubernetes/remote.yaml &> dc.out
fi
dc_check $?
echo "$ rm -fr \$STOREBASE" | ./boxes.sh LightCyan
rm -fr $STOREBASE
windowBottom
if [[ $STORAGE_ENV == 'swift' ]]; then
title -d 1 "Destroying CUBE containerized development environment" \
"from ./docker-compose_dev.yml"
echo "Do you want to also remove persistent volumes? [y/n]" | ./boxes.sh White
windowBottom
old_stty_cfg=$(stty -g)
stty raw -echo ; REPLY=$(head -c 1) ; stty $old_stty_cfg
echo -en "\033[2A\033[2K"
# read -p " " -n 1 -r REPLY
if [[ $REPLY =~ ^[Yy]$ ]] ; then
boxcenter ""
echo "Removing persistent volumes... please be patient." | ./boxes.sh Yellow
boxcenter ""
echo "$ docker compose -f docker-compose_dev.yml down -v" | ./boxes.sh LightCyan
windowBottom
docker compose -f docker-compose_dev.yml down -v >& dc.out
dc_check $?
else
echo "Keeping persistent volumes... please be patient." | ./boxes.sh Yellow
windowBottom
docker compose -f docker-compose_dev.yml down >& dc.out
dc_check $?
fi
windowBottom
elif [[ $STORAGE_ENV =~ ^(fslink|filesystem)$ ]]; then
title -d 1 "Destroying CUBE containerized development environment" \
"from ./docker-compose_noswift.yml"
echo "Do you want to also remove persistent volumes? [y/n]" | ./boxes.sh White
windowBottom
old_stty_cfg=$(stty -g)
stty raw -echo ; REPLY=$(head -c 1) ; stty $old_stty_cfg
echo -en "\033[2A\033[2K"
# read -p " " -n 1 -r REPLY
if [[ $REPLY =~ ^[Yy]$ ]] ; then
boxcenter ""
echo "Removing persistent volumes... please be patient." | ./boxes.sh Yellow
boxcenter ""
echo "$ docker compose -f docker-compose_noswift.yml down -v" | ./boxes.sh LightCyan
windowBottom
docker compose -f docker-compose_noswift.yml down -v >& dc.out
dc_check $?
else
echo "Keeping persistent volumes... please be patient." | ./boxes.sh Yellow
windowBottom
docker compose -f docker-compose_noswift.yml down >& dc.out
dc_check $?
fi
windowBottom
fi
if [[ $ORCHESTRATOR == swarm ]]; then
title -d 1 "Removing overlay network: remote"
windowBottom
sleep 2
docker network rm remote &> dc.out
dc_check $?
windowBottom
fi