Skip to content

Commit dda31a8

Browse files
authored
Add version endpoint and upx (#3)
* Add ident * add build artifacts to gitignore * Add upx to shrink binary
1 parent 0f92ba2 commit dda31a8

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* ident

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ Session.vim
1212
*~
1313
# auto-generated tag files
1414
tags
15+
16+
# build artifacts
17+
hello_world
18+
docker-hello-world

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ go:
33
- 1.8
44
- 1.9
55
- master
6+
addons:
7+
apt:
8+
packages:
9+
- upx
610
script:
711
- make all

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
FROM golang:1.9.2 AS builder
44
WORKDIR /go/src/github.com/infrastructure-as-code/docker-hello-world
55
ENV GIN_MODE debug
6+
ENV DEBIAN_FRONTEND noninteractive
67
COPY Makefile *.go ./
7-
RUN make all
8+
RUN apt-get update && \
9+
apt-get upgrade -y && \
10+
apt-get install -y upx && \
11+
make all
812

913
FROM scratch
1014
LABEL maintainer "Vince Tse <[email protected]>"

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
all: deps test
22
CGO_ENABLED=0 go build -a -o hello_world
3+
upx --brute hello_world
34

45
test:
56
GIN_MODE=debug go test

hello_world.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func getHostname() string {
1919
return name
2020
}
2121

22+
func getVersion() string {
23+
return "$Id$"
24+
}
25+
2226
func helloFunc(c *gin.Context) {
2327
c.Writer.Header().Set("X-Hostname", hostname)
2428
c.String(http.StatusOK, "Hello, World!")
@@ -29,6 +33,11 @@ func healthFunc(c *gin.Context) {
2933
c.String(http.StatusOK, "")
3034
}
3135

36+
func versionFunc(c *gin.Context) {
37+
c.Writer.Header().Set("X-Hostname", hostname)
38+
c.String(http.StatusOK, getVersion())
39+
}
40+
3241
func setupRouter(routePrefix string) *gin.Engine {
3342
router := gin.Default()
3443
ginprom := ginprometheus.NewPrometheus("gin")
@@ -37,6 +46,7 @@ func setupRouter(routePrefix string) *gin.Engine {
3746

3847
rg := router.Group(routePrefix)
3948
rg.GET("/", helloFunc)
49+
rg.GET("/version", versionFunc)
4050
return router
4151
}
4252

0 commit comments

Comments
 (0)