fix(version): single-source internal/version, fix dockerfile ldflags #27

Merged
steve merged 1 commits from fix-version-ldflags into main 2026-05-09 15:26:51 +01:00
5 changed files with 23 additions and 23 deletions
+4 -2
View File
@@ -8,8 +8,10 @@ VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || ec
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo none) COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION_PKG := gitea.dcglab.co.uk/steve/restic-manager/internal/version VERSION_PKG := gitea.dcglab.co.uk/steve/restic-manager/internal/version
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE) \ LDFLAGS := -s -w \
-X $(VERSION_PKG).Version=$(VERSION) -X $(VERSION_PKG).Commit=$(COMMIT) -X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).Commit=$(COMMIT) \
-X $(VERSION_PKG).Date=$(DATE)
GOFLAGS := -trimpath GOFLAGS := -trimpath
DOCKER_IMAGE ?= gitea.dcglab.co.uk/steve/restic-manager DOCKER_IMAGE ?= gitea.dcglab.co.uk/steve/restic-manager
DOCKER_TAG ?= dev DOCKER_TAG ?= dev
+6 -11
View File
@@ -22,12 +22,7 @@ import (
"gitea.dcglab.co.uk/steve/restic-manager/internal/agent/wsclient" "gitea.dcglab.co.uk/steve/restic-manager/internal/agent/wsclient"
"gitea.dcglab.co.uk/steve/restic-manager/internal/api" "gitea.dcglab.co.uk/steve/restic-manager/internal/api"
"gitea.dcglab.co.uk/steve/restic-manager/internal/restic" "gitea.dcglab.co.uk/steve/restic-manager/internal/restic"
) "gitea.dcglab.co.uk/steve/restic-manager/internal/version"
var (
version = "dev"
commit = "none"
date = "unknown"
) )
func main() { func main() {
@@ -66,7 +61,7 @@ func run() error {
flag.Parse() flag.Parse()
if *showVersion { if *showVersion {
fmt.Printf("restic-manager-agent %s (commit %s, built %s)\n", version, commit, date) fmt.Printf("restic-manager-agent %s (commit %s, built %s)\n", version.Version, version.Commit, version.Date)
return nil return nil
} }
@@ -82,14 +77,14 @@ func run() error {
if *enrollServer == "" { if *enrollServer == "" {
return errors.New("enrollment: -enroll-server is required with -enroll-token") return errors.New("enrollment: -enroll-server is required with -enroll-token")
} }
return doEnroll(*enrollServer, *enrollToken, cfg, version) return doEnroll(*enrollServer, *enrollToken, cfg, version.Version)
} }
// Announce-and-approve: -enroll-server set, no token, agent not // Announce-and-approve: -enroll-server set, no token, agent not
// yet enrolled. Run the announce flow inline; on success the cfg // yet enrolled. Run the announce flow inline; on success the cfg
// has the bearer + host_id and we drop into the normal run loop. // has the bearer + host_id and we drop into the normal run loop.
if !cfg.Enrolled() && *enrollServer != "" { if !cfg.Enrolled() && *enrollServer != "" {
if err := doAnnounce(*enrollServer, cfg, version); err != nil { if err := doAnnounce(*enrollServer, cfg, version.Version); err != nil {
return fmt.Errorf("announce: %w", err) return fmt.Errorf("announce: %w", err)
} }
} }
@@ -106,7 +101,7 @@ func run() error {
return fmt.Errorf("sysinfo: %w", err) return fmt.Errorf("sysinfo: %w", err)
} }
slog.Info("agent starting", slog.Info("agent starting",
"version", version, "version", version.Version,
"host_id", cfg.HostID, "host_id", cfg.HostID,
"server", cfg.ServerURL, "server", cfg.ServerURL,
"restic_version", snap.ResticVersion, "restic_version", snap.ResticVersion,
@@ -136,7 +131,7 @@ func run() error {
CertPinSHA256: cfg.CertPinSHA256, CertPinSHA256: cfg.CertPinSHA256,
HelloPayload: api.HelloPayload{ HelloPayload: api.HelloPayload{
ProtocolVersion: snap.ProtocolVersion, ProtocolVersion: snap.ProtocolVersion,
AgentVersion: version, AgentVersion: version.Version,
ResticVersion: snap.ResticVersion, ResticVersion: snap.ResticVersion,
Hostname: snap.Hostname, Hostname: snap.Hostname,
OS: snap.OS, OS: snap.OS,
+4 -9
View File
@@ -26,12 +26,7 @@ import (
"gitea.dcglab.co.uk/steve/restic-manager/internal/server/ui" "gitea.dcglab.co.uk/steve/restic-manager/internal/server/ui"
"gitea.dcglab.co.uk/steve/restic-manager/internal/server/ws" "gitea.dcglab.co.uk/steve/restic-manager/internal/server/ws"
"gitea.dcglab.co.uk/steve/restic-manager/internal/store" "gitea.dcglab.co.uk/steve/restic-manager/internal/store"
) "gitea.dcglab.co.uk/steve/restic-manager/internal/version"
var (
version = "dev"
commit = "none"
date = "unknown"
) )
func main() { func main() {
@@ -47,7 +42,7 @@ func run() error {
flag.Parse() flag.Parse()
if *showVersion { if *showVersion {
fmt.Printf("restic-manager-server %s (commit %s, built %s)\n", version, commit, date) fmt.Printf("restic-manager-server %s (commit %s, built %s)\n", version.Version, version.Commit, version.Date)
return nil return nil
} }
@@ -123,7 +118,7 @@ func run() error {
NotificationHub: notifHub, NotificationHub: notifHub,
UpdateWatcher: updateWatcher, UpdateWatcher: updateWatcher,
UI: renderer, UI: renderer,
Version: version, Version: version.Version,
OIDC: oidcClient, OIDC: oidcClient,
Metrics: metricsRegistry, Metrics: metricsRegistry,
} }
@@ -177,7 +172,7 @@ func run() error {
errCh := make(chan error, 1) errCh := make(chan error, 1)
go func() { go func() {
slog.Info("server listening", "addr", cfg.Listen, "version", version) slog.Info("server listening", "addr", cfg.Listen, "version", version.Version)
errCh <- srv.Start() errCh <- srv.Start()
}() }()
+5 -1
View File
@@ -26,7 +26,11 @@ ARG DATE=unknown
ARG TARGETOS ARG TARGETOS
ARG TARGETARCH ARG TARGETARCH
ENV LDFLAGS="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" ENV VERSION_PKG="gitea.dcglab.co.uk/steve/restic-manager/internal/version"
ENV LDFLAGS="-s -w \
-X ${VERSION_PKG}.Version=${VERSION} \
-X ${VERSION_PKG}.Commit=${COMMIT} \
-X ${VERSION_PKG}.Date=${DATE}"
# Server: built for the image's runtime arch. # Server: built for the image's runtime arch.
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
+4
View File
@@ -13,4 +13,8 @@ var (
// Commit is the short git SHA. Informational only; surfaced via // Commit is the short git SHA. Informational only; surfaced via
// /api/version but not used for any comparison. // /api/version but not used for any comparison.
Commit = "" Commit = ""
// Date is the RFC3339 build timestamp. Informational only; printed
// by `--version` but not used for any comparison.
Date = "unknown"
) )