gomods / athens

A Go module datastore and proxy
https://docs.gomods.io
MIT License
4.38k stars 492 forks source link

Empty build details when using go install #1776

Open pboguslawski opened 2 years ago

pboguslawski commented 2 years ago

Describe the bug When you build athens using go install, no version nor build time is set:

$ GOBIN=/tmp go install github.com/gomods/athens/cmd/proxy@latest
go: downloading github.com/gomods/athens v0.11.0
[...]

$ /tmp/proxy -version
Build Details:
    Version:    
    Date:   

Expected behavior

Version and build date are set automatically based on version selected by go install for installation and current time.

May help: https://www.reddit.com/r/golang/comments/u1a7ah/how_to_embed_version_when_go_installing_since_you/

Environment (please complete the following information):

nrwiersma commented 1 year ago

It turns out with the way the debug build info is set, this is not really possible to do consistently, as the build info can only be read in the main package, and we need the info in main and http handler.

matt0x6F commented 6 months ago

@nrwiersma would it not be possible to derive this information in the main package and pass it to the handler?

I could see changing build.go to a pointer whose value can be set once from main and read by many packages.

matt0x6F commented 3 months ago

I've recently discovered we actually do provide a way to get a versioned Go binary: https://docs.gomods.io/install/build-from-source/

pboguslawski commented 3 months ago

I've recently discovered we actually do provide a way to get a versioned Go binary:

This does not resolve issue which is about installing with go install, without messing with compiler flags.

matt0x6F commented 3 months ago

I think that's fair. I've assigned this to our 1.0.0 milestone because if you can go install you can probably follow the versioned binary instructions. Redoing the build system would be a larger effort. This may fall under having more reproducible builds as well.