- module path is now gitea.home.hrajfrisbee.cz/kacerr/gatewayapi-certificates-operator - internal/version resolves the commit from ldflags or Go build info; --version prints it and the first log line carries it - --metrics-bind-address is passed to the manager instead of being dropped - Dockerfile takes GIT_COMMIT, honours TARGETARCH, labels the image revision Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Package version reports which commit the binary was built from. Docker
|
|
// builds stamp it via -ldflags (the build context has no .git, so Go's
|
|
// automatic VCS stamp is absent there); host builds fall back to that
|
|
// automatic stamp.
|
|
package version
|
|
|
|
import "runtime/debug"
|
|
|
|
// Commit is set at link time via
|
|
// -ldflags "-X <module>/internal/version.Commit=<hash>".
|
|
var Commit string
|
|
|
|
// Resolve returns the commit the binary was built from, or "unknown" when
|
|
// neither the ldflags stamp nor build info is available (e.g. go test).
|
|
func Resolve() string {
|
|
return resolve(Commit, debug.ReadBuildInfo)
|
|
}
|
|
|
|
func resolve(ldflagsCommit string, readBuildInfo func() (*debug.BuildInfo, bool)) string {
|
|
if ldflagsCommit != "" {
|
|
return ldflagsCommit
|
|
}
|
|
bi, ok := readBuildInfo()
|
|
if !ok {
|
|
return "unknown"
|
|
}
|
|
var revision string
|
|
var modified bool
|
|
for _, s := range bi.Settings {
|
|
switch s.Key {
|
|
case "vcs.revision":
|
|
revision = s.Value
|
|
case "vcs.modified":
|
|
modified = s.Value == "true"
|
|
}
|
|
}
|
|
if revision == "" {
|
|
return "unknown"
|
|
}
|
|
if len(revision) > 12 {
|
|
revision = revision[:12]
|
|
}
|
|
if modified {
|
|
revision += "-dirty"
|
|
}
|
|
return revision
|
|
}
|