1
0
mirror of synced 2025-04-18 12:24:02 +03:00

Change Settings.Software and Settings.Version to build-time constants

Construct default Settings.Version using `git describe` (needs .git tree in builder)

Version number can be overridden on make command line with argument `VERSION=foobar`

Also include Settings.BuiltAt (unused by default but available for e.g. custom settings page)

Use `make build` in Dockerfile instead of go `install`, for consistency

Add **/keydump/, contrib/docker-compose/ and snap/ to .dockerignore for extra safety
This commit is contained in:
Andrew Gallagher 2022-06-24 16:01:00 +01:00
parent 34140ca77d
commit 4bcebe63f5
No known key found for this signature in database
GPG Key ID: 5C1EC404D5906629
4 changed files with 24 additions and 8 deletions

View File

@ -1,7 +1,8 @@
/bin
/pkg
/snap
/contrib/pyinfra
/.git
/contrib/docker-compose
/.gocache
/**/secrets
/keydump
/**/keydump

View File

@ -5,11 +5,12 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get -y install build-essential postgresql-11 postgresql-server-dev-11 --no-install-recommends
COPY --chown=builder:root Makefile /hockeypuck/
COPY --chown=builder:root src /hockeypuck/src
COPY --chown=builder:root .git /hockeypuck/.git
ENV GOPATH=/hockeypuck
USER builder
WORKDIR /hockeypuck
RUN make lint test test-postgresql
RUN cd src/hockeypuck && go install hockeypuck/server/cmd/...
RUN make build
FROM debian:buster-slim

View File

@ -2,6 +2,8 @@ PROJECTPATH = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
export GOPATH := $(PROJECTPATH)
export GOCACHE := $(GOPATH)/.gocache
export SRCDIR := $(PROJECTPATH)src/hockeypuck
VERSION ?= $(shell git describe --tags)
TIMESTAMP = $(shell date -Iseconds)
project = hockeypuck
@ -74,7 +76,11 @@ define make-go-cmd-target
$(eval cmd_target := $(cmd_name))
$(cmd_target):
cd $(SRCDIR) && go install $(cmd_package)
cd $(SRCDIR) && \
go install -ldflags " \
-X hockeypuck/server.Version=$(VERSION) \
-X hockeypuck/server.BuiltAt=$(TIMESTAMP) \
" $(cmd_package)
build: $(cmd_target)

View File

@ -186,8 +186,9 @@ type Settings struct {
Contact string `toml:"contact"`
Hostname string `toml:"hostname"`
Software string `toml:"software"`
Version string `toml:"version"`
Software string
Version string
BuiltAt string
MaxResponseLen int `toml:"maxResponseLen"`
}
@ -197,6 +198,12 @@ const (
DefaultLevelDBPath = "recon.db"
)
var (
Software = "Hockeypuck"
Version = "~unreleased"
BuiltAt string
)
func DefaultSettings() Settings {
metricsSettings := metrics.DefaultSettings()
reconSettings := recon.DefaultSettings()
@ -215,8 +222,9 @@ func DefaultSettings() Settings {
Metrics: metricsSettings,
OpenPGP: DefaultOpenPGP(),
LogLevel: DefaultLogLevel,
Software: "Hockeypuck",
Version: "~unreleased",
Software: Software,
Version: Version,
BuiltAt: BuiltAt,
MaxResponseLen: DefaultMaxResponseLen,
}
}