1
0
Fork 0

Refactor: tried to refactor code

- move scripts to assets/scripts (and updated build)
 - put most logic into HaproxyConfigGenerator
 - created DockerLabelHandler for all label handling from previous code
 - added unit tests and fixtures to cover HaproxyConfigGenerator and DockerLabelHandler
 - added a Makefile with build (for docker build) and test targets
This commit is contained in:
till 2020-05-30 22:24:40 +02:00
parent 5f9eac4b8a
commit 08de132450
No known key found for this signature in database
GPG key ID: B119050E2EBA1DC5
21 changed files with 387 additions and 131 deletions

View file

@ -1,24 +1,24 @@
# Easy HAProxy
# Easy HAProxy
This Docker image will create dynamically the `haproxy.cfg` based on the labels defined in docker containers or from
a simple Yaml instead docker
This Docker image will create dynamically the `haproxy.cfg` based on the labels defined in docker containers or from
a simple Yaml instead docker
# Features
- Enable or disable Stats on port 1936 with custom password
- Discover and setup haproxy from Docker Tag
- Discover and setup haproxy from Docker Tag
- Discover and setup haproxy redirect from Docker Tag
- Setup HAProxy CFG from a Yaml file.
- Setup HAProxy CFG from a Yaml file.
# Basic Usage
The Easy HAProxy will create the `haproxy.cfg` automatically based on the containers or from a YAML provided.
The Easy HAProxy will create the `haproxy.cfg` automatically based on the containers or from a YAML provided.
The basic command line to run is:
```bash
docker run -d \
docker run -d \
--name easy-haproxy-container \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DISCOVER="swarm|docker|static" \
@ -29,7 +29,7 @@ docker run -d \
The mapping to `/var/run/docker.sock` is necessary to discover the docker containers and get the labels;
The environment variables will setup the HAProxy.
The environment variables will setup the HAProxy.
{:.table}
| Environment Variable | Description |
@ -49,9 +49,9 @@ The environment variable `DISCOVER` will define where is located your containers
# 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.
The only requirement is that containers and easy-haproxy must be in the same docker network.
The only requirement is that containers and easy-haproxy must be in the same docker network.
The discover will occur every minute.
@ -67,12 +67,12 @@ docker run --network easyhaproxy myimage
# DISCOVER: swarm
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
swarm nodes.
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
swarm nodes.
The discover will occur every minute.
Important: easyhaproxy needs to be in the same network of the containers or otherwise will not access.
Important: easyhaproxy needs to be in the same network of the containers or otherwise will not access.
## Tags to be attached in the Docker Container
@ -163,12 +163,12 @@ customerrors: true # Optional (default false)
easymapping:
- port: 80
hosts:
hosts:
host1.com.br: container:5000
host2.com.br: other:3000
redirect:
www.host1.com.br: http://host1.com.br
- port: 443
ssl_cert: BASE64_PEM_CERTIFICATE
hosts:
@ -187,10 +187,10 @@ docker run -v /my/config.yml:/etc/haproxy/easyconfig.yml .... byjg/easyhaproxy
# 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.
```bash
docker run \
docker run \
/* other parameters */
-v /your/local/conf.d:/etc/haproxy/conf.d \
-d byjg/easy-haproxy
@ -199,9 +199,9 @@ docker run \
# Handling SSL
You can attach a valid SSL certificate to the request.
You can attach a valid SSL certificate to the request.
1. First Create a single PEM file including CA.
1. First Create a single PEM file including CA.
```bash
cat example.com.crt example.com.key > single.pem
@ -229,8 +229,8 @@ cat single.pem | base64 -w0
# Setting Custom Errors
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)
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)
# Build