-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcleanup.sh
executable file
·72 lines (64 loc) · 1.79 KB
/
cleanup.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
#!/bin/bash
scriptdir=$(realpath $(dirname "$0"))
source ${scriptdir}/common/common.sh
source ${scriptdir}/common/functions.sh
function print_help() {
echo -e "Usage:\n"\
"./cleanup.sh # cleanup build artefacts (sandbox container, sources, saved configuration)\n"\
" [-a ] false ] # cleanup all (build artefacts, dev-env image\n"\
" [-h ] # print help\n"
}
remove_sources=1
remove_containers=1
remove_image=0
remove_tf_dev_config=1
while getopts ":abh" opt; do
case $opt in
a)
remove_sources=1
remove_containers=1
remove_image=1
remove_tf_dev_config=1
;;
h)
print_help
exit
;;
*)
print_help
echo "Invalid option: -$opt. Exiting..." >&2
exit 1
;;
esac
done
echo tf-dev-env cleanup
if [[ $remove_containers -eq 1 ]] ; then
echo
echo '[containers]'
for container in $DEVENV_CONTAINER_NAME $REGISTRY_CONTAINER_NAME; do
if is_container_created "$container" ; then
echo -ne "$(mysudo docker stop $container) stopped."\\r
echo $(mysudo docker rm $container) removed.
else
echo "$container not running."
fi
done
fi
if [[ $remove_image -eq 1 ]] ; then
echo
echo '[images]'
mysudo docker inspect ${DEVENV_IMAGE} >/dev/null 2>&1 && mysudo docker rmi -f ${DEVENV_IMAGE}
mysudo docker inspect ${CONTAINER_REGISTRY}/${DEVENV_IMAGE} >/dev/null 2>&1 && mysudo docker rmi -f ${CONTAINER_REGISTRY}/${DEVENV_IMAGE}
echo "image $DEVENV_IMAGE removed"
fi
if [[ $remove_sources -eq 1 ]] ; then
echo
echo '[folder]'
[ -d "$CONTRAIL_DIR" ] && mysudo rm -rf "$CONTRAIL_DIR"
fi
if [[ $remove_tf_dev_config -eq 1 ]] ; then
echo
echo '[tf dev config]'
[ -d "$TF_CONFIG_DIR" ] && mysudo rm -rf "$TF_CONFIG_DIR"
fi
echo tf-dev-env cleanup finished