From 975f3c083793d07d01e4c1b25d24a69da0cf74e0 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 14 Apr 2021 19:02:44 +0200 Subject: [PATCH] Adapt Makefile and boardvoting.go to new ldflags --- .goreleaser.yml | 8 +++++--- Jenkinsfile | 2 +- Makefile | 5 +++-- boardvoting.go | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index cfa465d..50cafc7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -7,12 +7,14 @@ before: builds: - env: - CGO_ENABLED=1 - ldflags: - - -s -w -X main.version={{.Version}} -X main.build={{.Env.BUILD}} goos: - linux goarch: - amd64 + flags: + - -buildmode=pie + - -trimpath + - -v archives: - replacements: linux: Linux @@ -38,7 +40,7 @@ nfpms: - libsqlite3-0 - adduser priority: optional - bindir: /src/cacert-boardvoting + bindir: /srv/cacert-boardvoting contents: - src: config.yaml.example dst: /usr/share/doc/cacert-boardvoting/examples/config.yaml.example diff --git a/Jenkinsfile b/Jenkinsfile index afc504b..5d00342 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { stages { stage('Build') { steps { - sh "make distclean && make BUILD='${env.BUILD_TAG}'" + sh "make distclean && make" } } stage('Create build output') { diff --git a/Makefile b/Makefile index 73104a6..f83e998 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ VERSION := $(shell git describe --always --dirty=-dev) -BUILD := $(shell date --iso-8601=seconds --utc) +COMMIT := $(shell git show-ref --hash refs/heads/master) +DATE := $(shell date --iso-8601=seconds --utc) GOFILES = $(shell find . -type f -name '*.go') all: cacert-boardvoting cacert-boardvoting: ${GOFILES} - go build -o $@ -buildmode=pie -trimpath -x -ldflags " -s -w -X 'main.version=${VERSION}' -X 'main.build=${BUILD}'" + go build -o $@ -buildmode=pie -trimpath -x -ldflags " -s -w -X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -X 'main.date=${DATE}'" clean: rm -f cacert-boardvoting diff --git a/boardvoting.go b/boardvoting.go index d452636..e69632f 100644 --- a/boardvoting.go +++ b/boardvoting.go @@ -52,7 +52,8 @@ var config *Config var store *sessions.CookieStore var csrfKey []byte var version = "undefined" -var build = "undefined" +var commit = "undefined" +var date = "undefined" const ( cookieSecretMinLen = 32 @@ -1014,7 +1015,7 @@ func setupTLSConfig() (tlsConfig *tls.Config) { func main() { log.SetFormatter(&log.TextFormatter{FullTimestamp: true}) - log.Infof("CAcert Board Voting version %s, build %s", version, build) + log.Infof("CAcert Board Voting version %s, commit %s built at %s", version, commit, date) flag.StringVar( &configFile, "config", "config.yaml", "Configuration file name")