From bcd9f1253efcea761ecab41b77b81d3da52875cc Mon Sep 17 00:00:00 2001 From: Reed Allman Date: Sun, 11 Jun 2017 07:18:18 -0700 Subject: [PATCH] adds docker & release stuff for fnlb --- fnlb/Dockerfile | 10 ++++++++++ fnlb/Makefile | 16 ++++++++++++++++ fnlb/README.md | 23 ++++++++++++++++++++++- fnlb/lb/allgrouper.go | 3 +++ fnlb/main.go | 7 ++++++- fnlb/release.sh | 40 ++++++++++++++++++++++++++++++++++++++++ release.sh | 3 +++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 fnlb/Dockerfile create mode 100644 fnlb/Makefile create mode 100755 fnlb/release.sh diff --git a/fnlb/Dockerfile b/fnlb/Dockerfile new file mode 100644 index 000000000..5e1a1ed4b --- /dev/null +++ b/fnlb/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine + +RUN apk --update upgrade && \ + apk add curl ca-certificates && \ + update-ca-certificates && \ + rm -rf /var/cache/apk/* + +WORKDIR /app +ADD fnlb-alpine /app/fnlb +ENTRYPOINT ["./fnlb"] diff --git a/fnlb/Makefile b/fnlb/Makefile new file mode 100644 index 000000000..000205bb4 --- /dev/null +++ b/fnlb/Makefile @@ -0,0 +1,16 @@ +# Just builds +.PHONY: all build + +build: + go build + +docker-build: + docker pull funcy/go:dev + docker run --rm -v ${GOPATH}/src/gitlab-odx.oracle.com/odx/functions:/go/src/gitlab-odx.oracle.com/odx/functions \ + -w /go/src/gitlab-odx.oracle.com/odx/functions/fnlb funcy/go:dev go build -o fnlb-alpine + docker build --build-arg HTTP_PROXY -t funcy/fnlb:latest . + +docker-run: docker-build + docker run --rm -it --net=host -p 8081:8081 funcy/fnlb + +all: build diff --git a/fnlb/README.md b/fnlb/README.md index 14033be33..0e8eef76b 100644 --- a/fnlb/README.md +++ b/fnlb/README.md @@ -9,4 +9,25 @@ fnlb --listen --nodes ,, And redirect all traffic to the load balancer. -**NOTE: For the load balancer to work all function nodes need to be sharing the same DB.** \ No newline at end of file +**NOTE: For the load balancer to work all function nodes need to be sharing the same DB.** + +## Running with docker + +```sh +make docker-build +make docker-run +curl -X PUT -d '{"node":"127.0.0.1:8080"}' localhost:8081/1/lb/nodes +``` + +`127.0.0.1:8080` should be the address of a functions server. The lb will health +check this and log if it cannot reach that node. By default, docker-run runs +with --net=host and should work out of the box. Any number of functions +servers may be added to the load balancer. + +To make functions requests against the lb: + +```sh +API_URL=http://localhost:8081 fn call my/function +``` + +## TODO More docs to be added for complex installs.. diff --git a/fnlb/lb/allgrouper.go b/fnlb/lb/allgrouper.go index 2f63d5d6c..e23254cd7 100644 --- a/fnlb/lb/allgrouper.go +++ b/fnlb/lb/allgrouper.go @@ -53,6 +53,9 @@ type allGrouper struct { } func (a *allGrouper) add(newb string) { + if newb == "" { + return // we can't really do a lot of validation since hosts could be an ip or domain but we have health checks + } a.Lock() a.addNoLock(newb) a.Unlock() diff --git a/fnlb/main.go b/fnlb/main.go index 86670d9cc..af8340b4d 100644 --- a/fnlb/main.go +++ b/fnlb/main.go @@ -17,6 +17,8 @@ import ( "gitlab-odx.oracle.com/odx/functions/fnlb/lb" ) +const VERSION = "0.0.1" + func main() { // XXX (reed): normalize fnodes := flag.String("nodes", "", "comma separated list of IronFunction nodes") @@ -29,7 +31,10 @@ func main() { flag.IntVar(&conf.HealthcheckTimeout, "hc-timeout", 5, "timeout of healthcheck endpoint, in seconds") flag.Parse() - conf.Nodes = strings.Split(*fnodes, ",") + if len(*fnodes) > 0 { + // starting w/o nodes is fine too + conf.Nodes = strings.Split(*fnodes, ",") + } conf.Transport = &http.Transport{ Proxy: http.ProxyFromEnvironment, diff --git a/fnlb/release.sh b/fnlb/release.sh new file mode 100755 index 000000000..fb4dcecd6 --- /dev/null +++ b/fnlb/release.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -ex + +user="funcy" +service="fnlb" +tag="latest" + +# ensure working dir is clean +git status +if [[ -z $(git status -s) ]] +then + echo "tree is clean" +else + echo "tree is dirty, please commit changes before running this" + exit 1 +fi + +git pull + +version_file="main.go" +if [ -z $(grep -m1 -Eo "[0-9]+\.[0-9]+\.[0-9]+" $version_file) ]; then + echo "did not find semantic version in $version_file" + exit 1 +fi +perl -i -pe 's/\d+\.\d+\.\K(\d+)/$1+1/e' $version_file +version=$(grep -m1 -Eo "[0-9]+\.[0-9]+\.[0-9]+" $version_file) +echo "Version: $version" + +make docker-build + +git add -u +git commit -m "$service: $version release [skip ci]" +git tag -f -a "$version" -m "version $version" +git push +git push origin $version + +# Finally tag and push docker images +docker tag $user/$service:$tag $user/$service:$version +docker push $user/$service:$version +docker push $user/$service:$tag diff --git a/release.sh b/release.sh index 9a87d0f0f..81691642b 100755 --- a/release.sh +++ b/release.sh @@ -42,3 +42,6 @@ docker push $user/$service:$tag cd fn ./release.sh $version cd .. +cd fnlb +./release.sh +cd ..