Adapt Makefile and boardvoting.go to new ldflags

This commit is contained in:
Jan Dittberner 2021-04-14 19:02:44 +02:00
parent 4d87e35ec2
commit 975f3c0837
4 changed files with 12 additions and 8 deletions

View file

@ -7,12 +7,14 @@ before:
builds: builds:
- env: - env:
- CGO_ENABLED=1 - CGO_ENABLED=1
ldflags:
- -s -w -X main.version={{.Version}} -X main.build={{.Env.BUILD}}
goos: goos:
- linux - linux
goarch: goarch:
- amd64 - amd64
flags:
- -buildmode=pie
- -trimpath
- -v
archives: archives:
- replacements: - replacements:
linux: Linux linux: Linux
@ -38,7 +40,7 @@ nfpms:
- libsqlite3-0 - libsqlite3-0
- adduser - adduser
priority: optional priority: optional
bindir: /src/cacert-boardvoting bindir: /srv/cacert-boardvoting
contents: contents:
- src: config.yaml.example - src: config.yaml.example
dst: /usr/share/doc/cacert-boardvoting/examples/config.yaml.example dst: /usr/share/doc/cacert-boardvoting/examples/config.yaml.example

2
Jenkinsfile vendored
View file

@ -24,7 +24,7 @@ pipeline {
stages { stages {
stage('Build') { stage('Build') {
steps { steps {
sh "make distclean && make BUILD='${env.BUILD_TAG}'" sh "make distclean && make"
} }
} }
stage('Create build output') { stage('Create build output') {

View file

@ -1,11 +1,12 @@
VERSION := $(shell git describe --always --dirty=-dev) 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') GOFILES = $(shell find . -type f -name '*.go')
all: cacert-boardvoting all: cacert-boardvoting
cacert-boardvoting: ${GOFILES} 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: clean:
rm -f cacert-boardvoting rm -f cacert-boardvoting

View file

@ -52,7 +52,8 @@ var config *Config
var store *sessions.CookieStore var store *sessions.CookieStore
var csrfKey []byte var csrfKey []byte
var version = "undefined" var version = "undefined"
var build = "undefined" var commit = "undefined"
var date = "undefined"
const ( const (
cookieSecretMinLen = 32 cookieSecretMinLen = 32
@ -1014,7 +1015,7 @@ func setupTLSConfig() (tlsConfig *tls.Config) {
func main() { func main() {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true}) 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( flag.StringVar(
&configFile, "config", "config.yaml", "Configuration file name") &configFile, "config", "config.yaml", "Configuration file name")