From 956d7cf3f31ea949a34537ff2f08a6b9f5918b6c Mon Sep 17 00:00:00 2001 From: Wim Date: Fri, 17 Feb 2017 22:32:42 +0100 Subject: [PATCH] Add githash to docker builds --- Dockerfile | 2 +- matterbridge.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index e2f54669..bcf173bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ RUN apk update && apk add go git gcc musl-dev ca-certificates \ && cd /go/src/github.com/42wim/matterbridge \ && export GOPATH=/go \ && go get \ - && go build -o /bin/matterbridge \ + && go build -x -ldflags "-X main.githash=$(git log --pretty=format:'%h' -n 1)" -o /bin/matterbridge \ && rm -rf /go \ && apk del --purge git go gcc musl-dev diff --git a/matterbridge.go b/matterbridge.go index 32bc4285..7dfaaa22 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -9,7 +9,10 @@ import ( log "github.com/Sirupsen/logrus" ) -var version = "0.9.3-dev" +var ( + version = "0.9.3-dev" + githash string +) func init() { log.SetFormatter(&log.TextFormatter{FullTimestamp: true}) @@ -21,25 +24,25 @@ func main() { flagVersion := flag.Bool("version", false, "show version") flag.Parse() if *flagVersion { - fmt.Println("version:", version) + fmt.Printf("version: %s %s\n", version, githash) return } flag.Parse() if *flagDebug { - log.Info("enabling debug") + log.Info("Enabling debug") log.SetLevel(log.DebugLevel) } - fmt.Println("running version", version) + log.Printf("Running version %s %s", version, githash) cfg := config.NewConfig(*flagConfig) for _, gw := range cfg.SameChannelGateway { if !gw.Enable { continue } - fmt.Printf("starting samechannel gateway %#v\n", gw.Name) + log.Printf("Starting samechannel gateway %#v", gw.Name) g := samechannelgateway.New(cfg, &gw) err := g.Start() if err != nil { - log.Fatalf("starting gateway failed %#v", err) + log.Fatalf("Starting gateway failed %#v", err) } } @@ -47,11 +50,11 @@ func main() { if !gw.Enable { continue } - fmt.Printf("starting gateway %#v\n", gw.Name) + log.Printf("Starting gateway %#v", gw.Name) g := gateway.New(cfg, &gw) err := g.Start() if err != nil { - log.Fatalf("starting gateway failed %#v", err) + log.Fatalf("Starting gateway failed %#v", err) } } select {}