Merge branch 'fnlb-docker' into 'master'

adds docker & release stuff for fnlb

Closes #58

See merge request !65
This commit is contained in:
Derek Schultz
2017-06-29 10:57:04 -07:00
7 changed files with 130 additions and 3 deletions

9
fnlb/Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
FROM alpine
RUN apk --update upgrade && \
apk add --no-cache curl ca-certificates && \
update-ca-certificates
WORKDIR /app
ADD fnlb-alpine /app/fnlb
ENTRYPOINT ["./fnlb"]

13
fnlb/Makefile Normal file
View File

@@ -0,0 +1,13 @@
# 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 .
all: build

View File

@@ -9,4 +9,58 @@ fnlb --listen <address-for-incoming> --nodes <node1>,<node2>,<node3>
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.**
**NOTE: For the load balancer to be of use, all function nodes need to be sharing the same DB.**
## Running with docker
To build a docker image for `fnlb` just run (in `fnlb/`):
```
make docker-build
```
To start the `fnlb` proxy with the addresses of functions nodes in a docker
container:
```sh
docker run -d --name fnlb -p 8081:8081 funcy/fnlb:latest --nodes <node1>,<node2>
```
If running locally with functions servers in docker, running with docker links
can make things easier (can use local addresses). for example:
```sh
docker run -d --name fn-8080 --privileged -p 8080:8080 funcy/functions:latest
docker run -d --name fnlb --link fn-8080 -p 8081:8081 funcy/fnlb:latest --nodes 127.0.0.1:8080
```
## Operating / usage
To make functions requests against the lb with the cli:
```sh
API_URL=http://<fnlb_address> fn call my/function
```
To add a functions node later:
```sh
curl -sSL -X PUT -d '{"node":"<node>"}' <fnlb_address>/1/lb/nodes
```
`<node>` should be the address of a functions server. The lb will health check
this and log if it cannot reach that node as well as stop sending requests to
that node until it begins passing health checks again. Any number of functions
servers may be added to the load balancer.
To permanently remove a functions node:
```sh
curl -sSL -X DELETE -d '{"node":"<node>"}' <fnlb_address>/1/lb/nodes
```
To list functions nodes and their state:
```sh
curl -sSL -X GET <fnlb_address>/1/lb/nodes
```

View File

@@ -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()

View File

@@ -17,9 +17,11 @@ 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")
fnodes := flag.String("nodes", "", "comma separated list of functions nodes")
var conf lb.Config
flag.StringVar(&conf.Listen, "listen", ":8081", "port to run on")
@@ -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,

40
fnlb/release.sh Executable file
View File

@@ -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

View File

@@ -42,3 +42,6 @@ docker push $user/$service:$tag
cd fn
./release.sh $version
cd ..
cd fnlb
./release.sh
cd ..