From 2420b387b5cb39738027596413001c3113dc6075 Mon Sep 17 00:00:00 2001 From: "Ivana Yovcheva (VMware)" Date: Wed, 26 Jun 2019 22:28:35 +0300 Subject: [PATCH] Add architecture to /system/info endpoint With this change /system/info endpoint is going to give information about the platform architecture it is running on (arm64, armhf, x86_64) Signed-off-by: Ivana Yovcheva (VMware) --- api-docs/swagger.yml | 4 ++++ gateway/Dockerfile | 4 +++- gateway/build.sh | 3 +++ gateway/handlers/infohandler.go | 1 + gateway/tests/integration/infohandler_test.go | 20 +++++++++++++++++++ gateway/types/inforequest.go | 4 ++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/api-docs/swagger.yml b/api-docs/swagger.yml index 0fed4c4c..a2983404 100644 --- a/api-docs/swagger.yml +++ b/api-docs/swagger.yml @@ -434,6 +434,10 @@ definitions: type: string format: semver example: 0.8.9 + arch: + type: string + description: "Platform architecture" + example: "x86_64" required: - provider - version diff --git a/gateway/Dockerfile b/gateway/Dockerfile index 497113aa..4baaf5a1 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -2,6 +2,7 @@ FROM golang:1.10.4 as build ARG GIT_COMMIT_SHA ARG GIT_COMMIT_MESSAGE ARG VERSION='dev' +ARG ARCH RUN curl -sLSf \ https://raw.githubusercontent.com/teamserverless/license-check/master/get.sh | sh \ @@ -30,7 +31,8 @@ RUN license-check -path ./ --verbose=false "Alex Ellis" "OpenFaaS Project" "Open && CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w \ -X github.com/openfaas/faas/gateway/version.GitCommitSHA=${GIT_COMMIT_SHA}\ -X \"github.com/openfaas/faas/gateway/version.GitCommitMessage=${GIT_COMMIT_MESSAGE}\"\ - -X github.com/openfaas/faas/gateway/version.Version=${VERSION}" \ + -X \"github.com/openfaas/faas/gateway/version.Version=${VERSION}\" \ + -X github.com/openfaas/faas/gateway/types.Arch=${ARCH}"\ -a -installsuffix cgo -o gateway . FROM alpine:3.9 diff --git a/gateway/build.sh b/gateway/build.sh index 689e1738..af01ba87 100755 --- a/gateway/build.sh +++ b/gateway/build.sh @@ -9,7 +9,9 @@ export eTAG="latest-dev" if [ "$arch" = "armv7l" ] ; then dockerfile="Dockerfile.armhf" eTAG="latest-armhf-dev" + arch="armhf" elif [ "$arch" = "aarch64" ] ; then + arch="arm64" dockerfile="Dockerfile.arm64" eTAG="latest-arm64-dev" fi @@ -35,4 +37,5 @@ VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | se docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \ --build-arg GIT_COMMIT_MESSAGE="$GIT_COMMIT_MESSAGE" --build-arg GIT_COMMIT_SHA=$GIT_COMMIT_SHA \ --build-arg VERSION=${VERSION:-dev} \ + --build-arg ARCH=$arch \ -t $NS/gateway:$eTAG . -f $dockerfile --no-cache diff --git a/gateway/handlers/infohandler.go b/gateway/handlers/infohandler.go index 7c70bf69..daace8c4 100644 --- a/gateway/handlers/infohandler.go +++ b/gateway/handlers/infohandler.go @@ -48,6 +48,7 @@ func MakeInfoHandler(h http.Handler) http.HandlerFunc { Name: provider["provider"].(string), Orchestration: provider["orchestration"].(string), }, + Arch: types.Arch, } jsonOut, marshalErr := json.Marshal(gatewayInfo) diff --git a/gateway/tests/integration/infohandler_test.go b/gateway/tests/integration/infohandler_test.go index 7d5da69b..161d7a54 100644 --- a/gateway/tests/integration/infohandler_test.go +++ b/gateway/tests/integration/infohandler_test.go @@ -46,3 +46,23 @@ func Test_InfoEndpoint_Returns_Gateway_Version_SHA_And_Message(t *testing.T) { t.Errorf("length of commit message should be greater than 0. Json body was %s", body) } } + +func Test_InfoEndpoint_Returns_Arch(t *testing.T) { + body, _, err := fireRequest("http://localhost:8080/system/info", http.MethodGet, "") + + if err != nil { + t.Log(err) + t.Fail() + } + + gatewayInfo := &types.GatewayInfo{} + err = json.Unmarshal([]byte(body), gatewayInfo) + if err != nil { + t.Errorf("Could not unmarshal gateway info, response body:%s, error:%s", body, err.Error()) + t.Fail() + } + + if len(gatewayInfo.Arch) == 0 { + t.Errorf("value of arch should be non-empty") + } +} diff --git a/gateway/types/inforequest.go b/gateway/types/inforequest.go index 0b3e0a26..a07883be 100644 --- a/gateway/types/inforequest.go +++ b/gateway/types/inforequest.go @@ -1,9 +1,13 @@ package types +// Platform architecture the gateway is running on +var Arch string + // GatewayInfo provides information about the gateway and it's connected components type GatewayInfo struct { Provider *ProviderInfo `json:"provider"` Version *VersionInfo `json:"version"` + Arch string `json:"arch"` } // ProviderInfo provides information about the configured provider