From dd5f118a0d2d59da7dcb246934e4ed9adfbae407 Mon Sep 17 00:00:00 2001 From: Henrique Chehad Date: Fri, 16 Sep 2016 20:37:22 -0300 Subject: [PATCH] created caddy load balancer example --- examples/caddy-lb/Caddyfile | 5 +++ examples/caddy-lb/README.md | 58 ++++++++++++++++++++++++++++ examples/caddy-lb/docker-compose.yml | 23 +++++++++++ 3 files changed, 86 insertions(+) create mode 100644 examples/caddy-lb/Caddyfile create mode 100644 examples/caddy-lb/README.md create mode 100644 examples/caddy-lb/docker-compose.yml diff --git a/examples/caddy-lb/Caddyfile b/examples/caddy-lb/Caddyfile new file mode 100644 index 000000000..45f610e4f --- /dev/null +++ b/examples/caddy-lb/Caddyfile @@ -0,0 +1,5 @@ +:9000 { + proxy / {$LB_HOST01} {$LB_HOST02} {$LB_HOST03} { + policy least_conn + } +} \ No newline at end of file diff --git a/examples/caddy-lb/README.md b/examples/caddy-lb/README.md new file mode 100644 index 000000000..7af2a76a6 --- /dev/null +++ b/examples/caddy-lb/README.md @@ -0,0 +1,58 @@ +# IronFunctions Load Balance example using Caddy + +Simple example of IronFunctions load balancer using Caddy Server + + +## Run IronFunctions + +Start the IronFunctions instances + +Ref: https://github.com/iron-io/functions/blob/master/README.md#start-the-ironfunctions-api + + +## Configure environment variable + +Pass the host and port of IronFunctions instances in environment variables, +this example uses three IronFunctions instances. + +```sh +export LB_HOST01="172.17.0.1:8080" +export LB_HOST02="172.17.0.1:8081" +export LB_HOST03="172.17.0.1:8082" +``` + +Note: Caddy doesn't support multiple hosts in only one variable. + + +## Run Caddy + +```sh +docker run --rm \ + -v $PWD/Caddyfile:/etc/Caddyfile \ + -e LB_HOST01=$LB_HOST01 -e LB_HOST02=$LB_HOST02 -e LB_HOST03=$LB_HOST03 \ + -p 9000:9000 \ + abiosoft/caddy +``` + +## Execute a function + +Follow the Quick-Start steps replacing the example hosts by the Caddy host (localhost:9000) + +https://github.com/iron-io/functions/blob/master/README.md#quick-start + + +## Docker Compose example + +This is an additional example. + +```sh +docker-compose up +``` + + +## Caddy Reference: + +* https://github.com/mholt/caddy +* https://caddyserver.com/ + + diff --git a/examples/caddy-lb/docker-compose.yml b/examples/caddy-lb/docker-compose.yml new file mode 100644 index 000000000..d2ea9d834 --- /dev/null +++ b/examples/caddy-lb/docker-compose.yml @@ -0,0 +1,23 @@ +ironfunctions01: + restart: always + image: iron/functions +ironfunctions02: + restart: always + image: iron/functions +ironfunctions03: + restart: always + image: iron/functions +caddy: + image: abiosoft/caddy + volumes: + - ./Caddyfile:/etc/Caddyfile + ports: + - "9000:9000" + environment: + - LB_HOST01=ironfunctions01:8080 + - LB_HOST02=ironfunctions02:8080 + - LB_HOST03=ironfunctions01:8080 + links: + - ironfunctions01 + - ironfunctions02 + - ironfunctions03 \ No newline at end of file