mirror of
https://github.com/openfaas/faas.git
synced 2025-06-14 03:06:46 +00:00
Added -version flag to watchdog
This changes introduces a new flag -version to watchdog which will display version and SHA of last git commit. Version and SHA are injected at build time and passed as a build-args for Dockerfile. Fixes: #632 Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
parent
f936dcd757
commit
c258637d6d
@ -1,4 +1,6 @@
|
||||
FROM golang:1.9.4 as build
|
||||
ARG VERSION
|
||||
ARG GIT_COMMIT
|
||||
|
||||
RUN mkdir -p /go/src/github.com/openfaas/faas/watchdog
|
||||
WORKDIR /go/src/github.com/openfaas/faas/watchdog
|
||||
@ -8,14 +10,26 @@ COPY readconfig.go .
|
||||
COPY readconfig_test.go .
|
||||
COPY requesthandler_test.go .
|
||||
COPY types types
|
||||
COPY version.go .
|
||||
|
||||
# Run a gofmt and exclude all vendored code.
|
||||
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"
|
||||
|
||||
RUN go test -v ./...
|
||||
|
||||
# Stripping via -ldflags "-s -w"
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o watchdog . \
|
||||
&& GOARM=7 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o watchdog-armhf . \
|
||||
&& GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o watchdog-arm64 . \
|
||||
&& GOOS=windows CGO_ENABLED=0 go build -a -ldflags "-s -w" -installsuffix cgo -o watchdog.exe .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w \
|
||||
-X main.GitCommit=$GIT_COMMIT \
|
||||
-X main.Version=$VERSION" \
|
||||
-installsuffix cgo -o watchdog . \
|
||||
&& GOARM=7 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w \
|
||||
-X main.GitCommit=$GIT_COMMIT \
|
||||
-X main.Version=$VERSION" \
|
||||
-installsuffix cgo -o watchdog-armhf . \
|
||||
&& GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w \
|
||||
-X main.GitCommit=$GIT_COMMIT \
|
||||
-X main.Version=$VERSION" \
|
||||
-installsuffix cgo -o watchdog-arm64 . \
|
||||
&& GOOS=windows CGO_ENABLED=0 go build -a -ldflags "-s -w \
|
||||
-X main.GitCommit=$GIT_COMMIT \
|
||||
-X main.Version=$VERSION" \
|
||||
-installsuffix cgo -o watchdog.exe .
|
||||
|
@ -7,11 +7,17 @@ if [ "$arch" = "armv7l" ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd ..
|
||||
GIT_COMMIT=$(git rev-list -1 HEAD)
|
||||
VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///')
|
||||
cd watchdog
|
||||
|
||||
if [ ! $http_proxy == "" ]
|
||||
then
|
||||
docker build --no-cache --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -t functions/watchdog:build .
|
||||
docker build --no-cache --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \
|
||||
--build-arg GIT_COMMIT=$GIT_COMMIT --build-arg VERSION=$VERSION -t functions/watchdog:build .
|
||||
else
|
||||
docker build -t functions/watchdog:build .
|
||||
docker build --no-cache --build-arg VERSION=$VERSION --build-arg GIT_COMMIT=$GIT_COMMIT -t functions/watchdog:build .
|
||||
fi
|
||||
|
||||
docker create --name buildoutput functions/watchdog:build echo
|
||||
|
@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -309,7 +310,12 @@ func makeRequestHandler(config *WatchdogConfig) func(http.ResponseWriter, *http.
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
version = flag.Bool("version", false, "Print the version and Git SHA")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
acceptingConnections = false
|
||||
|
||||
osEnv := types.OsEnv{}
|
||||
@ -321,6 +327,12 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if *version == true {
|
||||
fmt.Printf("Commit: %v\n", GitCommit)
|
||||
fmt.Printf("Version: %v\n", BuildVersion())
|
||||
return
|
||||
}
|
||||
|
||||
readTimeout := config.readTimeout
|
||||
writeTimeout := config.writeTimeout
|
||||
|
||||
|
18
watchdog/version.go
Normal file
18
watchdog/version.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
var (
|
||||
//Version release version of the watchdog
|
||||
Version string
|
||||
//GitCommit SHA of the last git commit
|
||||
GitCommit string
|
||||
//DevVerison string for the development version
|
||||
DevVerison = "dev"
|
||||
)
|
||||
|
||||
//BuildVersion returns current version of watchdog
|
||||
func BuildVersion() string {
|
||||
if len(Version) == 0 {
|
||||
return DevVerison
|
||||
}
|
||||
return Version
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user