Skip to content

Commit

Permalink
Added make release rule for automated building of the release binary
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Oct 30, 2017
1 parent 8631b04 commit 7c7376d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
pkgs = $(shell go list ./...)

BUILD_CONSTS = \
-X main.buildTime=`date -u '+%Y-%m-%d_%H:%M:%S'` \
-X main.buildRevision=`git rev-parse HEAD` \
-X main.buildTag=`git tag --points-at HEAD`

BUILD_OPTS = -ldflags="$(BUILD_CONSTS)"

install:
go get golang.org/x/crypto/acme/autocert
go get github.com/prometheus/client_golang/prometheus
Expand All @@ -9,7 +16,7 @@ format:
go fmt $(pkgs)

build:
go build
go build $(BUILD_OPTS)

test: build
go test -race -v $(pkgs)
Expand All @@ -18,4 +25,7 @@ run: build
./chproxy -config=testdata/http.conf.yml

reconfigure:
kill -HUP `pidof chproxy`
kill -HUP `pidof chproxy`

release:
GOOS=linux GOARCH=amd64 go build $(BUILD_OPTS) -o chproxy-linux-amd64
24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import (

var (
configFile = flag.String("config", "", "Proxy configuration filename")
v = flag.Bool("v", false, "Prints current version and exits")
version = flag.Bool("version", false, "Prints current version and exits")
)

var (
version = "1.4.0"

proxy = newReverseProxy()

allowedNetworksHTTP atomic.Value
Expand All @@ -36,12 +34,12 @@ var (

func main() {
flag.Parse()
if *v {
fmt.Printf("Version %s\n", version)
if *version {
fmt.Printf("%s\n", versionString())
os.Exit(0)
}

log.Infof("Chproxy version: %s", version)
log.Infof("%s", versionString())
log.Infof("Loading config: %s", *configFile)
cfg, err := reloadConfig()
if err != nil {
Expand Down Expand Up @@ -216,3 +214,17 @@ func reloadConfig() (*config.Server, error) {
log.Infof("Loaded config: \n%s", cfg)
return &cfg.Server, nil
}

func versionString() string {
ver := buildTag
if len(ver) == 0 {
ver = "unknown"
}
return fmt.Sprintf("chproxy ver. %s, rev. %s, built at %s", ver, buildRevision, buildTime)
}

var (
buildTag = "unknown"
buildRevision = "unknown"
buildTime = "unknown"
)

0 comments on commit 7c7376d

Please sign in to comment.