-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn-containers.sh
executable file
·67 lines (54 loc) · 1.29 KB
/
spawn-containers.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
if [[ $# -eq 0 ]] ; then
echo "Number of containers to spawn is not given, spawning 10 containers"
N=10
else
N=$1
fi
OUT_FILE="docker-compose.yml"
CONFIG_FILE="./config/server-info"
docker-compose down
docker image prune -f
NETWORK="172.172.1.0"
NETWORK_HEX=$(printf '%.2X%.2X%.2X%.2X\n' `echo $NETWORK | sed -e 's/\./ /g'`)
START_PORT=4000
function inc_ip {
ip=$1
inc=$2
ip_hex=$(printf %.8X `echo $(( 0x$ip + $inc ))`)
r_ip=$(printf '%d.%d.%d.%d\n' `echo $ip_hex | sed -r 's/(..)/0x\1 /g'`)
echo "$r_ip"
}
function write_service {
idx=$1
servicePort=$((START_PORT + idx))
ip_inc=$((idx + 1))
host=$(inc_ip $NETWORK_HEX $ip_inc)
echo "node$idx $host $servicePort" >> "$CONFIG_FILE"
cat >> "$OUT_FILE" << EOF
kv$idx:
build: ./docker/.
expose:
- "22"
- "$servicePort"
networks:
performance_test_ntwrk:
ipv4_address: $host
volumes:
- "./:/home/ecs"
EOF
}
echo -n "" > "$CONFIG_FILE"
echo "version: '3'" > "$OUT_FILE"
echo "services:" >> "$OUT_FILE"
for i in `seq 1 $N`; do
write_service $i
done
cat >> "$OUT_FILE" << EOF
networks:
performance_test_ntwrk:
ipam:
driver: default
config:
- subnet: $NETWORK/24
EOF
docker-compose up --build -d