mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
runtime: don't override user set commit and timestamp (#7549)
Signed-off-by: sspaink <sspaink@styra.com>
This commit is contained in:
@@ -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
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user