diff --git a/README.md b/README.md index efd3a80..e043b27 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ Settings in this part is immutable, you have to redeploy HAProxy service to make |Environment Variable|Default|Description| |:-----:|:-----:|:----------| +|ADDITIONAL_BACKENDS| |list of additional backends to balance. The format is `backend name, FORCE_SSL(True|False), server name, host:port, options`| |ADDITIONAL_SERVICES| |list of additional services to balance (es: `prj1:web,prj2:sql`). Discovery will be based on `com.docker.compose.[project|service]` container labels. This environment variable only works on compose v2, and the referenced services must be on a network resolvable and accessible to this containers.| |BALANCE|roundrobin|load balancing algorithm to use. Possible values include: `roundrobin`, `static-rr`, `source`, `leastconn`. See:[HAProxy:balance](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-balance)| |CA_CERT_FILE| |the path of a ca-cert file. This allows you to mount your ca-cert file directly from a volume instead of from envvar. If set, `CA_CERT` envvar will be ignored. Possible value: `/cacerts/cert0.pem`| @@ -182,6 +183,7 @@ Settings in this part is immutable, you have to redeploy HAProxy service to make |EXTRA_GLOBAL_SETTINGS| |comma-separated string of extra settings, and each part will be appended to GLOBAL section in the configuration file. To escape comma, use `\,`. Possible value: `tune.ssl.cachesize 20000, tune.ssl.default-dh-param 2048`| |EXTRA_ROUTE_SETTINGS| |a string which is append to the each backend route after the health check, can be over written in the linked services. Possible value: "send-proxy"| |EXTRA_SSL_CERTS| |list of extra certificate names separated by comma, eg. `CERT1, CERT2, CERT3`. You also need to specify each certificate as separate env variables like so: `CERT1=""`, `CERT2=""`, `CERT3=""`| +|FORCE_DEFAULT_BACKEND| True | set the default_service as a default backend. This is useful when you have more than one backend and you don't want your default_service as a default backend |HEALTH_CHECK|check|set health check on each backend route, possible value: "check inter 2000 rise 2 fall 3". See:[HAProxy:check](https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#5.2-check)| |HTTP_BASIC_AUTH| |a comma-separated list of credentials(`:`) for HTTP basic auth, which applies to all the backend routes. To escape comma, use `\,`. *Attention:* DO NOT rely on this for authentication in production| |MAXCONN|4096|sets the maximum per-process number of concurrent connections.| @@ -477,4 +479,4 @@ Legacy links: In most cases, `dockercloud/haproxy` will configure itself automatically when the linked services change, you don't need to reload it manually. But for some reason, if you have to do so, here is how: * `docker exec /reload.sh`, if you are on the node where dockercloud/haproxy deploys -* `docker-cloud exec /reload.sh`, if you use docker-cloud cli +* `docker-cloud exec /reload.sh`, if you use docker-cloud cli \ No newline at end of file diff --git a/haproxy/config.py b/haproxy/config.py index 4a619c8..7fcea65 100644 --- a/haproxy/config.py +++ b/haproxy/config.py @@ -28,8 +28,23 @@ def parse_extra_frontend_settings(envvars): settings_dict[port] = settings return settings_dict +def parse_additional_backend_settings(envvars): + settings_dict = {} + if isinstance(envvars, os._Environ) or isinstance(envvars, dict): + frontend_settings_pattern = re.compile(r"^ADDITIONAL_BACKEND_(\w{1,9})$") + for k, v in envvars.iteritems(): + match = frontend_settings_pattern.match(k) + if match: + server = match.group(1) + settings = [x.strip().replace("\,", ",") for x in re.split(r'(?