mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
adds docker & release stuff for fnlb
This commit is contained in:
10
fnlb/Dockerfile
Normal file
10
fnlb/Dockerfile
Normal file
@@ -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"]
|
||||
16
fnlb/Makefile
Normal file
16
fnlb/Makefile
Normal file
@@ -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
|
||||
@@ -10,3 +10,24 @@ 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.**
|
||||
|
||||
## 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..
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
40
fnlb/release.sh
Executable file
40
fnlb/release.sh
Executable 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
|
||||
@@ -42,3 +42,6 @@ docker push $user/$service:$tag
|
||||
cd fn
|
||||
./release.sh $version
|
||||
cd ..
|
||||
cd fnlb
|
||||
./release.sh
|
||||
cd ..
|
||||
|
||||
Reference in New Issue
Block a user