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

universe: go: add git by default in go.#Image #1971

Merged
merged 1 commit into from Apr 4, 2022

Conversation

vdemeester
Copy link
Contributor

This adds git to the default go.#Image image so that 1.18 "just
works".

Fixes #1965

Signed-off-by: Vincent Demeester vincent@sbr.pm

@helderco
Copy link
Contributor

I'd rather follow up on docker-library/golang#415, and if you really need git, then you can:

img: go.#Image & {
    packages: git: {}
}

TomChv
TomChv previously requested changes Mar 31, 2022
Copy link
Member

@TomChv TomChv left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution, I've suggest a small improvement to avoid code duplication ;)

pkg/universe.dagger.io/go/image.cue Outdated Show resolved Hide resolved
@vdemeester
Copy link
Contributor Author

I'd rather follow up on docker-library/golang#415, and if you really need git, then you can:

img: go.#Image & {
    packages: git: {}
}

So In general, I would say yes. The only "trouble" with that is that go 1.18 assumes git is there by default. See #1965 for the error. Maybe installing git should be done conditionally on 1.18 version only ?

@helderco
Copy link
Contributor

There's other options, like setting buildvcs=false by default.

@helderco
Copy link
Contributor

helderco commented Mar 31, 2022

There's a push in golang/go#51748 to detect this situation and deal accordingly:

Require a VCS tool for -buildvcs=true, and implicitly disable stamping when the tool is missing for -buildvcs=auto

So if this goes through we don't have to change anything.

In the meantime we can add:

flags: "-buildvcs": *false | true

Note that previous docker images (1.17) didn't include the git binary, it's just this new default behavior in go 1.18 about adding vcs info to the build. This is why I think this is the proper fix. And if the default gets fixed upstream, we can then remove this flag.

@helderco
Copy link
Contributor

Also @vdemeester, if you're up for it, add a test which includes a git init'ed source dir to check if the build doesn't fail because of it.

@vdemeester
Copy link
Contributor Author

@helderco I'll do this tomorrow 👼🏼 😉

@aluzzardi
Copy link
Member

👍 on this. I just hit the problem myself, had to do a similar workaround.

Ideally the upstream go image would already include git, but if that doesn't come soon enough, we should go ahead with this

@shykes
Copy link
Contributor

shykes commented Apr 1, 2022

I think we should add the polyfill without waiting for upstream. We can always remove it later if it becomes redundant.

@vdemeester vdemeester changed the title universe.dagger.io/go: add git by default in go.#Image universe: go: add git by default in go.#Image Apr 1, 2022
@@ -17,6 +17,7 @@ dagger.#Plan & {
simple: {
build: go.#Build & {
source: client.filesystem."./data/hello".read.contents
buildvcs: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably should add a 2nd test entry here (one with, one without the flag), right ?

@@ -12,6 +12,8 @@ _#DefaultVersion: "1.18"
version: *_#DefaultVersion | string

packages: [pkgName=string]: version: string | *""
// FIXME Remove once golang image include 1.18 *or* go compiler is smart with -buildvcs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the FIXME 🙃

Copy link
Contributor

@helderco helderco Apr 1, 2022

Choose a reason for hiding this comment

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

Yes, keep this, but it's "...image includes git". Might as well reference the issues: Remove once golang image includes git (docker-library/golang#415) **or** go compiler is smart with -buildvcs (golang/go#51748).

@helderco
Copy link
Contributor

helderco commented Apr 1, 2022

There's two levels to this:

  1. Missing package in 1.18 docker-library/golang#415
    Will the upstream golang docker image include git? Doesn't seem likely, they are waiting on the status of 👇

  2. cmd/go: add (and default to) -buildvcs=auto golang/go#51748
    Will golang itself disable buildvcs by default in case git isn't in $PATH? Very possible 👇

That sounds like a consensus to me.

Option (3) it is! 👍

Originally posted by @bcmills in golang/go#51748 (comment)


So I'm partial to adding a shim (i.e., follow golang's lead), which means: don't add git, and set -buildvcs=false if it's not installed in the image.

  1. If golang ends up defaulting to -buildvcs=auto, then it's easy to remove the shim;
  2. If golang stays the course, then we either keep the convenience or get on board and remove the shim just the same.

@helderco
Copy link
Contributor

helderco commented Apr 1, 2022

There's an argument for making dagger have the convenience of adding git on top of the golang docker image.

Pros:

  • Easiest fix, at least for now;
  • More convinent for the most common use case;

Cons

  • Harder to remove later if users come to depend on it, then we're the ones breaking stuff;
  • You may be using mercurial or something else and we're back to square 1, but then you need to be aware of this change from the go language and either install your tool or add the flag;

@helderco
Copy link
Contributor

helderco commented Apr 1, 2022

Looking at your change I come to realize that our definition needs a better way to set flags. This can come in another PR.

From my previous comment, I say keep it simple for now:

  1. Just add git to the image;
  2. Don't set the flag, we'll allow for better user control soon;

@gerhard

This comment was marked as resolved.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
@vdemeester vdemeester force-pushed the universe-go-fix branch 2 times, most recently from 344fa70 to 2f2a4e0 Compare April 3, 2022 22:56
@helderco helderco requested a review from TomChv April 4, 2022 10:30
@helderco
Copy link
Contributor

helderco commented Apr 4, 2022

Ping @shykes

@vdemeester
Copy link
Contributor Author

cc @aluzzardi

@shykes
Copy link
Contributor

shykes commented Apr 4, 2022

This seems like a useful short-term fix. We will not be able to remove git from the default image in this package, because as @helderco noted, that might break developers that depend on it. But I think it's fine to keep git installed forever. Remember that this is only for the default image. Developers can easily swap in their own image, with or without git.

Copy link
Contributor

@shykes shykes left a comment

Choose a reason for hiding this comment

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

lgtm

@shykes
Copy link
Contributor

shykes commented Apr 4, 2022

We're good to merge @helderco

@helderco
Copy link
Contributor

helderco commented Apr 4, 2022

It's blocked until @TomChv approves his requested changes.

@aluzzardi
Copy link
Member

aluzzardi commented Apr 4, 2022

@TomChv's changes were addressed -- merging

@aluzzardi aluzzardi dismissed TomChv’s stale review April 4, 2022 22:31

Changes addressed

@aluzzardi aluzzardi merged commit d79de11 into dagger:main Apr 4, 2022
@vdemeester vdemeester deleted the universe-go-fix branch April 5, 2022 09:14
@helderco
Copy link
Contributor

https://go-review.googlesource.com/c/go/+/398855/

@vdemeester
Copy link
Contributor Author

@helderco will probably be fixed in 1.18.1 or something I guess ? 🤔

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.

🐞 go.#Build is broken by default with go 1.18
6 participants