From a457297c5fd2e1215edb3d95a259981ce62fb60e Mon Sep 17 00:00:00 2001 From: Joao M Date: Sat, 13 Aug 2022 17:29:07 +0000 Subject: [PATCH] Renaming docker environment variables. --- Dockerfile | 2 +- README.md | 27 +++++++++---------- assets/scripts/haproxy-reload.sh | 4 +-- assets/scripts/swarm.py | 2 +- .../docker/docker-compose-changed-label.yml | 4 +-- .../docker-compose-multi-containers.yml | 2 +- examples/docker/docker-compose.yml | 2 +- examples/static/docker-compose.yml | 5 +++- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 86f11ea..77c80c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.16 WORKDIR /scripts diff --git a/README.md b/README.md index 51224e3..617718e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -34,18 +34,18 @@ 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`. | -| 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 | +| Environment Variable | Description | +|--------------------------|-------------------------------------------------------------------------------| +| 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 | -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` diff --git a/assets/scripts/haproxy-reload.sh b/assets/scripts/haproxy-reload.sh index 094fd3e..55e7e27 100755 --- a/assets/scripts/haproxy-reload.sh +++ b/assets/scripts/haproxy-reload.sh @@ -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" diff --git a/assets/scripts/swarm.py b/assets/scripts/swarm.py index e09fab4..425535a 100644 --- a/assets/scripts/swarm.py +++ b/assets/scripts/swarm.py @@ -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)) diff --git a/examples/docker/docker-compose-changed-label.yml b/examples/docker/docker-compose-changed-label.yml index 5183940..9f944b5 100644 --- a/examples/docker/docker-compose-changed-label.yml +++ b/examples/docker/docker-compose-changed-label.yml @@ -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 diff --git a/examples/docker/docker-compose-multi-containers.yml b/examples/docker/docker-compose-multi-containers.yml index e5ee2a5..b2d7467 100644 --- a/examples/docker/docker-compose-multi-containers.yml +++ b/examples/docker/docker-compose-multi-containers.yml @@ -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 diff --git a/examples/docker/docker-compose.yml b/examples/docker/docker-compose.yml index 0675f35..9b1d9e6 100644 --- a/examples/docker/docker-compose.yml +++ b/examples/docker/docker-compose.yml @@ -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 diff --git a/examples/static/docker-compose.yml b/examples/static/docker-compose.yml index 59aaeb5..055f997 100644 --- a/examples/static/docker-compose.yml +++ b/examples/static/docker-compose.yml @@ -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"