Skip to content

Commit 97551a7

Browse files
committed
Refs #10 - Possibility to change frontend/backend to via environment variables
1 parent 764f8d2 commit 97551a7

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Upgrade to haproxy 1.8
66

7+
- Possibility to change frontend/backend `mode` to `TCP` via environment variables `FRONTEND_MODE` and `BACKENDS_MODE` [refs #10]
8+
79
## 2017-11-30 (1.7-4.1)
810

911
- bugfix add LOG_LEVEL to /etc/environment as well

haproxy/Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ either when running the container or in a `docker-compose.yml` file.
129129
* `STATS_AUTH` The authentication details (written as `user:password` for the statistics page - default `admin:admin`
130130
* `FRONTEND_NAME` The label of the frontend - default `http-frontend`
131131
* `FRONTEND_PORT` The port to bind the frontend to - default `5000`
132+
* `FRONTEND_MODE` Frontend mode - default `http`
132133
* `PROXY_PROTOCOL_ENABLED` The option to enable or disable accepting proxy protocol (`true` stands for enabled, `false` or anything else for disabled) - default `false`
133134
* `COOKIES_ENABLED` The option to enable or disable cookie-based sessions (`true` stands for enabled, `false` or anything else for disabled) - default `false`
134135
* `BACKEND_NAME` The label of the backend - default `http-backend`
135136
* `BACKENDS` The list of `server_ip:server_listening_port` to be load-balanced by HAProxy, separated by space - by default it is not set
136137
* `BACKENDS_PORT` Port to use when auto-discovering backends, or when `BACKENDS` are specified without port - by default `80`
138+
* `BACKENDS_MODE` Backends mode - default `http`
137139
* `BALANCE` The algorithm used for load-balancing - default `roundrobin`
138140
* `SERVICE_NAMES` An optional prefix for services to be included when discovering services separated by space. - by default it is not set
139141
* `LOGGING` Override logging ip address:port - default is udp `127.0.0.1:514` inside container

haproxy/docker-entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fi
3131
#enable cron logging
3232
service rsyslog restart
3333

34-
#add crontab
35-
crontab /var/crontab.txt
34+
#add crontab
35+
crontab /var/crontab.txt
3636
chmod 600 /etc/crontab
3737
service cron restart
3838

@@ -41,6 +41,7 @@ service cron restart
4141
echo "export PATH=$PATH"':$PATH' >> /etc/environment
4242
if [ ! -z "$BACKENDS" ]; then echo "export BACKENDS=\"$BACKENDS\"" >> /etc/environment; fi
4343
if [ ! -z "$BACKENDS_PORT" ]; then echo "export BACKENDS_PORT=\"$BACKENDS_PORT\"" >> /etc/environment; fi
44+
if [ ! -z "$BACKENDS_MODE" ]; then echo "export BACKENDS_MODE=\"$BACKENDS_MODE\"" >> /etc/environment; fi
4445
if [ ! -z "$BACKEND_NAME" ]; then echo "export BACKEND_NAME=\"$BACKEND_NAME\"" >> /etc/environment; fi
4546
if [ ! -z "$BALANCE" ]; then echo "export BALANCE=\"$BALANCE\"" >> /etc/environment; fi
4647
if [ ! -z "$COOKIES_ENABLED" ]; then echo "export COOKIES_ENABLED=\"$COOKIES_ENABLED\"" >> /etc/environment; fi
@@ -49,6 +50,7 @@ if [ ! -z "$FALL" ]; then echo "export FALL=\"$FALL\"" >> /etc/environment; fi
4950
if [ ! -z "$FAST_INTER" ]; then echo "export FAST_INTER=\"$FAST_INTER\"" >> /etc/environment; fi
5051
if [ ! -z "$FRONTEND_NAME" ]; then echo "export FRONTEND_NAME=\"$FRONTEND_NAME\"" >> /etc/environment; fi
5152
if [ ! -z "$FRONTEND_PORT" ]; then echo "export FRONTEND_PORT=\"$FRONTEND_PORT\"" >> /etc/environment; fi
53+
if [ ! -z "$FRONTEND_MODE" ]; then echo "export FRONTEND_MODE=\"$FRONTEND_MODE\"" >> /etc/environment; fi
5254
if [ ! -z "$HTTPCHK" ]; then echo "export HTTPCHK=\"$HTTPCHK\"" >> /etc/environment; fi
5355
if [ ! -z "$INTER" ]; then echo "export INTER=\"$INTER\"" >> /etc/environment; fi
5456
if [ ! -z "$LOGGING" ]; then echo "export LOGGING=\"$LOGGING\"" >> /etc/environment; fi

haproxy/src/configure.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
FRONTEND_NAME = os.environ.get('FRONTEND_NAME', 'http-frontend')
1212
FRONTEND_PORT = os.environ.get('FRONTEND_PORT', '5000')
13+
FRONTEND_MODE = os.environ.get('FRONTEND_MODE', 'http')
1314
BACKEND_NAME = os.environ.get('BACKEND_NAME', 'http-backend')
1415
BALANCE = os.environ.get('BALANCE', 'roundrobin')
1516
SERVICE_NAMES = os.environ.get('SERVICE_NAMES', '')
@@ -19,6 +20,7 @@
1920
STATS_AUTH = os.environ.get('STATS_AUTH', 'admin:admin')
2021
BACKENDS = os.environ.get('BACKENDS', '').split(' ')
2122
BACKENDS_PORT = os.environ.get('BACKENDS_PORT', '80')
23+
BACKENDS_MODE = os.environ.get('BACKEND_MODE', 'http')
2224
LOGGING = os.environ.get('LOGGING', '127.0.0.1')
2325
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'notice')
2426
TIMEOUT_CONNECT = os.environ.get('TIMEOUT_CONNECT', '5000')
@@ -44,7 +46,7 @@
4446
frontend_conf = Template("""
4547
frontend $name
4648
bind *:$port $accept_proxy
47-
mode http
49+
mode $mode
4850
default_backend $backend
4951
""")
5052

@@ -55,7 +57,7 @@
5557
#header with a specific value for each backend server as its cookie value.
5658
backend_conf = Template("""
5759
backend $backend
58-
mode http
60+
mode $mode
5961
balance $balance
6062
option forwardfor
6163
http-request set-header X-Forwarded-Port %[dst_port]
@@ -71,7 +73,7 @@
7173
#cookies variable (is set to empty)
7274
backend_conf = Template("""
7375
backend $backend
74-
mode http
76+
mode $mode
7577
balance $balance
7678
option forwardfor
7779
http-request set-header X-Forwarded-Port %[dst_port]
@@ -93,6 +95,7 @@
9395

9496
backend_conf = backend_conf.substitute(
9597
backend=BACKEND_NAME,
98+
mode=BACKENDS_MODE,
9699
balance=BALANCE,
97100
httpchk=HTTPCHK,
98101
inter=INTER,
@@ -232,6 +235,7 @@
232235
frontend_conf.substitute(
233236
name=FRONTEND_NAME,
234237
port=FRONTEND_PORT,
238+
mode=FRONTEND_MODE,
235239
backend=BACKEND_NAME,
236240
accept_proxy=accept_proxy
237241
)

0 commit comments

Comments
 (0)