Skip to content

Commit

Permalink
Set transport.Version via ldflags for release (#856)
Browse files Browse the repository at this point in the history
For most things consuming this package, they will depend on an actual
released version of go-containerregistry. When we release
go-containerregistry itself, the binaries are built at the same version
as the library, which means that they don't depend on an actual released
version of go-containerregistry, so the version in debug info is just
"(devel)". For our own release, we will just set it to the tag.
  • Loading branch information
jonjohnsonjr committed Dec 3, 2020
1 parent 3158c98 commit f39a196
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ builds:
- -trimpath
ldflags:
- "-s -w -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Version}}"
- "-s -w -X github.com/google/go-containerregistry/pkg/v1/remote/transport.Version={{.Version}}"
goarch:
- amd64
- arm
Expand All @@ -38,6 +39,7 @@ builds:
- -trimpath
ldflags:
- "-s -w -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Version}}"
- "-s -w -X github.com/google/go-containerregistry/pkg/v1/remote/transport.Version={{.Version}}"
goarch:
- amd64
- arm
Expand Down
15 changes: 13 additions & 2 deletions pkg/v1/remote/transport/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ import (
"runtime/debug"
)

var (
// Version can be set via:
// -ldflags="-X 'github.com/google/go-containerregistry/pkg/v1/remote/transport.Version=$TAG'"
Version string

ggcrVersion = defaultUserAgent
)

const (
defaultUserAgent = "go-containerregistry"
moduleName = "github.com/google/go-containerregistry"
)

var ggcrVersion = defaultUserAgent

type userAgentTransport struct {
inner http.RoundTripper
ua string
Expand All @@ -39,6 +45,11 @@ func init() {
}

func version() string {
if Version != "" {
// Version was set via ldflags, just return it.
return Version
}

info, ok := debug.ReadBuildInfo()
if !ok {
return ""
Expand Down

0 comments on commit f39a196

Please sign in to comment.