Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit b24cb6b

Browse files
author
Feng Honglin
committed
Merge pull request #5 from docker/staging
dockercloud-haproxy 1.1
2 parents b0e63b3 + 0cbec92 commit b24cb6b

39 files changed

Lines changed: 2824 additions & 769 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ output
88

99
# Packages
1010
*.egg
11+
*.eggs
1112
*.egg-info
1213
dist
1314
build
@@ -38,3 +39,4 @@ nosetests.xml
3839
.project
3940
.pydevproject
4041
.idea
42+
.DS_Store

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ ENV RSYSLOG_DESTINATION=127.0.0.1 \
2727
SSL_BIND_CIPHERS="ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA:DES-CBC3-SHA" \
2828
HEALTH_CHECK="check"
2929

30-
3130
EXPOSE 80 443 1936
3231
CMD ["dockercloud-haproxy"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Settings in this part is immutable, you have to redeploy HAProxy service to make
4343
|env var|default|description|
4444
|:-----:|:-----:|:----------|
4545
|DEFAULT_SSL_CERT||Default ssl cert, a pem file content with private key followed by public certificate, '\n'(two chars) as the line separator. should be formatted as one line - see [SSL Termination](#ssl-termination)|
46-
|EXTRA_SSL_CERTS||List of extra certificate names separated by space, eg. `CERT1 CERT2 CERT3`. You also need to specify each certifcate as separate env variables like so: `CERT1="<cert-body1>"`, `CERT2="<cert-body2>"`, `CERT3="<cert-body3>"`|
46+
|EXTRA_SSL_CERTS||List of extra certificate names separated by comma, eg. `CERT1, CERT2, CERT3`. You also need to specify each certifcate as separate env variables like so: `CERT1="<cert-body1>"`, `CERT2="<cert-body2>"`, `CERT3="<cert-body3>"`|
4747
|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)|
4848
|MODE|http|mode of load balancing for HAProxy. Possible values include: `http`, `tcp`, `health`|
4949
|MAXCONN|4096|sets the maximum per-process number of concurrent connections.|
@@ -57,7 +57,7 @@ Settings in this part is immutable, you have to redeploy HAProxy service to make
5757
|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)|
5858
|EXTRA_GLOBAL_SETTINGS|<empty>|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`|
5959
|EXTRA_DEFAULT_SETTINGS|<empty>|comma-separated string of extra settings, and each part will be appended to DEFAULT section in the configuration file. To escape comma, use `\,`|
60-
|EXTRA_BIND_SETTINGS|<empty>|comma-separated string(<port>:<setting>) of extra settings, and each part will be appended to the related port bind section in the configuration file. To escape comma, use `\,`. Possible vaule: `443:accept-proxy, 80:name http`|
60+
|EXTRA_BIND_SETTINGS|<empty>|comma-separated string(`<port>:<setting>`) of extra settings, and each part will be appended to the related port bind section in the configuration file. To escape comma, use `\,`. Possible vaule: `443:accept-proxy, 80:name http`|
6161
|HTTP_BASIC_AUTH|<empty>|a comma-separated list of credentials(`<user>:<pass>`) 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|
6262
|CA_CERT|<empty>|CA cert for haproxy to verify the client. Use the same format as `DEFAULT_SSL_CERT`|
6363
|MONITOR_PORT|<empty>|the port number where monitor_uri should be added to. Use together with `MONTIOR_URI`. Possible value: `80`|

haproxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.1"
1+
__version__ = "1.1"

haproxy/config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import re
3+
4+
from parser import parse_extra_bind_settings
5+
6+
# envvar
7+
DEFAULT_SSL_CERT = os.getenv("DEFAULT_SSL_CERT") or os.getenv("SSL_CERT")
8+
EXTRA_SSL_CERT = os.getenv("EXTRA_SSL_CERTS")
9+
DEFAULT_CA_CERT = os.getenv("CA_CERT")
10+
MAXCONN = os.getenv("MAXCONN", "4096")
11+
MODE = os.getenv("MODE", "http")
12+
OPTION = os.getenv("OPTION", "redispatch, httplog, dontlognull, forwardfor")
13+
RSYSLOG_DESTINATION = os.getenv("RSYSLOG_DESTINATION", "127.0.0.1")
14+
SSL_BIND_CIPHERS = os.getenv("SSL_BIND_CIPHERS")
15+
SSL_BIND_OPTIONS = os.getenv("SSL_BIND_OPTIONS")
16+
STATS_AUTH = os.getenv("STATS_AUTH", "stats:stats")
17+
STATS_PORT = os.getenv("STATS_PORT", "1936")
18+
TIMEOUT = os.getenv("TIMEOUT", "connect 5000, client 50000, server 50000")
19+
HEALTH_CHECK = os.getenv("HEALTH_CHECK", "check inter 2000 rise 2 fall 3")
20+
EXTRA_GLOBAL_SETTINGS = os.getenv("EXTRA_GLOBAL_SETTINGS")
21+
EXTRA_DEFAULT_SETTINGS = os.getenv("EXTRA_DEFAULT_SETTINGS")
22+
EXTRA_BIND_SETTINGS = parse_extra_bind_settings(os.getenv("EXTRA_BIND_SETTINGS"))
23+
HTTP_BASIC_AUTH = os.getenv("HTTP_BASIC_AUTH")
24+
MONITOR_URI = os.getenv("MONITOR_URI")
25+
MONITOR_PORT = os.getenv("MONITOR_PORT")
26+
BALANCE = os.getenv("BALANCE", "roundrobin")
27+
HAPROXY_CONTAINER_URI = os.getenv("DOCKERCLOUD_CONTAINER_API_URI")
28+
HAPROXY_SERVICE_URI = os.getenv("DOCKERCLOUD_SERVICE_API_URI")
29+
API_AUTH = os.getenv("DOCKERCLOUD_AUTH")
30+
DEBUG = os.getenv("DEBUG", False)
31+
32+
# const
33+
CERT_DIR = "/certs/"
34+
CACERT_DIR = "/cacerts/"
35+
HAPROXY_CONFIG_FILE = "/haproxy.cfg"
36+
HAPROXY_RUN_COMMAND = ['/usr/sbin/haproxy', '-f', HAPROXY_CONFIG_FILE, '-db', '-q']
37+
API_RETRY = 10 # seconds
38+
PID_FILE = "/tmp/dockercloud-haproxy.pid"
39+
40+
SERVICE_NAME_MATCH = re.compile(r"(.+)_\d+$")
41+
BACKEND_MATCH = re.compile(r"(?P<proto>tcp|udp):\/\/(?P<addr>[^:]*):(?P<port>.*)")
42+
SERVICE_ALIAS_MATCH = re.compile(r"_PORT_\d{1,5}_(TCP|UDP)$")
43+
DETAILED_SERVICE_ALIAS_MATCH = re.compile(r"_\d+_PORT_\d{1,5}_(TCP|UDP)$")
44+
ENV_SERVICE_ALIAS_MATCH = re.compile(r"_ENV_")
45+
ENV_DETAILED_SERVICE_ALIAS_MATCH = re.compile(r"_\d+_ENV")

haproxy/eventhandler.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import logging
2+
3+
import config
4+
from haproxycfg import run_haproxy, Haproxy
5+
from utils import get_uuid_from_resource_uri
6+
7+
logger = logging.getLogger("haproxy")
8+
9+
10+
def on_cloud_event(event):
11+
logger.debug(event)
12+
logger.debug(Haproxy.cls_linked_services)
13+
# When service scale up/down or container start/stop/terminate/redeploy, reload the service
14+
if event.get("state", "") not in ["In progress", "Pending", "Terminating", "Starting", "Scaling", "Stopping"] and \
15+
event.get("type", "").lower() in ["container", "service"] and \
16+
len(set(Haproxy.cls_linked_services).intersection(set(event.get("parents", [])))) > 0:
17+
msg = "Event: %s %s is %s" % (
18+
event["type"], get_uuid_from_resource_uri(event.get("resource_uri", "")), event["state"].lower())
19+
run_haproxy(msg)
20+
21+
# Add/remove services linked to haproxy
22+
if event.get("state", "") == "Success" and config.HAPROXY_SERVICE_URI in event.get("parents", []):
23+
run_haproxy("Event: New action is executed on the Haproxy container")
24+
25+
26+
def on_websocket_open():
27+
Haproxy.LINKED_CONTAINER_CACHE.clear()
28+
run_haproxy("Websocket open")
29+
30+
31+
def on_websocket_close():
32+
logger.info("Websocket close")
33+
34+
35+
def on_user_reload(signum, frame):
36+
run_haproxy("User reload")

0 commit comments

Comments
 (0)