Skip to content
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

refactor: use Go 1.18 buildinfo #2541

Merged
merged 2 commits into from
Jan 28, 2023

Conversation

sozercan
Copy link
Member

Signed-off-by: Sertac Ozercan [email protected]

What this PR does / why we need it:
instead of passing in vcs info through LDFLAGS, migrating to use Go 1.18 buildinfo https://tip.golang.org/doc/go1.18#debug/buildinfo

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #

Special notes for your reviewer:

Signed-off-by: Sertac Ozercan <[email protected]>
@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The 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

@sozercan sozercan requested a review from maxsmythe January 26, 2023 17:22
COPY go.mod .

RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest}" -o manager main.go
COPY . .
Copy link
Contributor

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 .output into the system, which may bloat the binary and/or lead to inadvertent disclosures of a publisher's machine.

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, makes sense

vcstimestamp := "unknown"
vcsdirty := ""

if info, ok := debug.ReadBuildInfo(); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this PR!

QQ, what happens when !ok to the version here? even this would even happen at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the code it looks like it defaults to "unknown/unknown"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the build fail instead of returning unknown/unknown?

Copy link
Member Author

@sozercan sozercan Jan 28, 2023

Choose a reason for hiding this comment

The 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"?

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants