From de0c7a93b872828bf48da32dfd1266b8f1353dde Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Mon, 17 Sep 2018 01:38:26 -0500 Subject: [PATCH] Added Custom Config --- Dockerfile | 3 ++- README.md | 29 +++++++++++++++++++++++++++-- conf.d/00-simple-comment.cfg | 1 + conf.d/README.md | 3 +++ entrypoint.sh | 22 +++++++++++++++++----- 5 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 conf.d/00-simple-comment.cfg create mode 100644 conf.d/README.md diff --git a/Dockerfile b/Dockerfile index 9e0eceb..2f64f12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,8 @@ FROM haproxy:1.8-alpine RUN apk add --no-cache bash -COPY entrypoint.sh / +COPY *.sh / +COPY conf.d /etc/haproxy/conf.d COPY assets/errors-custom/* /etc/haproxy/errors-custom/ ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/README.md b/README.md index d16b01c..d8482c1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ This Docker image will create dynamically the `haproxy.cfg` based on the argumen ## Features - Enable or disable Stats on port 1936 with custom password -- Add a mapping from a host to another +- Add a mapping from a host to another based on Environment Variables +- Dont need to setup .cfg file +- You can add custom .cfg file by mapping the `conf.d` folder + ## Usages @@ -28,8 +31,30 @@ docker run \ -e LB_STATS_USER=admin \ -e LB_STATS_PASS=mypassword \ -e LB_HOSTS="my.domain.com container1:8080 other.domain.com other:7000" \ + -p 80:80 \ --name easy-haproxy-instance \ - -t -d byjg/easy-haproxy + -d byjg/easy-haproxy +``` + +## Mapping custom .cfg files + +Just create a folder and put files with the extension .cfg. and map the volume to the container. +This will concatenate your config into the main haproxy.cfg + +```bash +docker run \ + /* other parameters */ + -v /your/local/conf.d:/etc/haproxy/conf.d \ + -d byjg/easy-haproxy +``` + +Check if your config is ok: + +```bash +docker run \ + /* other parameters */ + -v /your/local/conf.d:/etc/haproxy/conf.d \ + -byjg/easy-haproxy -c -f /etc/haproxy/haproxy.cfg ``` diff --git a/conf.d/00-simple-comment.cfg b/conf.d/00-simple-comment.cfg new file mode 100644 index 0000000..cf5fc87 --- /dev/null +++ b/conf.d/00-simple-comment.cfg @@ -0,0 +1 @@ +# Simple file include \ No newline at end of file diff --git a/conf.d/README.md b/conf.d/README.md new file mode 100644 index 0000000..661ea82 --- /dev/null +++ b/conf.d/README.md @@ -0,0 +1,3 @@ +# Custom HAProxy + +Put files .cfg to be included in the configuration diff --git a/entrypoint.sh b/entrypoint.sh index 2bcb453..c0d4e56 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash + set -e echo " ______ _ _ _____ " @@ -14,6 +15,8 @@ echo "" defaults() { echo " defaults + log global + timeout connect 3s timeout client 10s timeout server 10m @@ -114,13 +117,22 @@ do done # Write -defaults > $HAPROXY_CFG +defaults > ${HAPROXY_CFG} if [ ! -z "${LB_STATS_USER}" ] then - stats ${LB_STATS_USER} ${LB_STATS_PASS} >> $HAPROXY_CFG + stats ${LB_STATS_USER} ${LB_STATS_PASS} >> ${HAPROXY_CFG} fi -frontend "$FRONTEND" >> $HAPROXY_CFG -backend "$BACKEND" >> $HAPROXY_CFG +frontend "$FRONTEND" >> ${HAPROXY_CFG} +backend "$BACKEND" >> ${HAPROXY_CFG} + +# More +for config in `ls /etc/haproxy/conf.d/*.cfg` +do + echo Loading extra config: ${config} + cat ${config} >> ${HAPROXY_CFG} +done + +echo /sbin/syslogd -O /proc/1/fd/1 /docker-entrypoint.sh "$@"