Merge branch 'master' of github.com:byjg/docker-easy-haproxy
This commit is contained in:
commit
f562f0622f
6 changed files with 55 additions and 49 deletions
74
README.md
74
README.md
|
|
@ -49,7 +49,11 @@ The environment variable `DISCOVER` will define where is located your containers
|
||||||
- swarm
|
- swarm
|
||||||
- static
|
- static
|
||||||
|
|
||||||
## DISCOVER: docker
|
## Automatic Discover Services
|
||||||
|
|
||||||
|
Easy HAProxy can discover automatically the container services running in the same network of Docker or in a Docker Swarm cluster.
|
||||||
|
|
||||||
|
### DISCOVER: docker
|
||||||
|
|
||||||
This method will use a regular docker installation to discover the containers and configure the HAProxy.
|
This method will use a regular docker installation to discover the containers and configure the HAProxy.
|
||||||
|
|
||||||
|
|
@ -67,7 +71,7 @@ docker run --network easyhaproxy byjg/easyhaproxy
|
||||||
docker run --network easyhaproxy myimage
|
docker run --network easyhaproxy myimage
|
||||||
```
|
```
|
||||||
|
|
||||||
## DISCOVER: swarm
|
### DISCOVER: swarm
|
||||||
|
|
||||||
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
|
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
|
||||||
swarm nodes.
|
swarm nodes.
|
||||||
|
|
@ -78,25 +82,27 @@ Important: easyhaproxy needs to be in the same network of the containers or othe
|
||||||
|
|
||||||
### Tags to be attached in the Docker Container (Swarm or Docker)
|
### Tags to be attached in the Docker Container (Swarm or Docker)
|
||||||
|
|
||||||
| Tag | Description | Example |
|
| Tag | Description | Example |
|
||||||
|---------------------------------------------|---------------------------------------------------------------------------------------------------------|--------------|
|
|------------------------------------|---------------------------------------------------------------------------------------------------------|--------------|
|
||||||
| com.byjg.easyhaproxy.definitions | A Comma delimited list with the definitions. Each name requires the definition of the parameters below. | http,https |
|
| easyhaproxy.definitions | A Comma delimited list with the definitions. Each name requires the definition of the parameters below. | service,service2 |
|
||||||
| com.byjg.easyhaproxy.mode.[definition] | (Optional) Is this http or tcp mode in HAProxy. (Defaults to http) | http |
|
| easyhaproxy.mode.[definition] | (Optional) Is this `http` or `tcp` mode in HAProxy. (Defaults to http) | http |
|
||||||
| com.byjg.easyhaproxy.port.[definition] | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) | 80 |
|
| easyhaproxy.port.[definition] | (Optional) What is the port that the HAProxy will listen to. (Defaults to 80) | 80 |
|
||||||
| com.byjg.easyhaproxy.localport.[definition] | (Optional) What is the port that the container is listening. (Defaults to 80) | 8080 |
|
| easyhaproxy.localport.[definition] | (Optional) What is the port that the container is listening. (Defaults to 80) | 8080 |
|
||||||
| com.byjg.easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. | somehost.com |
|
| easyhaproxy.host.[definition] | What is the host that the HAProxy will listen to. | somehost.com |
|
||||||
| com.byjg.easyhaproxy.redirect.[definition] | (Optional) Host redirects from connections in the port defined above. | foo.com--https://bla.com,bar.com--https://bar.org |
|
| easyhaproxy.redirect.[definition] | (Optional) Host redirects from connections in the port defined above. | foo.com--https://bla.com,bar.com--https://bar.org |
|
||||||
| com.byjg.easyhaproxy.sslcert.[definition] | (Optional) Cert PEM Base64 encoded. | |
|
| easyhaproxy.sslcert.[definition] | (Optional) Cert PEM Base64 encoded. | |
|
||||||
| com.byjg.easyhaproxy.health-check.[definition] | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | |
|
| easyhaproxy.health-check.[definition] | (Optional) `ssl`, enable health check via SSL in `mode tcp` (Defaults to "empty") | |
|
||||||
|
|
||||||
Note: if you are deploying a stack set labels at the `deploy` level:
|
### Defining the labels in Docker Swarm
|
||||||
|
|
||||||
|
if you are deploying a stack in a Docker Swarm cluster set labels at the `deploy` level:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
foo:
|
foo:
|
||||||
deploy:
|
deploy:
|
||||||
labels:
|
labels:
|
||||||
com.byjg.easyhaproxy.definitions: "http,https"
|
easyhaproxy.definitions: "service1,service2"
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -105,9 +111,9 @@ services:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run \
|
docker run \
|
||||||
-l com.byjg.easyhaproxy.definitions=http \
|
-l easyhaproxy.definitions=webapi \
|
||||||
-l com.byjg.easyhaproxy.port.http=80\
|
-l easyhaproxy.port.webapi=80\
|
||||||
-l com.byjg.easyhaproxy.host.http=byjg.com.br \
|
-l easyhaproxy.host.webapi=byjg.com.br \
|
||||||
....
|
....
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -115,15 +121,15 @@ docker run \
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run \
|
docker run \
|
||||||
-l com.byjg.easyhaproxy.definitions=express,admin \
|
-l easyhaproxy.definitions=express,admin \
|
||||||
|
|
||||||
-l com.byjg.easyhaproxy.port.express=80 \
|
-l easyhaproxy.port.express=80 \
|
||||||
-l com.byjg.easyhaproxy.localport.express=3000 \
|
-l easyhaproxy.localport.express=3000 \
|
||||||
-l com.byjg.easyhaproxy.host.express=express.byjg.com.br \
|
-l easyhaproxy.host.express=express.byjg.com.br \
|
||||||
|
|
||||||
-l com.byjg.easyhaproxy.port.admin=80 \
|
-l easyhaproxy.port.admin=80 \
|
||||||
-l com.byjg.easyhaproxy.localport.admin=3001 \
|
-l easyhaproxy.localport.admin=3001 \
|
||||||
-l com.byjg.easyhaproxy.host.admin=admin.byjg.com.br \
|
-l easyhaproxy.host.admin=admin.byjg.com.br \
|
||||||
.... \
|
.... \
|
||||||
some/myimage
|
some/myimage
|
||||||
```
|
```
|
||||||
|
|
@ -134,10 +140,10 @@ Used to pass on SSL-termination to a backend:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run \
|
docker run \
|
||||||
-l com.byjg.easyhaproxy.defintions=tcp-service \
|
-l easyhaproxy.defintions=example \
|
||||||
-l com.byjg.easyhaproxy.mode.tcp-service=tcp \
|
-l easyhaproxy.mode.example=tcp \
|
||||||
-l com.byjg.easyhaproxy.health-check.tcp-service=ssl \
|
-l easyhaproxy.health-check.example=ssl \
|
||||||
-l com.byjg.easyhaproxy.port.tcp-service=443
|
-l easyhaproxy.port.example=443
|
||||||
.... \
|
.... \
|
||||||
some/tcp-service
|
some/tcp-service
|
||||||
```
|
```
|
||||||
|
|
@ -148,7 +154,7 @@ docker run \
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run \
|
docker run \
|
||||||
-l com.byjg.easyhaproxy.redirect.<defintion>=www.byjg.com.br--http://byjg.com.br,byjg.com--http://byjg.com.br
|
-l easyhaproxy.redirect.<defintion>=www.byjg.com.br--http://byjg.com.br,byjg.com--http://byjg.com.br
|
||||||
```
|
```
|
||||||
|
|
||||||
## DISCOVER: static
|
## DISCOVER: static
|
||||||
|
|
@ -189,7 +195,7 @@ Running:
|
||||||
docker run -v /my/config.yml:/etc/haproxy/easyconfig.yml .... byjg/easyhaproxy
|
docker run -v /my/config.yml:/etc/haproxy/easyconfig.yml .... byjg/easyhaproxy
|
||||||
```
|
```
|
||||||
|
|
||||||
# Mapping custom .cfg files
|
## Mapping custom .cfg files
|
||||||
|
|
||||||
Map a folder containing valid HAProxy `.cfg` files to `/etc/haproxy/conf.d`. It will be concatenated to your HAProxy CFG.
|
Map a folder containing valid HAProxy `.cfg` files to `/etc/haproxy/conf.d`. It will be concatenated to your HAProxy CFG.
|
||||||
|
|
||||||
|
|
@ -201,7 +207,7 @@ docker run \
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Handling SSL
|
## Handling SSL
|
||||||
|
|
||||||
You can attach a valid SSL certificate to the request.
|
You can attach a valid SSL certificate to the request.
|
||||||
|
|
||||||
|
|
@ -229,14 +235,14 @@ MIIEojCCA4qgAwIBAgIUegW2BimwuL4RzRZ2WYkHA6U5nkAwDQYJKoZIhvcNAQEL
|
||||||
cat single.pem | base64 -w0
|
cat single.pem | base64 -w0
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Use this string to define the label `com.byjg.easyhaproxy.sslcert.[definition]`
|
3. Use this string to define the label `easyhaproxy.sslcert.[definition]`
|
||||||
|
|
||||||
# Setting Custom Errors
|
## Setting Custom Errors
|
||||||
|
|
||||||
If enabled, map the volume : `/etc/haproxy/errors-custom/` to your container and put a file named `ERROR_NUMBER.http`
|
If enabled, map the volume : `/etc/haproxy/errors-custom/` to your container and put a file named `ERROR_NUMBER.http`
|
||||||
where ERROR_NUMBER is the http error code (e.g. 503.http)
|
where ERROR_NUMBER is the http error code (e.g. 503.http)
|
||||||
|
|
||||||
# Build
|
## Build
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t byjg/easy-haproxy .
|
docker build -t byjg/easy-haproxy .
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,5 @@ fi
|
||||||
|
|
||||||
if [[ "$RELOAD" == "true" ]]; then
|
if [[ "$RELOAD" == "true" ]]; then
|
||||||
echo "Reloading..."
|
echo "Reloading..."
|
||||||
/usr/local/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
|
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class DockerLabelHandler:
|
||||||
class HaproxyConfigGenerator:
|
class HaproxyConfigGenerator:
|
||||||
def __init__(self, mapping, ssl_cert_folder="/etc/haproxy/certs"):
|
def __init__(self, mapping, ssl_cert_folder="/etc/haproxy/certs"):
|
||||||
self.mapping = mapping
|
self.mapping = mapping
|
||||||
self.label = DockerLabelHandler("com.byjg.easyhaproxy")
|
self.label = DockerLabelHandler("easyhaproxy")
|
||||||
self.ssl_cert_folder = ssl_cert_folder
|
self.ssl_cert_folder = ssl_cert_folder
|
||||||
self.ssl_cert_increment = 0
|
self.ssl_cert_increment = 0
|
||||||
os.makedirs(self.ssl_cert_folder, exist_ok=True)
|
os.makedirs(self.ssl_cert_folder, exist_ok=True)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
8
tests/fixtures/services
vendored
8
tests/fixtures/services
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
portainer-agent_agent={"com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"portainer-agent"}
|
portainer-agent_agent={"com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"portainer-agent"}
|
||||||
my-stack_agent={"com.byjg.easyhaproxy.definitions":"agent","com.byjg.easyhaproxy.host.agent":"agent.quantum.example.org","com.byjg.easyhaproxy.localport.agent":"9001","com.byjg.easyhaproxy.mode.agent":"tcp","com.byjg.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_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={"com.byjg.easyhaproxy.definitions":"cadvisor","com.byjg.easyhaproxy.host.cadvisor":"cadvisor.quantum.example.org","com.byjg.easyhaproxy.localport.cadvisor":"8080","com.byjg.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_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={"com.byjg.easyhaproxy.definitions":"exp","com.byjg.easyhaproxy.host.exp":"node-exporter.quantum.example.org","com.byjg.easyhaproxy.localport.exp":"9100","com.byjg.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_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_reverse-proxy={"com.docker.stack.image":"quay.io/pngmbh/easy-haproxy:tcp-mode","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={"com.byjg.easyhaproxy.definitions":"http,https","com.byjg.easyhaproxy.port.http":"80","com.byjg.easyhaproxy.host.http":"www.somehost.com.br","com.byjg.easyhaproxy.localport.http":"80","com.byjg.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","com.byjg.easyhaproxy.port.https":"443","com.byjg.easyhaproxy.host.https":"www.somehost.com.br","com.byjg.easyhaproxy.localport.https":"80","com.byjg.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","com.byjg.easyhaproxy.sslcert.https":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}
|
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="}
|
||||||
2
tests/fixtures/services-tcp
vendored
2
tests/fixtures/services-tcp
vendored
|
|
@ -1,2 +1,2 @@
|
||||||
test_agent={"com.byjg.easyhaproxy.definitions":"agent","com.byjg.easyhaproxy.host.agent":"agent.quantum.local","com.byjg.easyhaproxy.localport.agent":"9001","com.byjg.easyhaproxy.mode.agent":"tcp","com.byjg.easyhaproxy.port.agent":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"test", "com.byjg.easyhaproxy.health-check.agent":"ssl"}
|
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_proxy={"com.docker.stack.image":"byjg/easy-haproxy:local","com.docker.stack.namespace":"test"}
|
test_proxy={"com.docker.stack.image":"byjg/easy-haproxy:local","com.docker.stack.namespace":"test"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue