-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
executable file
·70 lines (56 loc) · 2.06 KB
/
docker-entrypoint.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
#!/bin/bash
set -e
set -x
### This is the start of what has been added
if [ -z ${BOOTSTRAP_HOSTNAME} ]; then
echo "Environment variable BOOTSTRAP_HOSTNAME not set"
exit 1
fi
if [ -z ${ADMIN_API_HOSTNAME} ]; then
echo "Environment variable ADMIN_API_HOSTNAME not set"
exit 1
fi
if [ -z ${CKU_COUNT} ]; then
echo "Environment variable CKU_COUNT not set"
exit 1
fi
if [[ ${CKU_COUNT} -eq 1 ]]; then
BROKER_COUNT=4
else
BROKER_COUNT=$((CKU_COUNT * 3))
fi
# Two static parts, two dynamic parts. Like a sandwich.
cp /haproxy_top.cfg /tmp/haproxy_0.cfg
> /tmp/haproxy_1.dcfg
cp /haproxy_middle.cfg /tmp/haproxy_2.cfg
> /tmp/haproxy_3.dcfg
# Generate dynamic files. This could absolutely be more elegant (seds or multiline strings or something),
# but in this case easier to understand is probably better
for (( b = 0; b < BROKER_COUNT; ++b )); do
echo " acl is_broker${b} req.ssl_sni -i b${b}-${BOOTSTRAP_HOSTNAME}" >> /tmp/haproxy_1.dcfg
echo " use_backend broker${b} if is_broker${b}" >> /tmp/haproxy_1.dcfg
echo "" >> /tmp/haproxy_1.dcfg
echo "backend broker${b}" >> /tmp/haproxy_3.dcfg
echo " mode tcp" >> /tmp/haproxy_3.dcfg
echo " server broker${b} b${b}-${BOOTSTRAP_HOSTNAME}:9092 check" >> /tmp/haproxy_3.dcfg
echo "" >> /tmp/haproxy_3.dcfg
done
cat /tmp/haproxy_0.cfg /tmp/haproxy_1.dcfg /tmp/haproxy_2.cfg /tmp/haproxy_3.dcfg > /usr/local/etc/haproxy/haproxy.cfg
sed -i \
-e "s|ADMIN_API_HOSTNAME|${ADMIN_API_HOSTNAME}|g" \
-e "s|BOOTSTRAP_HOSTNAME|${BOOTSTRAP_HOSTNAME}|g" \
/usr/local/etc/haproxy/haproxy.cfg
cat /usr/local/etc/haproxy/haproxy.cfg
### Everything below is copied from the default haproxy docker-entrypoint.sh
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- haproxy "$@"
fi
if [ "$1" = 'haproxy' ]; then
shift # "haproxy"
# if the user wants "haproxy", let's add a couple useful flags
# -W -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2")
# -db -- disables background mode
set -- haproxy -W -db "$@"
fi
exec "$@"