runtime: don't override user set commit and timestamp (#7549)

Signed-off-by: sspaink <sspaink@styra.com>
This commit is contained in:
Sebastian Spaink
2025-05-05 12:03:44 -05:00
committed by GitHub
parent 7dd0dceb6d
commit c99bf28eec
2 changed files with 22 additions and 6 deletions
+7 -1
View File
@@ -382,7 +382,13 @@ set at build-time:
These values can be set on the command-line when building OPA from source:
```
go build -o opa++ -ldflags "-X github.com/open-policy-agent/opa/version.Version=MY_VERSION" main.go
go build \
-ldflags=" \
-X github.com/open-policy-agent/opa/v1/version.Version=MY_VERSION\
-X github.com/open-policy-agent/opa/v1/version.Vcs=MY_COMMIT_HASH \
-X github.com/open-policy-agent/opa/v1/version.Hostname=MY_HOSTNAME \
-X github.com/open-policy-agent/opa/v1/version.Timestamp=MY_TIMESTAMP" \
-o opa++
```
## Appendix
+15 -5
View File
@@ -31,18 +31,28 @@ func init() {
if !ok {
return
}
dirty := false
var dirty bool
var binTimestamp, binVcs string
for _, s := range bi.Settings {
switch s.Key {
case "vcs.time":
Timestamp = s.Value
binTimestamp = s.Value
case "vcs.revision":
Vcs = s.Value
binVcs = s.Value
case "vcs.modified":
dirty = s.Value == "true"
}
}
if dirty {
Vcs += "-dirty"
if Timestamp == "" {
Timestamp = binTimestamp
}
if Vcs == "" {
Vcs = binVcs
if dirty {
Vcs += "-dirty"
}
}
}