From 4b85b9841202fdbaaf6520e5f204832322d5c221 Mon Sep 17 00:00:00 2001 From: Joao M Date: Sat, 20 Aug 2022 15:50:11 +0000 Subject: [PATCH] Some log information and error treatment --- .github/workflows/build.yml | 2 ++ Dockerfile | 4 ++++ Makefile | 4 +++- README.md | 6 ++++++ assets/scripts/banner.txt | 5 +++++ assets/scripts/certbot.sh | 4 ++++ assets/scripts/haproxy-reload.sh | 5 +++++ assets/scripts/haproxy.sh | 8 ++++++++ docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ 9 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 assets/scripts/banner.txt create mode 100644 docker-compose.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 289fcb9..e18c8a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,6 +69,8 @@ jobs: with: context: . file: Dockerfile + build-args: | + RELEASE_VERSION_ARG="${{ join(steps.meta.outputs.tags, ',') }} - ${{ env.GITHUB_SHA }}" platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index ef19a6f..9cb2339 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ FROM alpine:3.16 +ARG RELEASE_VERSION_ARG + +ENV RELEASE_VERSION=$RELEASE_VERSION_ARG + WORKDIR /scripts COPY requirements.txt /scripts diff --git a/Makefile b/Makefile index d721ef9..4c3b4e4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ +VERSION := $(shell git rev-parse --short HEAD) + .PHONY: build build: - docker build -t byjg/easy-haproxy -t byjg/easy-haproxy:local . + docker build -t byjg/easy-haproxy --build-arg RELEASE_VERSION_ARG="$(VERSION)" -t byjg/easy-haproxy:local . .PHONY: test test: diff --git a/README.md b/README.md index 7320e43..786a355 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,12 @@ docker run --network easyhaproxy byjg/easyhaproxy docker run --network easyhaproxy myimage ``` +or, if the container is already created you can join it using the command: + +``` +docker network connect easyhaproxy mycontainer +``` + ### EASYHAPROXY_DISCOVER: swarm This method requires a functional Docker Swarm Cluster. The system will search for the labels in all containers on all diff --git a/assets/scripts/banner.txt b/assets/scripts/banner.txt new file mode 100644 index 0000000..f897aab --- /dev/null +++ b/assets/scripts/banner.txt @@ -0,0 +1,5 @@ + _ + ___ __ _ ____ _ ___| |_ __ _ _ __ _ _ _____ ___ _ +/ -_) _` (_-< || |___| ' \/ _` | '_ \ '_/ _ \ \ / || | +\___\__,_/__/\_, | |_||_\__,_| .__/_| \___/_\_\\_, | + |__/ |_| |__/ diff --git a/assets/scripts/certbot.sh b/assets/scripts/certbot.sh index 6d9113d..eea18eb 100755 --- a/assets/scripts/certbot.sh +++ b/assets/scripts/certbot.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +if [ ! -f /scripts/letsencrypt_hosts.txt ]; then + exit 0 +fi + # Semaphore if [ -f /tmp/certbot-lock ]; then echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Another process is running" diff --git a/assets/scripts/haproxy-reload.sh b/assets/scripts/haproxy-reload.sh index 1d55fe5..8e2df83 100755 --- a/assets/scripts/haproxy-reload.sh +++ b/assets/scripts/haproxy-reload.sh @@ -4,6 +4,11 @@ cd /scripts RELOAD="true" +if [[ "static|docker|swarm" != *"$EASYHAPROXY_DISCOVER"* ]];then + echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") ERROR: EASYHAPROXY_DISCOVER should be 'static', 'docker', or 'swarm'. I got '$EASYHAPROXY_DISCOVER' instead." + exit 1 +fi + if [[ "$EASYHAPROXY_DISCOVER" == "static" ]]; then CONTROL_FILE="/etc/haproxy/haproxy.cfg" touch ${CONTROL_FILE} diff --git a/assets/scripts/haproxy.sh b/assets/scripts/haproxy.sh index b830088..08b98c8 100755 --- a/assets/scripts/haproxy.sh +++ b/assets/scripts/haproxy.sh @@ -10,6 +10,14 @@ if [ -z "$EASYHAPROXY_REFRESH_CONF" ]; then export EASYHAPROXY_REFRESH_CONF=10 fi + +cat banner.txt +echo Release: $RELEASE_VERSION +echo +echo "Environment" +env | sort | grep 'HAPROXY' | xargs -I{} echo " - {} " +echo + /scripts/haproxy-reload.sh initial while true; do diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2af38f1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3" + +services: + easyhaproxy: + image: byjg/easy-haproxy:4.1.0 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - certs_letsencrypt:/certs/letsencrypt + - certs_haproxy:/certs/haproxy + + environment: + EASYHAPROXY_DISCOVER: docker + EASYHAPROXY_LABEL_PREFIX: easyhaproxy + EASYHAPROXY_LETSENCRYPT_EMAIL: changeme@example.org + EASYHAPROXY_SSL_MODE: "default" + HAPROXY_CUSTOMERRORS: "true" + HAPROXY_USERNAME: admin + HAPROXY_PASSWORD: password + HAPROXY_STATS_PORT: 1936 + + ports: + - "80:80/tcp" + - "443:443/tcp" + - "1936:1936/tcp" + +volumes: + certs_letsencrypt: + certs_haproxy: + +networks: + easyhaproxy: + driver: bridge