1
0
Fork 0

Inverted order of the definitions

This commit is contained in:
Joao M 2022-08-12 02:01:11 +00:00
parent d278629671
commit c62834c52b
10 changed files with 59 additions and 58 deletions

View file

@ -86,13 +86,13 @@ Important: easyhaproxy needs to be in the same network of the containers or othe
| Tag | Description | Example |
|------------------------------------|---------------------------------------------------------------------------------------------------------|--------------|
| easyhaproxy.definitions | A Comma delimited list with the definitions. Each name requires the definition of the parameters below. | service,service2 |
| easyhaproxy.mode.[definition] | (Optional) Is this `http` or `tcp` mode in HAProxy. (Defaults to http) | http |
| easyhaproxy.port.[definition] | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) | 80 |
| easyhaproxy.localport.[definition] | (Optional) What is the port that the container is listening. (Defaults to 80) | 8080 |
| easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. | somehost.com |
| easyhaproxy.redirect.[definition] | (Optional) Host redirects from connections in the port defined above. | foo.com--https://bla.com,bar.com--https://bar.org |
| easyhaproxy.sslcert.[definition] | (Optional) Cert PEM Base64 encoded. | |
| easyhaproxy.health-check.[definition] | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | |
| easyhaproxy.[definition].mode | (Optional) Is this `http` or `tcp` mode in HAProxy. (Defaults to http) | http |
| easyhaproxy.[definition].port | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) | 80 |
| easyhaproxy.[definition].localport | (Optional) What is the port that the container is listening. (Defaults to 80) | 8080 |
| easyhaproxy.[definition].host | What is the host that the HAProxy will listen to. | somehost.com |
| easyhaproxy.[definition].redirect | (Optional) Host redirects from connections in the port defined above. | foo.com--https://bla.com,bar.com--https://bar.org |
| easyhaproxy.[definition].sslcert | (Optional) Cert PEM Base64 encoded. | |
| easyhaproxy.[definition].health-check | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | |
### Defining the labels in Docker Swarm
@ -113,8 +113,8 @@ services:
```bash
docker run \
-l easyhaproxy.definitions=webapi \
-l easyhaproxy.port.webapi=80\
-l easyhaproxy.host.webapi=byjg.com.br \
-l easyhaproxy.webapi.port=80\
-l easyhaproxy.webapi.host=byjg.com.br \
....
```
@ -124,13 +124,13 @@ docker run \
docker run \
-l easyhaproxy.definitions=express,admin \
-l easyhaproxy.port.express=80 \
-l easyhaproxy.localport.express=3000 \
-l easyhaproxy.host.express=express.byjg.com.br \
-l easyhaproxy.express.port=80 \
-l easyhaproxy.express.localport=3000 \
-l easyhaproxy.express.host=express.byjg.com.br \
-l easyhaproxy.port.admin=80 \
-l easyhaproxy.localport.admin=3001 \
-l easyhaproxy.host.admin=admin.byjg.com.br \
-l easyhaproxy.admin.port=80 \
-l easyhaproxy.admin.localport=3001 \
-l easyhaproxy.admin.host=admin.byjg.com.br \
.... \
some/myimage
```
@ -142,9 +142,9 @@ Used to pass on SSL-termination to a backend:
```bash
docker run \
-l easyhaproxy.defintions=example \
-l easyhaproxy.mode.example=tcp \
-l easyhaproxy.health-check.example=ssl \
-l easyhaproxy.port.example=443
-l easyhaproxy.example.mode=tcp \
-l easyhaproxy.example.health-check=ssl \
-l easyhaproxy.example.port=443
.... \
some/tcp-service
```
@ -155,7 +155,7 @@ docker run \
```bash
docker run \
-l easyhaproxy.redirect.<defintion>=www.byjg.com.br--http://byjg.com.br,byjg.com--http://byjg.com.br
-l easyhaproxy.[definition].redirect=www.byjg.com.br--http://byjg.com.br,byjg.com--http://byjg.com.br
```
## DISCOVER: static
@ -236,7 +236,7 @@ MIIEojCCA4qgAwIBAgIUegW2BimwuL4RzRZ2WYkHA6U5nkAwDQYJKoZIhvcNAQEL
cat single.pem | base64 -w0
```
3. Use this string to define the label `easyhaproxy.sslcert.[definition]`
3. Use this string to define the label `easyhaproxy.[definition].sslcert`
## Setting Custom Errors

View file

