Renaming docker environment variables.
This commit is contained in:
parent
4a1c36d003
commit
a457297c5f
8 changed files with 25 additions and 23 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
FROM alpine:3.14
|
FROM alpine:3.16
|
||||||
|
|
||||||
WORKDIR /scripts
|
WORKDIR /scripts
|
||||||
|
|
||||||
|
|
|
||||||
19
README.md
19
README.md
|
|
@ -24,7 +24,7 @@ The basic command line to run is:
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name easy-haproxy-container \
|
--name easy-haproxy-container \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
-e DISCOVER="swarm|docker|static" \
|
-e EASYHAPROXY_DISCOVER="swarm|docker|static" \
|
||||||
# + Environment Variables \
|
# + Environment Variables \
|
||||||
# + ports mapped to the host \
|
# + ports mapped to the host \
|
||||||
byjg/easy-haproxy
|
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.
|
The environment variables will setup the HAProxy.
|
||||||
|
|
||||||
| Environment Variable | Description |
|
| Environment Variable | Description |
|
||||||
|----------------------|-------------------------------------------------------------------------------|
|
|--------------------------|-------------------------------------------------------------------------------|
|
||||||
| DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` |
|
| EASYHAPROXY_DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` |
|
||||||
| LOOKUP_LABEL | (Optional) The key will search to match resources. Default: `easyhaproxy`. |
|
| 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_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` |
|
||||||
| HAPROXY_PASSWORD | The HAProxy password to the statistics. If not set disable stats. |
|
| 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_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
|
- docker
|
||||||
- swarm
|
- swarm
|
||||||
- static
|
- 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.
|
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.
|
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
|
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
|
This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all
|
||||||
swarm nodes.
|
swarm nodes.
|
||||||
|
|
@ -138,7 +138,6 @@ Used to pass on SSL-termination to a backend:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run \
|
docker run \
|
||||||
-l easyhaproxy.defintions=example \
|
|
||||||
-l easyhaproxy.example.mode=tcp \
|
-l easyhaproxy.example.mode=tcp \
|
||||||
-l easyhaproxy.example.health-check=ssl \
|
-l easyhaproxy.example.health-check=ssl \
|
||||||
-l easyhaproxy.example.port=443
|
-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
|
-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`
|
This method expects a YAML file to setup the `haproxy.cfg`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ cd /scripts
|
||||||
|
|
||||||
RELOAD="true"
|
RELOAD="true"
|
||||||
|
|
||||||
if [[ "$DISCOVER" == "static" ]]; then
|
if [[ "$EASYHAPROXY_DISCOVER" == "static" ]]; then
|
||||||
CONTROL_FILE="/etc/haproxy/haproxy.cfg"
|
CONTROL_FILE="/etc/haproxy/haproxy.cfg"
|
||||||
touch ${CONTROL_FILE}
|
touch ${CONTROL_FILE}
|
||||||
cp ${CONTROL_FILE} ${CONTROL_FILE}.old
|
cp ${CONTROL_FILE} ${CONTROL_FILE}.old
|
||||||
|
|
@ -15,7 +15,7 @@ else
|
||||||
mv ${CONTROL_FILE} ${CONTROL_FILE}.old
|
mv ${CONTROL_FILE} ${CONTROL_FILE}.old
|
||||||
touch ${CONTROL_FILE}
|
touch ${CONTROL_FILE}
|
||||||
|
|
||||||
if [[ "$DISCOVER" == "docker" ]]; then
|
if [[ "$EASYHAPROXY_DISCOVER" == "docker" ]]; then
|
||||||
CONTAINERS=$(docker ps -q)
|
CONTAINERS=$(docker ps -q)
|
||||||
LABEL_PATH=".Config.Labels"
|
LABEL_PATH=".Config.Labels"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ if os.getenv("HAPROXY_PASSWORD"):
|
||||||
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
|
"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)
|
cfg = HaproxyConfigGenerator(result)
|
||||||
print(cfg.generate(lineList))
|
print(cfg.generate(lineList))
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
environment:
|
environment:
|
||||||
DISCOVER: docker
|
EASYHAPROXY_DISCOVER: docker
|
||||||
LOOKUP_LABEL: haproxy
|
EASYHAPROXY_LABEL_PREFIX: haproxy
|
||||||
HAPROXY_CUSTOMERRORS: "true"
|
HAPROXY_CUSTOMERRORS: "true"
|
||||||
HAPROXY_USERNAME: admin
|
HAPROXY_USERNAME: admin
|
||||||
HAPROXY_PASSWORD: password
|
HAPROXY_PASSWORD: password
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
environment:
|
environment:
|
||||||
DISCOVER: docker
|
EASYHAPROXY_DISCOVER: docker
|
||||||
HAPROXY_CUSTOMERRORS: "true"
|
HAPROXY_CUSTOMERRORS: "true"
|
||||||
HAPROXY_USERNAME: admin
|
HAPROXY_USERNAME: admin
|
||||||
HAPROXY_PASSWORD: password
|
HAPROXY_PASSWORD: password
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
environment:
|
environment:
|
||||||
DISCOVER: docker
|
EASYHAPROXY_DISCOVER: docker
|
||||||
HAPROXY_CUSTOMERRORS: "true"
|
HAPROXY_CUSTOMERRORS: "true"
|
||||||
HAPROXY_USERNAME: admin
|
HAPROXY_USERNAME: admin
|
||||||
HAPROXY_PASSWORD: password
|
HAPROXY_PASSWORD: password
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
# To test:
|
||||||
|
# curl -k -H "Host: host1.local" https://127.0.0.1/
|
||||||
|
|
||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
@ -8,7 +11,7 @@ services:
|
||||||
- ./host1.local.pem:/etc/certs/host1.local.pem
|
- ./host1.local.pem:/etc/certs/host1.local.pem
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
environment:
|
environment:
|
||||||
DISCOVER: static
|
EASYHAPROXY_DISCOVER: static
|
||||||
ports:
|
ports:
|
||||||
- "80:80/tcp"
|
- "80:80/tcp"
|
||||||
- "443:443/tcp"
|
- "443:443/tcp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue