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

Set version and revision at linked time #234

Merged
merged 5 commits into from Aug 26, 2022

Conversation

crazy-max
Copy link
Member

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2022

Codecov Report

Merging #234 (a2d8aac) into master (5124911) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##           master     #234   +/-   ##
=======================================
  Coverage   55.25%   55.25%           
=======================================
  Files           9        9           
  Lines         666      666           
=======================================
  Hits          368      368           
  Misses        255      255           
  Partials       43       43           
Impacted Files Coverage Δ
credentials/credentials.go 52.33% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@thaJeztah
Copy link
Member

oh, sorry; needs a rebase now 😅

Dockerfile Outdated Show resolved Hide resolved
credentials/credentials.go Outdated Show resolved Hide resolved
Comment on lines +4 to +15
// Package is filled at linking time
Package = "github.com/docker/docker-credential-helpers"

// Version holds the complete version number. Filled in at linking time.
Version = "v0.0.0+unknown"

// Revision is filled with the VCS (e.g. git) revision being used to build
// the program at linking time.
Revision = ""
Copy link
Member

Choose a reason for hiding this comment

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

Are we already at a point where we could use Go's built-in features for this?

If so; can they still be overridden?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum good idea we should look at this in a follow-up

Makefile Show resolved Hide resolved
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@thaJeztah
Copy link
Member

Hmm... so for fun, I tried make deb (we need to update that one to something more current, and to not depend on the distro go package); that's something for a follow-up, but I think this part may be related to this PR:

 > [11/11] RUN /build/build-deb v0.6.4-39-geb147ed xenial:
#16 0.312 + set -e
#16 0.312 + version=v0.6.4-39-geb147ed
#16 0.312 + distro=xenial
#16 0.313 ++ awk -F ': ' '$1 == "Maintainer" { print $2; exit }' debian/control
#16 0.315 + maintainer='Docker <support@docker.com>'
#16 0.315 + cat
#16 0.317 ++ date --rfc-2822
#16 0.319 + mkdir -p src/github.com/docker/docker-credential-helpers
#16 0.321 + ln -s /build/credentials /build/src/github.com/docker/docker-credential-helpers/credentials
#16 0.322 + ln -s /build/secretservice /build/src/github.com/docker/docker-credential-helpers/secretservice
#16 0.323 + ln -s /build/pass /build/src/github.com/docker/docker-credential-helpers/pass
#16 0.324 + dpkg-buildpackage -us -uc
#16 0.402 dpkg-buildpackage: warning:     debian/changelog(l1): version 'v0.6.4-39-geb147ed' is invalid: version number does not start with digit
#16 0.402 LINE: docker-credential-helpers (v0.6.4-39-geb147ed) xenial; urgency=low
#16 0.403 dpkg-buildpackage: error: version number does not start with digit
#16 0.404 dpkg-buildpackage: source package docker-credential-helpers
#16 0.404 dpkg-buildpackage: source version v0.6.4-39-geb147ed
------
executor failed running [/bin/sh -c /build/build-deb ${VERSION} ${DISTRO}]: exit code: 255
make: *** [deb] Error 1

@crazy-max
Copy link
Member Author

Hmm... so for fun, I tried make deb (we need to update that one to something more current, and to not depend on the distro go package); that's something for a follow-up, but I think this part may be related to this PR:

Yes I have a branch ready to fix this. Pretty much like #209 but specs not inline.

@thaJeztah
Copy link
Member

I tried changing

to

version=${1##v}

Which fixes the version issue:

#16 0.748 dpkg-source: info: building docker-credential-helpers in docker-credential-helpers_0.6.4-39-geb147ed.m.tar.gz
#16 0.778 dpkg-source: info: building docker-credential-helpers in docker-credential-helpers_0.6.4-39-geb147ed.m.dsc
#16 0.782  debian/rules build
#16 0.785 dh build

But then breaks because we added -trimpath (and the Go version is too old)

#16 0.932 flag provided but not defined: -trimpath

Yeah, looks like that needs more work (was hoping fixing that version would make it "somewhat" work); let's keep that for later

@thaJeztah
Copy link
Member

make pass
./bin/build/docker-credential-pass version
docker-credential-pass (github.com/docker/docker-credential-helpers) v0.6.4-39-geb147ed.m
make VERSION=v1.2.3 pass
./bin/build/docker-credential-pass version
docker-credential-pass (github.com/docker/docker-credential-helpers) v1.2.3

Hm... this one doesn't look right;

make VERSION=v1.2.3 PKG=hello-package  pass
./bin/build/docker-credential-pass version
 (github.com/docker/docker-credential-helpers) v0.0.0+unknown

AH!

make VERSION=v1.2.3 PKG=hello pass
go build -trimpath -ldflags="-s -w -X hello/credentials.Version=v1.2.3 -X hello/credentials.Revision=eb147ed80c90ebba74d2e331daa47528e1578d67.m -X hello/credentials.Package=hello -X hello/credentials.Name=docker-credential-pass" -o ./bin/build/docker-credential-pass ./pass/cmd/

Looks like you're using PKG both for actual package, and for .Package

Makefile Outdated Show resolved Hide resolved
@crazy-max
Copy link
Member Author

But then breaks because we added -trimpath (and the Go version is too old)

#16 0.932 flag provided but not defined: -trimpath

Yeah, looks like that needs more work (was hoping fixing that version would make it "somewhat" work); let's keep that for later

Yeah deb pkg is broken since Go 1.18.5. I made quick changes to fix that but I have another branch to merge that logic in the main Dockerfile.

Also added a simple gha job to check deb package builds correctly: https://github.com/docker/docker-credential-helpers/runs/8045166392?check_suite_focus=true

Makefile Outdated
.PHONY: build-%
build-%: # build, can be one of build-osxkeychain build-pass build-secretservice build-wincred
$(eval BINNAME ?= docker-credential-$*)
go build -trimpath -ldflags="$(GO_LDFLAGS) -X ${PKG}/credentials.Package=${PKG}/$* -X ${PKG}/credentials.Name=docker-credential-$*" -o $(DESTDIR)/$(BINNAME) ./$*/cmd/
Copy link
Member

Choose a reason for hiding this comment

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

Did you update, because this looks to still have PKG used both at the start and as value;

Suggested change
go build -trimpath -ldflags="$(GO_LDFLAGS) -X ${PKG}/credentials.Package=${PKG}/$* -X ${PKG}/credentials.Name=docker-credential-$*" -o $(DESTDIR)/$(BINNAME) ./$*/cmd/
go build -trimpath -ldflags="$(GO_LDFLAGS) -X ${PKG}/credentials.Package=${PACKAGE_NAME}/$* -X ${PKG}/credentials.Name=docker-credential-$*" -o $(DESTDIR)/$(BINNAME) ./$*/cmd/

(mostly thinking that Package here could, e.g., be docker-ce or some other name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I get it now, so for me Package is Go module or base package. Will change that with a new var like you said..

Copy link
Member

Choose a reason for hiding this comment

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

Yes, so wondering if PKG needs to be configurable in this context 🤔 (could just be hard-coded)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes hardcoded is fine, changed to GO_PKG

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah thaJeztah merged commit da1d534 into docker:master Aug 26, 2022
@crazy-max crazy-max deleted the versioning branch August 26, 2022 22:39
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.

None yet

3 participants