Skip to content

Commit

Permalink
Add version and commit hash to binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kibish committed Oct 13, 2019
1 parent 7a0e25a commit efcc06e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
.PHONY: test build
.DEFAULT_GOAL := help

GIT_COMMIT=$(shell git rev-list -1 HEAD)
GIT_VERSION=$(shell git describe --abbrev=0 --tags)

test: ## run tests
go test -v -cover -race `go list ./... | grep -v /vendor/`

build: ## build binaries for distribution
GOOS=linux GOARCH=amd64 go build -o ddns-Linux-x86_64 .
GOOS=darwin GOARCH=amd64 go build -o ddns-Darwin-x86_64 .
GOOS=linux GOARCH=arm GOARM=7 go build -o ddns-Linux-armv7l .
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.buildVersion=$(GIT_VERSION) -X main.buildCommitHash=$(GIT_COMMIT)" -o ddns-Linux-x86_64 .
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.buildVersion=$(GIT_VERSION) -X main.buildCommitHash=$(GIT_COMMIT)" -o ddns-Darwin-x86_64 .
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-X main.buildVersion=$(GIT_VERSION) -X main.buildCommitHash=$(GIT_COMMIT)" -o ddns-Linux-armv7l .

help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Usage of ./ddns:
Location of the configuration file (default "$HOME/.ddns.yml")
-req-timeout duration
Request timeout to external resources (default 10s)
-v Show version and exit
```

**Configuration should be supplied.** By default it is read from `$HOME/.ddns.yml`.
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"time"
Expand All @@ -17,6 +18,11 @@ import (
"github.com/skibish/ddns/notifier"
)

var (
buildVersion string
buildCommitHash string
)

func main() {
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
Expand All @@ -28,9 +34,15 @@ func main() {
reqTimeouts = flag.Duration("req-timeout", 10*time.Second, "Request timeout to external resources")
checkPeriod = flag.Duration("check-period", 5*time.Minute, "Check if IP has been changed period")
confFile = flag.String("conf-file", "$HOME/.ddns.yml", "Location of the configuration file")
showVersion = flag.Bool("v", false, "Show version and exit")
)
flag.Parse()

if *showVersion {
fmt.Printf("Version: %s\nCommitHash: %s\n", buildVersion, buildCommitHash)
return
}

// read configuration
var errConf error
cf, errConf := conf.NewConfiguration(*confFile)
Expand Down

0 comments on commit efcc06e

Please sign in to comment.