Skip to content

Commit 6f355f6

Browse files
author
valentinab25
committed
Add cookie declaration parameters
1 parent d45b605 commit 6f355f6

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

haproxy/Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,14 @@ 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`
132+
* `FRONTEND_MODE` Frontend mode - default `http` or `BACKENDS_MODE` if declared
133133
* `PROXY_PROTOCOL_ENABLED` The option to enable or disable accepting proxy protocol (`true` stands for enabled, `false` or anything else for disabled) - default `false`
134134
* `COOKIES_ENABLED` The option to enable or disable cookie-based sessions (`true` stands for enabled, `false` or anything else for disabled) - default `false`
135+
* `COOKIES_PARAMS` Will be added on cookie declaration - example `indirect nocache maxidle 30m maxlife 8h` or `maxlife 24h` - documentation https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-cookie
135136
* `BACKEND_NAME` The label of the backend - default `http-backend`
136137
* `BACKENDS` The list of `server_ip:server_listening_port` to be load-balanced by HAProxy, separated by space - by default it is not set
137138
* `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`
139+
* `BACKENDS_MODE` Backends mode - default `http` or `FRONTEND_MODE` if declared
139140
* `BALANCE` The algorithm used for load-balancing - default `roundrobin`
140141
* `SERVICE_NAMES` An optional prefix for services to be included when discovering services separated by space. - by default it is not set
141142
* `LOGGING` Override logging ip address:port - default is udp `127.0.0.1:514` inside container

haproxy/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if ! test -e /etc/haproxy/haproxy.cfg; then
3737
if [ ! -z "$BACKEND_NAME" ]; then echo "export BACKEND_NAME=\"$BACKEND_NAME\"" >> /etc/environment; fi
3838
if [ ! -z "$BALANCE" ]; then echo "export BALANCE=\"$BALANCE\"" >> /etc/environment; fi
3939
if [ ! -z "$COOKIES_ENABLED" ]; then echo "export COOKIES_ENABLED=\"$COOKIES_ENABLED\"" >> /etc/environment; fi
40+
if [ ! -z "$COOKIES_PARAMS" ]; then echo "export COOKIES_PARAMS=\"$COOKIES_PARAMS\"" >> /etc/environment; fi
4041
if [ ! -z "$DOWN_INTER" ]; then echo "export DOWN_INTER=\"$DOWN_INTER\"" >> /etc/environment; fi
4142
if [ ! -z "$FALL" ]; then echo "export FALL=\"$FALL\"" >> /etc/environment; fi
4243
if [ ! -z "$FAST_INTER" ]; then echo "export FAST_INTER=\"$FAST_INTER\"" >> /etc/environment; fi

haproxy/src/configure.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
BALANCE = os.environ.get('BALANCE', 'roundrobin')
1616
SERVICE_NAMES = os.environ.get('SERVICE_NAMES', '')
1717
COOKIES_ENABLED = (os.environ.get('COOKIES_ENABLED', 'false').lower() == "true")
18+
COOKIES_PARAMS = os.environ.get('COOKIES_PARAMS','')
1819
PROXY_PROTOCOL_ENABLED = (os.environ.get('PROXY_PROTOCOL_ENABLED', 'false').lower() == "true")
1920
STATS_PORT = os.environ.get('STATS_PORT', '1936')
2021
STATS_AUTH = os.environ.get('STATS_AUTH', 'admin:admin')
@@ -60,7 +61,7 @@
6061
mode $mode
6162
balance $balance
6263
default-server inter $inter fastinter $fastinter downinter $downinter fall $fall rise $rise
63-
cookie SRV_ID insert
64+
cookie SRV_ID insert $cookies_params
6465
""")
6566
cookies = "cookie \\\"@@value@@\\\""
6667
else:
@@ -72,11 +73,10 @@
7273
mode $mode
7374
balance $balance
7475
default-server inter $inter fastinter $fastinter downinter $downinter fall $fall rise $rise
75-
cookie SRV_ID prefix
76+
cookie SRV_ID prefix $cookies_params
7677
""")
7778
cookies = ""
7879

79-
8080
backend_type_http = Template("""
8181
option forwardfor
8282
http-request set-header X-Forwarded-Port %[dst_port]
@@ -101,7 +101,8 @@
101101
fastinter=FAST_INTER,
102102
downinter=DOWN_INTER,
103103
fall=FALL,
104-
rise=RISE
104+
rise=RISE,
105+
cookies_params=COOKIES_PARAMS
105106
)
106107

107108
if BACKENDS_MODE == 'http':

0 commit comments

Comments
 (0)