Skip to content

Conversation

@jedevc
Copy link
Collaborator

@jedevc jedevc commented Feb 16, 2023

🛠️ As mentioned in #1620 (comment).

If Revision is not set by the linker, fallback to load the revision in the same format as generated by ./hack/git-meta.

Unfortunately, we have no access to the tags, so we can't have a fallback for the Version field.

)

func init() {
if info, ok := debug.ReadBuildInfo(); ok {
Copy link
Member

Choose a reason for hiding this comment

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

Could we check first Revision is empty to avoid extra call to build info?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 🎉

Copy link
Member

Choose a reason for hiding this comment

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

Does this information gets used when buildx is used as a module? Because in that case it would be showing version from "whatever project used it as a module"

Copy link
Collaborator Author

@jedevc jedevc Mar 13, 2023

Choose a reason for hiding this comment

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

😱 ah! I think you're right, ugh.

We could try and read through the modules first, and look for buildx in there, so we don't hit that? Frustratingly, BuildInfo.Main.Version doesn't get populated, so we can't pull from there.

Maybe we should drop this PR, and avoid clever guessing, since using buildx as a module is definitely a valid use case (e.g. in compose, in docker desktop, etc). This PR is mostly just to provide a fallback for #1620 anyways - we should push the reading of buildinfo down into the logic there, instead of trying to make it generic here.

Copy link
Member

Choose a reason for hiding this comment

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

I think vcs.* is only populated at build time

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah - but I think it's populated by whatever vcs information is in the build.

So, if compose uses buildx as a module, then with this patch, we'd populate Revision with compose's revision.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right yeah

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Going to close this PR, don't think it's worth adding all this extra complex logic just to find a revision.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

LGTM, PTAL @thaJeztah

If Revision is not set by the linker, fallback to load the revision in
the same format as generated by ./hack/git-meta.

Unfortunately, we have no access to the tags, so we can't have a
fallback for the Version field.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc force-pushed the version-fallback branch from 6c6e5a9 to 0d2a90e Compare March 13, 2023 10:45
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.

3 participants