@ -81,24 +81,24 @@ class HaproxyConfigGenerator:
definitions = d[self.label.create("definitions")].split(",")
for definition in definitions:
mode = self.label.get(
self.label.create(["mode", definition]),
self.label.create([definition, "mode"]),
"http"
)
# TODO: we can ignore "host" in TCP, but it would break the template
host_label = self.label.create(["host", definition])
host_label = self.label.create([definition, "host"])
if not self.label.has_label(host_label):
continue
port = self.label.get(
self.label.create(["port", definition]),
self.label.create([definition, "port"]),
"80"
)
hash = ""
if self.label.create(["sslcert", definition]) in d:
if self.label.create([definition, "sslcert"]) in d:
hash = hashlib.md5(
d[self.label.create(["sslcert", definition])].encode('utf-8')
d[self.label.create([definition, "sslcert"])].encode('utf-8')
).hexdigest()
key = port if not hash else port + "_" + hash
@ -114,12 +114,12 @@ class HaproxyConfigGenerator:
# TODO: this could use `EXPOSE` from `Dockerfile`?
ct_port = self.label.get(
self.label.create(["localport", definition]),
self.label.create([definition, "localport"]),
"80"
)
easymapping[key]["health-check"] = self.label.get(
self.label.create(["health-check", definition]),
self.label.create([definition, "health-check"]),
""
)
@ -127,7 +127,7 @@ class HaproxyConfigGenerator:
easymapping[key]["hosts"][d[host_label]] += ["{}:{}".format(container, ct_port)]
# handle SSL
ssl_label = self.label.create(["sslcert", definition])
ssl_label = self.label.create([definition, "sslcert"])
if self.label.has_label(ssl_label):
self.ssl_cert_increment += 1
filename = "{}/{}.{}.pem".format(
@ -141,7 +141,7 @@ class HaproxyConfigGenerator:
# handle redirects
redirect = self.label.get(
self.label.create(["redirect", definition])
self.label.create([definition, "redirect"])
)
if len(redirect) > 0:
for r in redirect.split(","):

File diff suppressed because one or more lines are too long

View file

@ -32,8 +32,8 @@ services:
labels:
easyhaproxy.definitions: "http"
easyhaproxy.redirect.http: google.helloworld.com--www.google.com
easyhaproxy.host.http: www.helloworld.com
easyhaproxy.port.http: 19901
easyhaproxy.localport.http: 80
easyhaproxy.http.redirect: google.helloworld.com--www.google.com
easyhaproxy.http.host: www.helloworld.com
easyhaproxy.http.port: 19901
easyhaproxy.http.localport: 80

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
portainer-agent_agent={"com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"portainer-agent"}
my-stack_agent={"easyhaproxy.definitions":"agent","easyhaproxy.host.agent":"agent.quantum.example.org","easyhaproxy.localport.agent":"9001","easyhaproxy.mode.agent":"tcp","easyhaproxy.port.agent":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_cadvisor={"easyhaproxy.definitions":"cadvisor","easyhaproxy.host.cadvisor":"cadvisor.quantum.example.org","easyhaproxy.localport.cadvisor":"8080","easyhaproxy.port.cadvisor":"31337","com.docker.stack.image":"gcr.io/google-containers/cadvisor:v0.34.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_node-exporter={"easyhaproxy.definitions":"exp","easyhaproxy.host.exp":"node-exporter.quantum.example.org","easyhaproxy.localport.exp":"9100","easyhaproxy.port.exp":"31337","com.docker.stack.image":"stefanprodan/swarmprom-node-exporter:v0.16.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_agent={"easyhaproxy.definitions":"agent","easyhaproxy.agent.host":"agent.quantum.example.org","easyhaproxy.agent.localport":"9001","easyhaproxy.agent.mode":"tcp","easyhaproxy.agent.port":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_cadvisor={"easyhaproxy.definitions":"cadvisor","easyhaproxy.cadvisor.host":"cadvisor.quantum.example.org","easyhaproxy.cadvisor.localport":"8080","easyhaproxy.cadvisor.port":"31337","com.docker.stack.image":"gcr.io/google-containers/cadvisor:v0.34.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_node-exporter={"easyhaproxy.definitions":"exp","easyhaproxy.exp.host":"node-exporter.quantum.example.org","easyhaproxy.exp.localport":"9100","easyhaproxy.exp.port":"31337","com.docker.stack.image":"stefanprodan/swarmprom-node-exporter:v0.16.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_reverse-proxy={"com.docker.stack.image":"quay.io/pngmbh/easy-haproxy:tcp-mode","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
some-service={"easyhaproxy.definitions":"http,https","easyhaproxy.port.http":"80","easyhaproxy.host.http":"www.somehost.com.br","easyhaproxy.localport.http":"80","easyhaproxy.redirect.http":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","easyhaproxy.port.https":"443","easyhaproxy.host.https":"www.somehost.com.br","easyhaproxy.localport.https":"80","easyhaproxy.redirect.https":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","easyhaproxy.sslcert.https":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}
some-service={"easyhaproxy.definitions":"http,https","easyhaproxy.http.port":"80","easyhaproxy.http.host":"www.somehost.com.br","easyhaproxy.http.localport":"80","easyhaproxy.http.redirect":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","easyhaproxy.https.port":"443","easyhaproxy.https.host":"www.somehost.com.br","easyhaproxy.https.localport":"80","easyhaproxy.https.redirect":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","easyhaproxy.https.sslcert":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}

View file

@ -1,6 +1,6 @@
portainer-agent_agent={"com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"portainer-agent"}
my-stack_agent={"haproxy.definitions":"agent","haproxy.host.agent":"agent.quantum.example.org","haproxy.localport.agent":"9001","haproxy.mode.agent":"tcp","haproxy.port.agent":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_cadvisor={"haproxy.definitions":"cadvisor","haproxy.host.cadvisor":"cadvisor.quantum.example.org","haproxy.localport.cadvisor":"8080","haproxy.port.cadvisor":"31337","com.docker.stack.image":"gcr.io/google-containers/cadvisor:v0.34.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_node-exporter={"haproxy.definitions":"exp","haproxy.host.exp":"node-exporter.quantum.example.org","haproxy.localport.exp":"9100","haproxy.port.exp":"31337","com.docker.stack.image":"stefanprodan/swarmprom-node-exporter:v0.16.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_agent={"haproxy.definitions":"agent","haproxy.agent.host":"agent.quantum.example.org","haproxy.agent.localport":"9001","haproxy.agent.mode":"tcp","haproxy.agent.port":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_cadvisor={"haproxy.definitions":"cadvisor","haproxy.cadvisor.host":"cadvisor.quantum.example.org","haproxy.cadvisor.localport":"8080","haproxy.cadvisor.port":"31337","com.docker.stack.image":"gcr.io/google-containers/cadvisor:v0.34.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_node-exporter={"haproxy.definitions":"exp","haproxy.exp.host":"node-exporter.quantum.example.org","haproxy.exp.localport":"9100","haproxy.exp.port":"31337","com.docker.stack.image":"stefanprodan/swarmprom-node-exporter:v0.16.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_reverse-proxy={"com.docker.stack.image":"quay.io/pngmbh/easy-haproxy:tcp-mode","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
some-service={"haproxy.definitions":"http,https","haproxy.port.http":"80","haproxy.host.http":"www.somehost.com.br","haproxy.localport.http":"80","haproxy.redirect.http":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.port.https":"443","haproxy.host.https":"www.somehost.com.br","haproxy.localport.https":"80","haproxy.redirect.https":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.sslcert.https":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}
some-service={"haproxy.definitions":"http,https","haproxy.http.port":"80","haproxy.http.host":"www.somehost.com.br","haproxy.http.localport":"80","haproxy.http.redirect":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.https.port":"443","haproxy.https.host":"www.somehost.com.br","haproxy.https.localport":"80","haproxy.https.redirect":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.https.sslcert":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}

View file

@ -1,2 +1,2 @@
test_nginx.2.t5r94mjlced7m3t5orfjbowmm={"easyhaproxy.definitions":"http","easyhaproxy.host.http":"www.helloworld.com","easyhaproxy.localport.http":"80","easyhaproxy.port.http":"19901","com.docker.stack.image":"stenote/nginx-hostname","com.docker.stack.namespace":"test"}
test_nginx.1.p552hqxkdx88narjrp5kouwb2={"easyhaproxy.definitions":"http","easyhaproxy.host.http":"www.helloworld.com","easyhaproxy.localport.http":"80","easyhaproxy.port.http":"19901","com.docker.stack.image":"stenote/nginx-hostname","com.docker.stack.namespace":"test"}
test_nginx.2.t5r94mjlced7m3t5orfjbowmm={"easyhaproxy.definitions":"http","easyhaproxy.http.host":"www.helloworld.com","easyhaproxy.http.localport":"80","easyhaproxy.http.port":"19901","com.docker.stack.image":"stenote/nginx-hostname","com.docker.stack.namespace":"test"}
test_nginx.1.p552hqxkdx88narjrp5kouwb2={"easyhaproxy.definitions":"http","easyhaproxy.http.host":"www.helloworld.com","easyhaproxy.http.localport":"80","easyhaproxy.http.port":"19901","com.docker.stack.image":"stenote/nginx-hostname","com.docker.stack.namespace":"test"}

View file

@ -1,2 +1,2 @@
test_agent={"easyhaproxy.definitions":"agent","easyhaproxy.host.agent":"agent.quantum.local","easyhaproxy.localport.agent":"9001","easyhaproxy.mode.agent":"tcp","easyhaproxy.port.agent":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"test", "easyhaproxy.health-check.agent":"ssl"}
test_agent={"easyhaproxy.definitions":"agent","easyhaproxy.agent.host":"agent.quantum.local","easyhaproxy.agent.localport":"9001","easyhaproxy.agent.mode":"tcp","easyhaproxy.agent.port":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"test", "easyhaproxy.agent.health-check":"ssl"}
test_proxy={"com.docker.stack.image":"byjg/easy-haproxy:local","com.docker.stack.namespace":"test"}

View file

@ -205,3 +205,4 @@ def test_parser_multi_containers():
#test_parser_finds_services_raw()
#test_parser_tcp()