1
0
Fork 0

Renaming docker environment variables.

This commit is contained in:
Joao M 2022-08-13 17:29:07 +00:00
parent 4a1c36d003
commit a457297c5f
8 changed files with 25 additions and 23 deletions

View file

@ -1,4 +1,4 @@
FROM alpine:3.14
FROM alpine:3.16
WORKDIR /scripts

View file

@ -24,7 +24,7 @@ The basic command line to run is:
docker run -d \
--name easy-haproxy-container \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DISCOVER="swarm|docker|static" \
-e EASYHAPROXY_DISCOVER="swarm|docker|static" \
# + Environment Variables \
# + ports mapped to the host \
byjg/easy-haproxy
@ -35,17 +35,17 @@ The mapping to `/var/run/docker.sock` is necessary to discover the docker contai
The environment variables will setup the HAProxy.
| Environment Variable | Description |
|----------------------|-------------------------------------------------------------------------------|
| DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` |
| LOOKUP_LABEL | (Optional) The key will search to match resources. Default: `easyhaproxy`. |
|--------------------------|-------------------------------------------------------------------------------|
| EASYHAPROXY_DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` |
| EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search to match resources. Default: `easyhaproxy`. |
| HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` |
| HAPROXY_PASSWORD | The HAProxy password to the statistics. If not set disable stats. |
| HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936` |
| HAPROXY_CUSTOMERRORS | (Optional) If HAProxy will use custom HTML errors. true/false. Default: false |
| HAPROXY_CUSTOMERRORS. | (Optional) If HAProxy will use custom HTML errors. true/false. Default: false |
The environment variable `DISCOVER` will define where is located your containers (see below more details):
The environment variable `EASYHAPROXY_DISCOVER` will define where is located your containers (see below more details):
- docker
- swarm
- static
@ -54,7 +54,7 @@ The environment variable `DISCOVER` will define where is located your containers
Easy HAProxy can discover automatically the container services running in the same network of Docker or in a Docker Swarm cluster.
### DISCOVER: docker
### EASYHAPROXY_DISCOVER: docker
This method will use a regular docker installation to discover the containers and configure the HAProxy.
@ -72,7 +72,7 @@ docker run --network easyhaproxy byjg/easyhaproxy
docker run --network easyhaproxy myimage
```
### DISCOVER: swarm
### EASYHAPROXY_DISCOVER: swarm
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
swarm nodes.
@ -138,7 +138,6 @@ Used to pass on SSL-termination to a backend:
```bash
docker run \
-l easyhaproxy.defintions=example \
-l easyhaproxy.example.mode=tcp \
-l easyhaproxy.example.health-check=ssl \
-l easyhaproxy.example.port=443
@ -155,7 +154,7 @@ docker run \
-l easyhaproxy.[definition].redirect=www.byjg.com.br--http://byjg.com.br,byjg.com--http://byjg.com.br
```
## DISCOVER: static
## EASYHAPROXY_DISCOVER: static
This method expects a YAML file to setup the `haproxy.cfg`

View file

@ -4,7 +4,7 @@ cd /scripts
RELOAD="true"
if [[ "$DISCOVER" == "static" ]]; then
if [[ "$EASYHAPROXY_DISCOVER" == "static" ]]; then
CONTROL_FILE="/etc/haproxy/haproxy.cfg"
touch ${CONTROL_FILE}
cp ${CONTROL_FILE} ${CONTROL_FILE}.old
@ -15,7 +15,7 @@ else
mv ${CONTROL_FILE} ${CONTROL_FILE}.old
touch ${CONTROL_FILE}
if [[ "$DISCOVER" == "docker" ]]; then
if [[ "$EASYHAPROXY_DISCOVER" == "docker" ]]; then
CONTAINERS=$(docker ps -q)
LABEL_PATH=".Config.Labels"

View file

@ -16,7 +16,7 @@ if os.getenv("HAPROXY_PASSWORD"):
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
}
result["lookup_label"] = os.getenv("LOOKUP_LABEL") if os.getenv("LOOKUP_LABEL") else "easyhaproxy"
result["lookup_label"] = os.getenv("EASYHAPROXY_LABEL_PREFIX") if os.getenv("EASYHAPROXY_LABEL_PREFIX") else "easyhaproxy"
cfg = HaproxyConfigGenerator(result)
print(cfg.generate(lineList))

View file

@ -12,8 +12,8 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DISCOVER: docker
LOOKUP_LABEL: haproxy
EASYHAPROXY_DISCOVER: docker
EASYHAPROXY_LABEL_PREFIX: haproxy
HAPROXY_CUSTOMERRORS: "true"
HAPROXY_USERNAME: admin
HAPROXY_PASSWORD: password

View file

@ -15,7 +15,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DISCOVER: docker
EASYHAPROXY_DISCOVER: docker
HAPROXY_CUSTOMERRORS: "true"
HAPROXY_USERNAME: admin
HAPROXY_PASSWORD: password

View file

@ -12,7 +12,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DISCOVER: docker
EASYHAPROXY_DISCOVER: docker
HAPROXY_CUSTOMERRORS: "true"
HAPROXY_USERNAME: admin
HAPROXY_PASSWORD: password

View file

@ -1,3 +1,6 @@
# To test:
# curl -k -H "Host: host1.local" https://127.0.0.1/
version: "3"
services:
@ -8,7 +11,7 @@ services:
- ./host1.local.pem:/etc/certs/host1.local.pem
- /var/run/docker.sock:/var/run/docker.sock
environment:
DISCOVER: static
EASYHAPROXY_DISCOVER: static
ports:
- "80:80/tcp"
- "443:443/tcp"