diff --git a/.gitignore b/.gitignore index 8ccb8f1d..0dcad16f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ fwatchdog-armhf **/*.DS_Store .vscode .idea +certifier +.editorconfig diff --git a/.travis.yml b/.travis.yml index 3841dc24..c3f73670 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,8 @@ addons: before_install: script: - - sh build.sh - # Invoke ci script too - - sh contrib/ci.sh + - ./build.sh + - ./contrib/ci.sh after_success: - if [ -z $DOCKER_NS ] ; then diff --git a/Makefile b/Makefile index 34545e02..76dc9078 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ -.PHONY: build +.PHONY: build build-gateway test-ci build: ./build.sh build-gateway: (cd gateway; ./build.sh latest-dev) +test-ci: + ./contrib/ci.sh diff --git a/api-docs/swagger.yml b/api-docs/swagger.yml index 0bbdd8f2..a1a9b807 100644 --- a/api-docs/swagger.yml +++ b/api-docs/swagger.yml @@ -263,6 +263,16 @@ definitions: additionalProperties: type: string description: Overrides to environmental variables + labels: + type: array + items: + type: string + description: An array of labels used by the back-end for making scheduling or routing decisions + annotations: + type: array + items: + type: string + description: An array of annotations used by the back-end for management, orchestration, events and build tasks secrets: type: array items: diff --git a/contrib/ci.sh b/contrib/ci.sh old mode 100644 new mode 100755 index 2c8afc0a..3cdcfd61 --- a/contrib/ci.sh +++ b/contrib/ci.sh @@ -1,39 +1,78 @@ #!/bin/bash - docker swarm init --advertise-addr=127.0.0.1 +set -e ./deploy_stack.sh --no-auth docker service update func_gateway --image=openfaas/gateway:latest-dev # Script makes sure OpenFaaS API gateway is ready before running tests - +wait_success=false for i in {1..30}; do - echo "Checking if 127.0.0.1:8000 is up.. ${i}/30" - curl -fs 127.0.0.1:8080/ + echo "Checking if 127.0.0.1:8000 is up.. ${i}/30" + status_code=$(curl --silent --output /dev/stderr --write-out "%{http_code}" http://127.0.0.1:8080/) - if [ $? -eq 0 ]; then + if [ "$status_code" -ge 200 -a "$status_code" -lt 400 ]; then + echo "Deploying gateway success" + wait_success=true break fi sleep 0.5 done +if [ "$wait_success" != true ] ; then + echo "Failed to wait for gateway" + exit 1 +fi + cd .. echo $GOPATH -mkdir -p $GOPATH/src/github.com/openfaas/ -cp -r faas $GOPATH/src/github.com/openfaas/ +if [ ! -d "$GOPATH/src/github.com/openfaas/" ]; then + mkdir -p $GOPATH/src/github.com/openfaas/ + cp -r faas $GOPATH/src/github.com/openfaas/ +fi -git clone https://github.com/openfaas/certifier +if [ ! -d "$GOPATH/src/github.com/openfaas/certifier" ]; then + git clone https://github.com/openfaas/certifier +fi -cp -r certifier $GOPATH/src/github.com/openfaas/ +echo "Deploying OpenFaaS stack.yml from $(pwd)/faas" +command -v faas-cli >/dev/null 2>&1 || curl -sSL https://cli.openfaas.com | sudo sh +faas-cli deploy -f ./faas/stack.yml +wait_success=false +for i in {1..30} +do + echo "Checking if 127.0.0.1:8080/function/echoit is up.. ${i}/30" + status_code=$(curl --silent --output /dev/stderr --write-out "%{http_code}" http://127.0.0.1:8080/function/echoit -d "hello") + + if [ "$status_code" -ge 200 -a "$status_code" -lt 400 ]; then + echo "Deploying OpenFaaS stack.yml success" + wait_success=true + break + else + echo "Attempt $i lets try again" + fi + + printf '.' + sleep 0.5 +done + +if [ "$wait_success" != true ] ; then + echo "Failed to wait for stack.yml to deploy" + exit 1 +fi + +echo Running integration tests cd $GOPATH/src/github.com/openfaas/faas/gateway/tests/integration && \ - go test -v + go test -v -count=1 +echo Running certifier cd $GOPATH/src/github.com/openfaas/certifier && \ make test +echo Integration tests all PASSED exit 0 diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index fa8cbada..048c1ab1 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -36,6 +36,10 @@ type CreateFunctionRequest struct { // back-end for making scheduling or routing decisions Labels *map[string]string `json:"labels"` + // Annotations are metadata for functions which may be used by the + // back-end for management, orchestration, events and build tasks + Annotations *map[string]string `json:"annotations"` + // Limits for function Limits *FunctionResources `json:"limits"` @@ -67,6 +71,10 @@ type Function struct { // Labels are metadata for functions which may be used by the // back-end for making scheduling or routing decisions Labels *map[string]string `json:"labels"` + + // Annotations are metadata for functions which may be used by the + // back-end for management, orchestration, events and build tasks + Annotations *map[string]string `json:"annotations"` } // AsyncReport is the report from a function executed on a queue worker. diff --git a/gateway/tests/integration/README.md b/gateway/tests/integration/README.md index 899df19d..549fc200 100644 --- a/gateway/tests/integration/README.md +++ b/gateway/tests/integration/README.md @@ -2,3 +2,15 @@ These tests should be run against the sample stack included in the repository root. +## Deploy the stack +``` +./deploy_stack.sh +faas-cli deploy -f ./stack.yml +``` + +## Remove the stack +1. Delete all OpenFaaS deployed functions +``` +faas-cli remove +docker stack rm func +``` \ No newline at end of file diff --git a/gateway/tests/integration/infohandler_test.go b/gateway/tests/integration/infohandler_test.go index a9f803d3..7d5da69b 100644 --- a/gateway/tests/integration/infohandler_test.go +++ b/gateway/tests/integration/infohandler_test.go @@ -34,7 +34,7 @@ func Test_InfoEndpoint_Returns_Gateway_Version_SHA_And_Message(t *testing.T) { gatewayInfo := &types.GatewayInfo{} err = json.Unmarshal([]byte(body), gatewayInfo) if err != nil { - t.Log(err) + t.Errorf("Could not unmarshal gateway info, response body:%s, error:%s", body, err.Error()) t.Fail() } diff --git a/sample-functions/WebhookStash/handler.go b/sample-functions/WebhookStash/handler.go index f2a0516f..7474a110 100644 --- a/sample-functions/WebhookStash/handler.go +++ b/sample-functions/WebhookStash/handler.go @@ -3,17 +3,17 @@ package main import ( "fmt" "io/ioutil" + "log" "os" "strconv" "time" - "log" ) func main() { input, err := ioutil.ReadAll(os.Stdin) if err != nil { log.Fatalf("Cannot read input %s.\n", err) - return + return } now := time.Now() stamp := strconv.FormatInt(now.UnixNano(), 10) @@ -21,7 +21,7 @@ func main() { writeErr := ioutil.WriteFile(stamp+".txt", input, 0644) if writeErr != nil { log.Fatalf("Cannot write input %s.\n", err) - return + return } fmt.Printf("Stashing request: %s.txt\n", stamp)