diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..31884f8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* ident diff --git a/.gitignore b/.gitignore index 447ab76..d5ea5bc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ Session.vim *~ # auto-generated tag files tags + +# build artifacts +hello_world +docker-hello-world diff --git a/.travis.yml b/.travis.yml index 0ac1e0d..2c5155b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,9 @@ go: - 1.8 - 1.9 - master +addons: + apt: + packages: + - upx script: - make all diff --git a/Dockerfile b/Dockerfile index 20eeb01..e47fdd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,12 @@ FROM golang:1.9.2 AS builder WORKDIR /go/src/github.com/infrastructure-as-code/docker-hello-world ENV GIN_MODE debug +ENV DEBIAN_FRONTEND noninteractive COPY Makefile *.go ./ -RUN make all +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y upx && \ + make all FROM scratch LABEL maintainer "Vince Tse " diff --git a/Makefile b/Makefile index 2edc088..2b8873e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ all: deps test CGO_ENABLED=0 go build -a -o hello_world + upx --brute hello_world test: GIN_MODE=debug go test diff --git a/hello_world.go b/hello_world.go index fc2bd0f..316e984 100644 --- a/hello_world.go +++ b/hello_world.go @@ -19,6 +19,10 @@ func getHostname() string { return name } +func getVersion() string { + return "$Id$" +} + func helloFunc(c *gin.Context) { c.Writer.Header().Set("X-Hostname", hostname) c.String(http.StatusOK, "Hello, World!") @@ -29,6 +33,11 @@ func healthFunc(c *gin.Context) { c.String(http.StatusOK, "") } +func versionFunc(c *gin.Context) { + c.Writer.Header().Set("X-Hostname", hostname) + c.String(http.StatusOK, getVersion()) +} + func setupRouter(routePrefix string) *gin.Engine { router := gin.Default() ginprom := ginprometheus.NewPrometheus("gin") @@ -37,6 +46,7 @@ func setupRouter(routePrefix string) *gin.Engine { rg := router.Group(routePrefix) rg.GET("/", helloFunc) + rg.GET("/version", versionFunc) return router }