-
Notifications
You must be signed in to change notification settings - Fork 0
/
haproxy.cfg
70 lines (50 loc) · 2.22 KB
/
haproxy.cfg
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
global
# enable runtime api via socket, run this inside the container
# echo "get var proc.strategy" | socat stdio unix-connect:/tmp/haproxy.sock
# see https://www.haproxy.com/documentation/haproxy-runtime-api/
stats socket /tmp/haproxy.sock user haproxy group haproxy mode 660 level admin
# strategy can be either "PERCENTAGE" or "COOKIE"
set-var proc.strategy env(STRATEGY)
# default some environment variables
presetenv PERCENTAGE_NEW "0"
presetenv PERCENTAGE_OLD "100"
# we source them from the environment here to actually typecheck them
set-var proc.percentage_new int("${PERCENTAGE_NEW}")
set-var proc.percentage_old int("${PERCENTAGE_OLD}")
#log stdout format raw local0
defaults
timeout connect 5s
timeout client 1m
timeout server 1m
mode http
#log global
#option httplog
frontend http-in
bind *:80
# the cookie name for the "COOKIE" strategy e.g. (cookie_name=cookie_value)
acl is_new_cookie hdr_sub(cookie) "$COOKIE_STRATEGY_NAME" --
# decide on the strategy
acl routing_strategy_percentage var(proc.strategy) -m str "PERCENTAGE"
acl routing_strategy_cookie var(proc.strategy) -m str "COOKIE"
# default use the old_domain backend
default_backend old_domain
# when using the "PERCENTAGE" strategy, we route to the percentage_strategy backend
use_backend percentage_strategy if routing_strategy_percentage
# when using the "COOKIE" strategy and the cookie matches, we route to the cookie_strategy backend
use_backend cookie_strategy if routing_strategy_cookie is_new_cookie
backend old_domain
http-response set-header X-Proxy-Flow route-to-legacy
option tcp-check
server default_old "$OLD_DOMAIN" check ssl verify none
backend percentage_strategy
http-response set-header X-Proxy-Flow route-to-percentage
option tcp-check
cookie "$COOKIE_PERCENTAGE_NAME" insert indirect
# old domain
server old_domain_percentage "$OLD_DOMAIN" check cookie old_domain ssl verify none weight "$PERCENTAGE_OLD"
# new domain
server new_domain_percentage "$NEW_DOMAIN" check cookie new_domain ssl verify none weight "$PERCENTAGE_NEW"
backend cookie_strategy
http-response set-header X-Proxy-Flow route-to-new
option tcp-check
server default_new "$NEW_DOMAIN" check ssl verify none