Skip to content

Commit

Permalink
Add version endpoint and upx (#3)
Browse files Browse the repository at this point in the history
* Add ident

* add build artifacts to gitignore

* Add upx to shrink binary
  • Loading branch information
vincetse authored Dec 2, 2017
1 parent 0f92ba2 commit dda31a8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* ident
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ Session.vim
*~
# auto-generated tag files
tags

# build artifacts
hello_world
docker-hello-world
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ go:
- 1.8
- 1.9
- master
addons:
apt:
packages:
- upx
script:
- make all
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions hello_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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")
Expand All @@ -37,6 +46,7 @@ func setupRouter(routePrefix string) *gin.Engine {

rg := router.Group(routePrefix)
rg.GET("/", helloFunc)
rg.GET("/version", versionFunc)
return router
}

Expand Down

0 comments on commit dda31a8

Please sign in to comment.