-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmake_docker_compose_yml.sh
executable file
·120 lines (94 loc) · 2.69 KB
/
make_docker_compose_yml.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
#!/bin/bash
###
# // small setup
# $ zookeeper=1 drillbit=1 ./make_docker_compose_yml.sh drill > docker-compose.yml
#
# // hdfs+hbase+drill setup
# ./make_docker_compose_yml.sh hdfs hbase drill > docker-compose.yml
#
# ./make_docker_compose_yml.sh [hdfs] [hbase] [yarn] [drill]
###
DEBUG=${DEBUG:-0}
# docker network name
network_name=${network_name:-"vnet"}
# zookeeper scale size
zookeeper=${zookeeper:-3}
# hdfs scale size
journalnode=${journalnode:-3}
namenode=${namenode:-2}
datanode=${datanode:-3}
# yarn scale size
resourcemanager=${resourcemanager:-1}
historyserver=${historyserver:-1}
nodemanager=${nodemanager:-${datanode}}
# hbase scale size
hmaster=${hmaster:-2}
regionserver=${regionserver:-${datanode}}
# drill scale size
drillbit=${drillbit:-1}
debug() {
[ ${DEBUG} -gt 0 ] && echo "[DEBUG] $@" 1>&2
}
services=()
zk_quorum=()
for z in `seq ${zookeeper}`; do
zk_quorum+=("zookeeper-$z.${network_name}:2181")
done
ZOOKEEPER_QUORUM="$(IFS=,; echo "${zk_quorum[*]}")"
zookeeper_arg=0
for component in $@; do
if [ "${component}" == "zookeeper" ]; then
zookeeper_arg=1
break
fi
done
if [ $zookeeper_arg -eq 0 ]; then
set -- zookeeper $@
fi
for component in $@; do
template=services.${component}.yml.tpl
if [ ! -e ${template} ]; then
continue
fi
debug "Template: $template ..."
service_keys=$(cat $template | sed -e '/^## /!d' | sed -e 's/^##[ ]*//g' )
for k in $service_keys; do
part=$(cat $template \
| sed -e '/^## '${k}'/,/^##\/ '${k}'/!d' \
| sed -e '/^##/d' \
)
KK=$(echo $k | tr '[a-z]' '[A-Z]')
debug $k $KK
scale_size=${!k}
debug $KK scale_size: $scale_size
for i in `seq 1 ${scale_size}`; do
swarm_filter="SWARM_FILTER_${KK}_${i}"
debug $swarm_filter
# replace template variable
filter=""
if [ "${!swarm_filter}" != "" ]; then
filter="- ${!swarm_filter}"
fi
_part=$(echo "$part" \
| sed -e 's/${i}/'$i'/g' \
-e 's/${network_name}/'$network_name'/g' \
-e 's/${scale_size}/'$scale_size'/g' \
-e 's/${ZOOKEEPER_QUORUM}/'$ZOOKEEPER_QUORUM'/g' \
| sed -e 's/${'${swarm_filter}'}/'"${filter}"'/g' \
)
services+=("$_part" "")
done
done
done
# join
docker_compose_services="$(IFS=$'\n'; echo "${services[*]}")"
# output docker-compose.yml v2 format
cat <<EOD
version: "2"
services:
$docker_compose_services
networks:
$network_name:
external:
name: $network_name
EOD