Skip to content

refactor: use Go 1.18 buildinfo#2541

Merged
sozercan merged 2 commits into
open-policy-agent:masterfrom
sozercan:go118-buildinfo
Jan 28, 2023
Merged

refactor: use Go 1.18 buildinfo#2541
sozercan merged 2 commits into
open-policy-agent:masterfrom
sozercan:go118-buildinfo

Conversation

@sozercan
Copy link
Copy Markdown
Member

Signed-off-by: Sertac Ozercan sozercan@gmail.com

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 <sozercan@gmail.com>
Comment thread Makefile

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
Copy Markdown
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
Comment thread Dockerfile
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ack, makes sense

Comment thread pkg/version/version.go
vcstimestamp := "unknown"
vcsdirty := ""

if info, ok := debug.ReadBuildInfo(); ok {
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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