-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathunmake.sh
More file actions
executable file
·199 lines (192 loc) · 7.03 KB
/
unmake.sh
File metadata and controls
executable file
·199 lines (192 loc) · 7.03 KB
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
#!/bin/bash
#
# NAME
#
# unmake.sh
#
# SYNPOSIS
#
# unmake.sh [-h] [-N] \
# [-F <swift|s3|filesystem|fslink|zipfile>] \
# [-O <docker|swarm|kubernetes>] \
# [-S <storeBase>]
#
#
# DESC
#
# 'unmake.sh' destroys a pfcon development instance running on Docker, Swarm or Kubernetes.
#
# TYPICAL CASES:
#
# Destroy pfcon dev instance on Docker:
#
# unmake.sh
#
# Destroy pfcon dev instance operating in-network on Docker using Swift storage:
#
# unmake.sh -N -F swift
#
# Destroy pfcon dev instance operating in-network on Docker using S3 storage:
#
# unmake.sh -N -F s3
#
# Destroy pfcon dev instance operating in-network on Docker using mounted filesystem
# with ChRIS links storage:
#
# unmake.sh -N -F fslink
#
# Destroy pfcon dev instance operating in-network on Docker using mounted filesystem storage:
#
# unmake.sh -N -F filesystem
#
# Destroy pfcon dev instance on Swarm:
#
# unmake.sh -O swarm
#
# Destroy pfcon dev instance on Kubernetes:
#
# unmake.sh -O kubernetes
#
# ARGS
#
#
# -h
#
# -N
#
# Explicitly set pfcon to operate in-network mode (using a shared storage instead of
# a zip file).
#
# Optional print usage help.
#
# -F <swift|s3|filesystem|fslink|zipfile>
#
# Explicitly set the storage environment. This option must be swift, s3,
# filesystem or fslink for pfcon operating in-network mode. For pfcon
# operating in out-of-network mode it must be set to zipfile (default).
#
# -O <docker|swarm|kubernetes>
#
# Explicitly set the orchestrator. Default is docker.
#
# -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
CONTAINER_ENV=docker
STORAGE_ENV=zipfile
print_usage () {
echo "Usage: ./unmake.sh [-h] [-N] [-F <swift|s3|filesystem|fslink|zipfile>] [-O <docker|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|s3|filesystem|fslink|zipfile)$ ]]; then
echo "Invalid value for option -- F"
print_usage
fi
;;
O) CONTAINER_ENV=$OPTARG
if ! [[ "$CONTAINER_ENV" =~ ^(docker|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
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|s3|filesystem|fslink|>' when PFCON_INNETWORK=True" | ./boxes.sh
exit 1
fi
else
echo -e "PFCON_INNETWORK=False" | ./boxes.sh
fi
echo -e "exporting CONTAINER_ENV=$CONTAINER_ENV " | ./boxes.sh
export CONTAINER_ENV=$CONTAINER_ENV
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 $CONTAINER_ENV"
if [[ $CONTAINER_ENV == docker ]]; then
if (( b_pfconInNetwork )) ; then
if [[ $STORAGE_ENV == 'swift' ]]; then
echo "docker compose -f swarm/docker-compose_dev_innetwork.yml down -v" | ./boxes.sh ${LightCyan}
docker compose -f swarm/docker-compose_dev_innetwork.yml down -v
elif [[ $STORAGE_ENV == 's3' ]]; then
echo "docker compose -f swarm/docker-compose_dev_innetwork_s3.yml down -v" | ./boxes.sh ${LightCyan}
docker compose -f swarm/docker-compose_dev_innetwork_s3.yml down -v
elif [[ "$STORAGE_ENV" =~ ^(filesystem|fslink)$ ]]; then
echo "docker compose -f swarm/docker-compose_dev_innetwork_fs.yml down -v" | ./boxes.sh ${LightCyan}
docker compose -f swarm/docker-compose_dev_innetwork_fs.yml down -v
fi
else
echo "docker compose -f swarm/docker-compose_dev.yml down -v" | ./boxes.sh ${LightCyan}
docker compose -f swarm/docker-compose_dev.yml down -v
fi
elif [[ $CONTAINER_ENV == 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
elif [[ $STORAGE_ENV == 's3' ]]; then
echo "docker volume rm -f pfcon_dev_stack_s3_storage_dev"
sleep 15
docker volume rm pfcon_dev_stack_s3_storage_dev
fi
fi
elif [[ $CONTAINER_ENV == 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
elif [[ $STORAGE_ENV == 's3' ]]; then
echo "kubectl delete -f kubernetes/pfcon_dev_innetwork_s3.yaml" | ./boxes.sh ${LightCyan}
kubectl delete -f kubernetes/pfcon_dev_innetwork_s3.yaml
echo "Removing s3_storage folder $SOURCEDIR/s3_storage" | ./boxes.sh
rm -fr $SOURCEDIR/s3_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