-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmule.sh
executable file
·135 lines (119 loc) · 3.37 KB
/
mule.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
#!/usr/bin/env bash
# Defaults
DO_KILL=false
DO_BUILD=false
DO_RUN=false
ATTACHED=false
SQL_SLEEP_MAX=2 # seconds
LOOP_COUNT=100
POOL_SIZE=400
TARGET_URL="http://127.0.0.1:9000/sleep"
# Functions
function main() {
define_image
build_image
kill_previous_container
launch_container
}
function define_image() {
if [[ -z "$IMAGE" ]]
then
echo "++ Working with image name taken from current working directory"
IMAGE=$(basename $(pwd))
fi
NAME="${IMAGE}_container"
}
function build_image() {
if [[ "$DO_BUILD" = true ]];
then
echo "++ Building image..."
docker build -t ${IMAGE} .
else
echo "-- Skip building of image..."
fi
}
function kill_previous_container() {
if [[ "$DO_KILL" = true ]];
then
echo "++ Killing existing container..."
docker rm -f "${IMAGE}_container"
else
echo "-- Skip killing of previously run container..."
fi
}
function launch_container() {
if [[ "$DO_RUN" = true ]];
then
CMD="docker run --name=$NAME --rm "
if [[ "$ATTACHED" = false ]];
then
CMD="${CMD} -d "
fi
CMD="${CMD} -e SQL_SLEEP_MAX=${SQL_SLEEP_MAX} -e LOOP_COUNT=${LOOP_COUNT} -e POOL_SIZE=${POOL_SIZE} -e TARGET_URL=${TARGET_URL}"
CMD="${CMD} --net=host $IMAGE"
echo "++ Launching container..."
eval ${CMD}
else
echo "-- Skip running container..."
fi
}
function build_all_images() {
DO_BUILD=true
root_test="/shared"
root=$(pwd)
if [[ ! "$root" = "$root_test" ]];
then
echo "You must be in repo's root dir: ${root_test}"
echo "current dir is ${root}"
exit 1
fi
image_dirs=$(find . -type f -name 'processname.txt' | sed -r 's|/[^/]+$||' | sort | uniq)
for f in $image_dirs; do
echo "cd into ${f}"
cd "$f"
echo '----'
define_image
build_image
cd "$root"
IMAGE=""
done
}
function show_usage() {
cat << EOF
-------------------------------------------
This script runs docker container for specific framework.
OPTIONS:
-x Build docker images for all frameworks (useful for a newly deployed machine)
-d Directory name of the framework service (if not specified, defaults to the current directory)
-r Run container? (default: $DO_RUN)
-b Build image? (default: $DO_BUILD)
-k Kill the previously run container? (default: $DO_KILL)
-a Attach container's TTY? (default: $ATTACHED)
-l Max loop count for service load. Docker container env variable LOOP_COUNT (default: $LOOP_COUNT)
-s Max sleep seconds for DB call. Docker container env variable SQL_SLEEP_MAX (default: $SQL_SLEEP_MAX)
-p Postgres pool size (min & max). Docker container env variable POOL_SIZE (default: $POOL_SIZE)
-u URL to make http requests to (default: $TARGET_URL)
-h Show script usage
-------------------------------------------
EOF
}
# Running Main!
while getopts d:p:u:l:s:ahkbrx option
do
case "${option}"
in
d) IMAGE=${OPTARG};;
r) DO_RUN=true;;
k) DO_KILL=true;;
b) DO_BUILD=true;;
a) ATTACHED=true;;
l) LOOP_COUNT=${OPTARG};;
s) SQL_SLEEP_MAX=${OPTARG};;
p) POOL_SIZE=${OPTARG};;
u) TARGET_URL=${OPTARG};;
x) build_all_images; exit;;
h) show_usage; exit;;
\?) show_usage; exit;;
esac
done
main