Skip to content

Commit ebd87c9

Browse files
committed
More configurable parameters
1 parent 2f86ff9 commit ebd87c9

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

services/rabbit/docker-compose.yml.j2

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ services:
55
image: haproxy:3.2
66
deploy:
77
# https://discourse.haproxy.org/t/haproxy-high-availability-configuration/11983
8-
replicas: 2
8+
replicas: ${RABBIT_LB_REPLICAS}
99
# necessary to preserve client ip
1010
# otherwise we see overlay network lb ip
1111
# (rabbitmq management dashboard connection section)
1212
endpoint_mode: dnsrr
1313
# healthcheck: https://github.com/haproxy/haproxy/issues/3091
1414
networks:
1515
- rabbit
16+
- public
1617
configs:
1718
- source: haproxy.cfg
1819
target: /usr/local/etc/haproxy/haproxy.cfg
20+
1921
{% for ix in NODE_IXS %}
2022
rabbit0{{ ix }}:
2123
image: itisfoundation/rabbitmq:4.1.2-management
@@ -27,9 +29,11 @@ services:
2729
constraints:
2830
- node.labels.rabbit0{{ ix }} == true
2931
environment:
32+
# https://www.rabbitmq.com/docs/configure#supported-environment-variables
3033
RABBITMQ_DEFAULT_USER: ${RABBIT_USER}
3134
RABBITMQ_DEFAULT_PASS: ${RABBIT_PASSWORD}
3235
RABBITMQ_NODENAME: {% raw %}"rabbit@{{.Service.Name}}"{% endraw %}
36+
RABBITMQ_NODE_PORT: ${RABBIT_PORT}
3337
# https://docs.docker.com/reference/compose-file/services/#long-syntax-5
3438
# https://hub.docker.com/_/rabbitmq#erlang-cookie
3539
secrets:
@@ -97,21 +101,20 @@ volumes:
97101
{%- endfor %}
98102

99103
networks:
100-
# TODO: consider creating it externally for better control over subnets size and ip ranges
101104
rabbit:
102-
name: ${RABBIT_DOCKER_SWARM_NETWORK_NAME}
103-
driver: overlay
104-
attachable: true
105+
name: ${RABBIT_NETWORK}
106+
external: true
105107

106108
configs:
107109
rabbitmq.conf:
110+
# no rolling update since it requires full cluster restart
108111
file: ./rabbitmq.conf
109112
haproxy.cfg:
110113
file: ./haproxy.cfg
111114
name: ${STACK_NAME}_haproxy_conf_{{ "./haproxy.cfg" | sha256file | substring(0,10) }}
112115

113116
secrets:
114117
rabbit_erlang_cookie:
115-
# TODO: rolling secrets update?
118+
# no rolling update since it requires full cluster restart
116119
name: ${STACK_NAME}_erlang_cookie
117120
file: ./erlang.cookie.secret

services/rabbit/haproxy.cfg.j2

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% set NODE_IXS = range(1, (RABBIT_CLUSTER_NODE_COUNT | int) + 1) -%}
2+
13
global
24
log stdout format raw local0
35
maxconn 4096
@@ -29,20 +31,20 @@ defaults
2931
timeout server 30s
3032

3133
frontend rabbit
32-
bind *:5672
34+
bind *:{{ RABBIT_PORT }}
3335
default_backend rabbit_backends
3436

3537
frontend rabbit_dashboard
36-
bind *:15672
38+
bind *:{{ RABBIT_MANAGEMENT_PORT }}
3739
default_backend rabbit_dashboard_backends
3840

3941
backend rabbit_backends
4042
balance roundrobin
4143

42-
# init-addrs libc,none - start even if there aren’t any running
43-
server rabbit01 rabbit_rabbit01:5672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3 send-proxy
44-
server rabbit02 rabbit_rabbit02:5672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3 send-proxy
45-
server rabbit03 rabbit_rabbit03:5672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3 send-proxy
44+
# init-addrs libc,none - start even if there aren’t any backend servers running
45+
{% for ix in NODE_IXS %}
46+
server rabbit0{{ ix }} rabbit_rabbit0{{ ix }}:{{ RABBIT_PORT }} check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3 send-proxy
47+
{%- endfor %}
4648

4749
backend rabbit_dashboard_backends
4850
mode http
@@ -52,6 +54,7 @@ backend rabbit_dashboard_backends
5254
http-request set-header X-Forwarded-Port %[dst_port]
5355
http-request add-header X-Forwarded-Proto https if { ssl_fc }
5456

55-
server rabbit01 rabbit_rabbit01:15672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3
56-
server rabbit02 rabbit_rabbit02:15672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3
57-
server rabbit03 rabbit_rabbit03:15672 check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3
57+
{% for ix in NODE_IXS %}
58+
server rabbit0{{ ix }} rabbit_rabbit0{{ ix }}:{{ RABBIT_MANAGEMENT_PORT }} check resolvers dockerdns init-addr libc,none inter 5s rise 2 fall 3
59+
{%- endfor %}
60+
# keep new line in the end to avoid "Missing LF on last line" error

services/rabbit/template.env

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ RABBIT_QUORUM_QUEUE_DEFAULT_REPLICA_COUNT=${RABBIT_QUORUM_QUEUE_DEFAULT_REPLICA_
55

66
RABBIT_USER=${RABBIT_USER}
77
RABBIT_PASSWORD=${RABBIT_PASSWORD}
8+
RABBIT_PORT=${RABBIT_PORT}
9+
RABBIT_MANAGEMENT_PORT=${RABBIT_MANAGEMENT_PORT}
10+
811
RABBIT_ERLANG_COOKIE=${RABBIT_ERLANG_COOKIE}
12+
RABBIT_LB_REPLICAS=${RABBIT_LB_REPLICAS}
13+
RABBIT_NETWORK=${RABBIT_NETWORK}
914

10-
RABBIT_DOCKER_SWARM_NETWORK_NAME=rabbit_rabbit_subnet
15+
PUBLIC_NETWORK=${PUBLIC_NETWORK}
16+
MONITORING_DOMAIN=${MONITORING_DOMAIN}

0 commit comments

Comments
 (0)