forked from scikit-multiflow/scikit-multiflow
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmultiflow.sh
151 lines (141 loc) · 6.04 KB
/
multiflow.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
#! /bin/bash
set -e # Ensure we fail if an error occurs
set -o pipefail # Ensure we fail if something fails at pipeline level
######################## GET SCRIPT LOCATION - START - ##############################
SCRIPT_LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
######################## GET SCRIPT LOCATION - END - ################################
PROFILE="${PROFILE:-LOCAL}"
# Possible profiles: "LOCAL", "DOCKER-DEV"
MODE="$1"
# Check if option passed is valid
OPTIONS_ARRAY=( "--start" "--recreate" "--stop" "--destroy" "--show-args" "--into-dev" "--attach-tmux" "--help" "--update-images" "--purge-images" "--run-tests" "--run-test" )
VALID_OPTION="false"
if [ -z "$1" ]; then
echo "Please specify an option!"
IFS=$'\n'; echo "${OPTIONS_ARRAY[*]}"
exit 1
fi
for k in "${OPTIONS_ARRAY[@]}"; do
if [ $k = $1 ]; then
VALID_OPTION="true"
fi
done
if [ $VALID_OPTION = "false" ]; then
echo "$1 is not a valid option! Valid options are: "
IFS=$'\n'; echo "${OPTIONS_ARRAY[*]}"
exit 1
fi
#########################################################################
# execute requested action
if [ $MODE = "--start" ] || [ $MODE = "--recreate" ] || [ $MODE = "--prepare" ]; then
if [ $PROFILE = "LOCAL" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/dev/cli/start-dev-env.sh $SCRIPT_LOCATION $MODE
else
echo "Detected $PROFILE profile - $MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--destroy" ]; then
if [ $PROFILE != "LOCAL" ]; then
echo "Detected $PROFILE profile - $MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--stop" ] || [ $MODE = "--destroy" ]; then
if [ $PROFILE = "LOCAL" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/dev/cli/stop-dev-env.sh $SCRIPT_LOCATION $MODE
else
echo "Detected $PROFILE profile - $MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--show-args" ]; then
if [ $PROFILE != "LOCAL" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/dev/cli/show-env-variables.sh
else
echo "$MODE allowed inside Docker only."
fi
fi
if [ $MODE = "--into-dev" ]; then
if [ $PROFILE = "LOCAL" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/dev/cli/log-into-dev.sh
else
echo "Detected $PROFILE profile - $MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--attach-tmux" ]; then
if [ $PROFILE != "LOCAL" ]; then
x=$(tmux list-session | grep 'ql' || true)
x=$(echo $x |wc -l)
if [ $x -eq 0 ]; then
export HOME_DIR=/home/multiflow
. $HOME_DIR/scripts/common/setup-env-variables.sh
if [ $PROFILE = "DOCKER-DEV" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/common/start-scripts/tmux-start-dev.sh
fi
fi
/bin/bash $SCRIPT_LOCATION/scripts/dev/cli/attach-tmux.sh
else
echo "$MODE allowed inside Docker only."
fi
fi
if [ $MODE = "--update-images" ]; then
if [ $PROFILE = "LOCAL" ]; then
docker pull "multiflow/multiflow-dev:latest"
docker pull "multiflow/kafka:latest"
else
echo "$MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--purge-images" ]; then
if [ $PROFILE = "LOCAL" ]; then
docker images -f dangling=true | awk '{print $3}' | xargs docker rmi
else
echo "$MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--rebuild-images" ]; then
if [ $PROFILE = "LOCAL" ]; then
allchangescommitted=$(git diff-index --quiet HEAD -- || echo "NO")
allchangescommitted=${allchangescommitted:-YES}
if [ $allchangescommitted = "YES" ]; then
/bin/bash $SCRIPT_LOCATION/scripts/build/build-docker-images-tree.sh -p
else
echo "We detected uncommitted changes: please commit before building the Docker images."
fi
else
echo "$MODE allowed outside Docker only."
fi
fi
if [ $MODE = "--run-tests" ]; then
if [ $PROFILE != "LOCAL" ]; then
cd /home/multiflow && python setup.py test
else
echo "$MODE allowed inside Docker only."
fi
fi
if [ $MODE = "--run-test" ]; then
if [ $PROFILE != "LOCAL" ]; then
pytest $2 --showlocals -v
else
echo "$MODE allowed inside Docker only."
fi
fi
if [ $MODE = "--help" ]; then
if [ $PROFILE = "LOCAL" ]; then
MULTIFLOW_SCRIPT="bash multiflow.sh"
echo "To START DEV environment"
echo " $MULTIFLOW_SCRIPT --start | create a container, using existing volumes"
echo " $MULTIFLOW_SCRIPT --recreate | recreates containers"
echo "To STOP DEV environment"
echo " $MULTIFLOW_SCRIPT --stop | stops existing containers with graceful shutdown"
echo " $MULTIFLOW_SCRIPT --destroy | kills existing containers and disks"
echo "OTHER utilities"
echo " $MULTIFLOW_SCRIPT --into-dev | get into multiflow-dev container"
echo " $MULTIFLOW_SCRIPT --update-images | update local Docker images to latest version"
echo " $MULTIFLOW_SCRIPT --rebuild-images | rebuild our Docker images tree"
echo " $MULTIFLOW_SCRIPT --purge-images | purge Docker dangling images"
else
echo "$MULTIFLOW_SCRIPT --run-tests | run all tests"
echo "$MULTIFLOW_SCRIPT --run-test <TEST-NAME> | run a specific test"
echo "$MULTIFLOW_SCRIPT --attach-tmux | attach tmux session"
echo "$MULTIFLOW_SCRIPT --show-args | display relevant environment variables"
fi
fi