Skip to content

Commit ce81071

Browse files
committed
add config templating
1 parent 8742884 commit ce81071

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ENV ALLOW_RESTARTS=0 \
99
COMMIT=0 \
1010
CONFIGS=0 \
1111
CONTAINERS=0 \
12+
DISABLE_IPV6=0 \
1213
DISTRIBUTION=0 \
1314
EVENTS=1 \
1415
EXEC=0 \
@@ -30,4 +31,5 @@ ENV ALLOW_RESTARTS=0 \
3031
TASKS=0 \
3132
VERSION=1 \
3233
VOLUMES=0
33-
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
34+
COPY docker-entrypoint.sh /usr/local/bin/
35+
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg.template

docker-entrypoint.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Normalize the input for DISABLE_IPV6 to lowercase
5+
DISABLE_IPV6_LOWER=$(echo "$DISABLE_IPV6" | tr '[:upper:]' '[:lower:]')
6+
7+
# Check for different representations of 'true' and set BIND_CONFIG
8+
case "$DISABLE_IPV6_LOWER" in
9+
1|true|yes)
10+
BIND_CONFIG=":2375"
11+
;;
12+
*)
13+
BIND_CONFIG="[::]:2375 v4v6"
14+
;;
15+
esac
16+
17+
# Process the HAProxy configuration template using sed
18+
sed "s/\${BIND_CONFIG}/$BIND_CONFIG/g" /usr/local/etc/haproxy/haproxy.cfg.template > /usr/local/etc/haproxy/haproxy.cfg
19+
20+
# first arg is `-f` or `--some-option`
21+
if [ "${1#-}" != "$1" ]; then
22+
set -- haproxy "$@"
23+
fi
24+
25+
if [ "$1" = 'haproxy' ]; then
26+
shift # "haproxy"
27+
# if the user wants "haproxy", let's add a couple useful flags
28+
# -W -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2")
29+
# -db -- disables background mode
30+
set -- haproxy -W -db "$@"
31+
fi
32+
33+
exec "$@"

haproxy.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ backend docker-events
4444
timeout server 0
4545

4646
frontend dockerfrontend
47-
bind :::2375 v4v6
47+
bind ${BIND_CONFIG}
4848
http-request deny unless METH_GET || { env(POST) -m bool }
4949
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/((stop)|(restart)|(kill)) } { env(ALLOW_RESTARTS) -m bool }
5050
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/start } { env(ALLOW_START) -m bool }

0 commit comments

Comments
 (0)