From 254f3a061094e5a11a17f502402d46868e802658 Mon Sep 17 00:00:00 2001 From: Simon Prinz Date: Sat, 5 Dec 2020 19:03:28 +0100 Subject: [PATCH] add source code from local folder --- Caddyfile | 6 ++++++ Dockerfile | 7 +++++++ README.md | 12 +++++++++++- generateCaddyfile.sh | 9 +++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Caddyfile create mode 100644 Dockerfile create mode 100644 generateCaddyfile.sh diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..1a9ff4f --- /dev/null +++ b/Caddyfile @@ -0,0 +1,6 @@ +:80 { + reverse_proxy { + to HOSTS + lb_policy round_robin + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c5e1fe3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM caddy:2-alpine +WORKDIR /app + +COPY Caddyfile . +COPY generateCaddyfile.sh . + +CMD ["./generateCaddyfile.sh"] diff --git a/README.md b/README.md index 71fd5d6..1da1fee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # CaddyBalancer - A Docker image for load balancing based on Caddy + +A Docker image for load balancing based on Caddy + +## Usage + +```bash +docker run -d \ + -p 8080:80 \ + -e UPSTREAMS="http://12.34.56.78:9999,http://98.76.54.32:1111" \ + docker.pkg.github.com/simonprinz/caddybalancer/caddybalancer:latest +``` diff --git a/generateCaddyfile.sh b/generateCaddyfile.sh new file mode 100644 index 0000000..c81ba50 --- /dev/null +++ b/generateCaddyfile.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# generate Caddyfile +hosts=`echo "$UPSTREAMS" | sed "s|,|\\\\\\n\\t\\tto |"` +sed -i "s|HOSTS|$hosts|" Caddyfile +cat Caddyfile + +# run caddy +caddy run --config /app/Caddyfile --adapter caddyfile