Skip to content

Commit ac12a4d

Browse files
committed
Add -version
1 parent 613bd8d commit ac12a4d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.SILENT :
22
.PHONY : docker-gen clean fmt
33

4+
TAG:=`git describe --abbrev=0 --tags`
5+
LDFLAGS:=-X main.buildVersion $(TAG)
6+
47
all: docker-gen
58

69
docker-gen:
710
echo "Building docker-gen"
8-
go build
11+
go build -ldflags "$(LDFLAGS)"
912

1013
dist-clean:
1114
rm -rf dist
@@ -17,5 +20,5 @@ dist: dist-clean
1720

1821
release: dist
1922
godep restore
20-
tar -cvzf docker-gen-linux-amd64-latest.tar.gz -C dist/linux/amd64 docker-gen
21-
tar -cvzf docker-gen-linux-i386-latest.tar.gz -C dist/linux/i386 docker-gen
23+
tar -cvzf docker-gen-linux-amd64-$(TAG).tar.gz -C dist/linux/amd64 docker-gen
24+
tar -cvzf docker-gen-linux-i386-$(TAG).tar.gz -C dist/linux/i386 docker-gen

docker-gen.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
)
1616

1717
var (
18+
buildVersion string
19+
version bool
1820
watch bool
1921
notifyCmd string
2022
onlyExposed bool
@@ -198,6 +200,7 @@ func generateFromEvents(client *docker.Client, configs ConfigFile) {
198200
}
199201

200202
func initFlags() {
203+
flag.BoolVar(&version, "version", false, "show version")
201204
flag.BoolVar(&watch, "watch", false, "watch for container changes")
202205
flag.BoolVar(&onlyExposed, "only-exposed", false, "only include containers with exposed ports")
203206
flag.BoolVar(&onlyPublished, "only-published", false, "only include containers with published ports (implies -only-exposed)")
@@ -211,6 +214,11 @@ func initFlags() {
211214
func main() {
212215
initFlags()
213216

217+
if version {
218+
fmt.Println(buildVersion)
219+
return
220+
}
221+
214222
if flag.NArg() < 1 && configFile == "" {
215223
usage()
216224
os.Exit(1)

0 commit comments

Comments
 (0)