-
Notifications
You must be signed in to change notification settings - Fork 0
/
kadlab
executable file
·98 lines (88 loc) · 2.36 KB
/
kadlab
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
#!/bin/bash
# USAGE:
compose=false # -c start many containers with docker compose
swarm=false # -s start many containers with docker swarm
one=false # -o run one single docker container
stop=false # -t stop all docker containers
remove=false # -r remove all docker containers
build=false # -b build docker file
kill=false # -k kill all
exec=false # -e start a terminal for given node ID
id=""
nodes=""
# Parse
while getopts "c:s:otrbke:" opt; do
case $opt in
c)
compose=true
nodes=$OPTARG
;;
s)
swarm=true
nodes=$OPTARG
;;
o)
one=true
;;
t)
stop=true
;;
r)
remove=true
;;
b)
build=true
;;
k)
kill=true
;;
e)
exec=true
id=$OPTARG
;;
esac
done
if [ "$stop" = true ]; then
echo "##### Stopping all containers... #####"
sudo docker stop $(sudo docker ps -aq)
fi
if [ "$remove" = true ]; then
echo "##### Removing all containers... #####"
sudo docker rm -f $(sudo docker ps -aq)
fi
if [ "$kill" = true ]; then
echo "##### Killing all containers... #####"
sudo docker rm -f $(sudo docker ps -aq)
sleep 1
echo "##### Killing service... #####"
sudo docker service rm $(sudo docker service ls -q)
sleep 1
echo "##### Killing network... #####"
sudo docker network rm $(sudo docker network ls -q)
sleep 3
fi
if [ "$build" = true ]; then
echo "##### Building image... #####"
sudo docker build . -t kadlab
fi
if [ "$compose" = true ]; then
echo "##### Starting $nodes containers... #####"
sudo docker-compose --compatibility up -d --scale node="$nodes"
fi
if [ "$swarm" = true ]; then
echo "##### Swarm init... #####"
sudo docker swarm init
echo "##### Starting service... #####"
sudo docker stack deploy -c docker-compose.yml kadlab
echo "##### Starting $nodes containers... #####"
sleep 1
sudo docker service scale kadlab_node=$nodes
fi
if [ "$one" = true ]; then
echo "##### Starting one containers... #####"
sudo docker run kadlab
fi
if [ "$exec" = true ]; then
echo "##### Starting terminal on node $id... #####"
sudo docker exec -it $id sh
fi