-
Notifications
You must be signed in to change notification settings - Fork 862
refactor: use Go 1.18 buildinfo #2541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,14 +40,7 @@ BENCHMARK_FILE_NAME ?= benchmarks.txt | |
| ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
| BIN_DIR := $(abspath $(ROOT_DIR)/bin) | ||
|
|
||
| BUILD_COMMIT := $(shell ./build/get-build-commit.sh) | ||
| BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh) | ||
| BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed hostname, i am not sure if there is value but I can re-add if anyone thinks this is important |
||
|
|
||
| LDFLAGS := "-X github.com/open-policy-agent/gatekeeper/pkg/version.Version=$(VERSION) \ | ||
| -X github.com/open-policy-agent/gatekeeper/pkg/version.Vcs=$(BUILD_COMMIT) \ | ||
| -X github.com/open-policy-agent/gatekeeper/pkg/version.Timestamp=$(BUILD_TIMESTAMP) \ | ||
| -X github.com/open-policy-agent/gatekeeper/pkg/version.Hostname=$(BUILD_HOSTNAME) \ | ||
| -X main.frameworksVersion=$(FRAMEWORKS_VERSION) \ | ||
| -X main.opaVersion=$(OPA_VERSION)" | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,18 +3,32 @@ package version | |
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| "runtime/debug" | ||
| ) | ||
|
|
||
| // Vcs is is the commit hash for the binary build. | ||
| var Vcs string | ||
|
|
||
| // Timestamp is the date for the binary build. | ||
| var Timestamp string | ||
|
|
||
| // Version is the gatekeeper version. | ||
| var Version string | ||
|
|
||
| // GetUserAgent returns a user agent of the format: gatekeeper/<version> (<goos>/<goarch>) <vcs>/<timestamp>. | ||
| // GetUserAgent returns a user agent of the format: gatekeeper/<version> (<goos>/<goarch>) <vcsrevision><-vcsdirty>/<vcstimestamp>. | ||
| func GetUserAgent() string { | ||
| return fmt.Sprintf("gatekeeper/%s (%s/%s) %s/%s", Version, runtime.GOOS, runtime.GOARCH, Vcs, Timestamp) | ||
| vcsrevision := "unknown" | ||
| vcstimestamp := "unknown" | ||
| vcsdirty := "" | ||
|
|
||
| if info, ok := debug.ReadBuildInfo(); ok { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this PR! QQ, what happens when
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it might be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from the code it looks like it defaults to "unknown/unknown"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the build fail instead of returning unknown/unknown?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this wouldn't happen in our CI. If someone is randomly building GK with a super old version of Go, do we support it or care that it says "unknown"?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is mostly for our CI, I'm ok leave it as unknown for now unless someone raises an issue.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO unknown/unknown is fine in order to avoid unnecessary brittleness for people hacking on G8r. If we wanted to ensure our builds aren't affected, we could test that the flag returns an expected result? |
||
| for _, v := range info.Settings { | ||
| switch v.Key { | ||
| case "vcs.revision": | ||
| vcsrevision = v.Value | ||
| case "vcs.modified": | ||
| if v.Value == "true" { | ||
| vcsdirty = "-dirty" | ||
| } | ||
| case "vcs.time": | ||
| vcstimestamp = v.Value | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return fmt.Sprintf("gatekeeper/%s (%s/%s) %s%s/%s", Version, runtime.GOOS, runtime.GOARCH, vcsrevision, vcsdirty, vcstimestamp) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs the risk of copying temp files, such as
.outputinto the system, which may bloat the binary and/or lead to inadvertent disclosures of a publisher's machine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just the builder image, it is not published
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, makes sense