This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Websocket Example
Jason Kölker edited this page Apr 18, 2019
·
4 revisions
NOTE In marathon-lb 1.12.x it is necessary to also override HAPROXY_0_HTTP_BACKEND_REVPROXY_GLUE
as follows:
"HAPROXY_0_HTTP_BACKEND_REVPROXY_GLUE": " acl hdr_location res.hdr(Location) -m found\n rspirep \"^Location: (https?://{hostname}(:[0-9]+)?)?(/.*)\" \"Location:\\ {rootpath}\\3\" if hdr_location\n"
This has been fixed in 96b045f0 and will be included in the next release.
In order to upgrade the connection to a websocket, modify the HAPROXY_0_HTTP_FRONTEND_ACL
label adding and acl and having it use that backend (\\n acl is_websocket hdr(Upgrade) -i WebSocket\\n use_backend {backend} if is_websocket
):
"HAPROXY_0_HTTP_FRONTEND_ACL": " acl host_{cleanedUpHostname} hdr(host) -i {hostname}\\n use_backend {backend} if host_{cleanedUpHostname}\\n acl is_websocket hdr(Upgrade) -i WebSocket\\n use_backend {backend} if is_websocket",
Make sure to include the default portion of HAPROXY_0_HTTP_FRONTEND_ACL
.
A full example of a deployment that just echos on the websocket is as follows:
{
"id": "/websocket",
"user":"root",
"cmd": "/bin/sh -c \"wget https://github.com/vi/websocat/releases/download/v1.2.0/websocat_amd64-linux-static -O /websocat && chmod +x /websocat && /websocat --text --exit-on-eof ws-l:0.0.0.0:1234 mirror:\"",
"container": {
"portMappings": [
{
"containerPort": 1234,
"hostPort": 0,
"protocol": "tcp"
}
],
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "alpine"
}
},
"cpus": 0.1,
"instances": 4,
"labels": {
"HAPROXY_GROUP": "external",
"HAPROXY_0_HTTP_FRONTEND_ACL": " acl host_{cleanedUpHostname} hdr(host) -i {hostname}\\n use_backend {backend} if host_{cleanedUpHostname}\\n acl is_websocket hdr(Upgrade) -i WebSocket\\n use_backend {backend} if is_websocket",
"HAPROXY_0_HTTP_BACKEND_PROXYPASS_PATH": "/websocket",
"HAPROXY_0_HTTP_BACKEND_REVPROXY_PATH": "/",
"HAPROXY_0_PATH": "/websocket",
"HAPROXY_0_VHOST": "vhost.example.com",
"HAPROXY_0_ENABLED": "true"
},
"mem": 32,
"networks": [
{
"mode": "container/bridge"
}
],
"requirePorts": false
}