Skip to content

vendor: use go mod#43075

Closed
errordeveloper wants to merge 2 commits intomoby:masterfrom
errordeveloper:go-mod
Closed

vendor: use go mod#43075
errordeveloper wants to merge 2 commits intomoby:masterfrom
errordeveloper:go-mod

Conversation

@errordeveloper
Copy link
Contributor

No description provided.

vendor.mod Outdated
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200227132054-3f1135a288c9
google.golang.org/grpc => google.golang.org/grpc v1.27.1
gopkg.in/fsnotify.v1 => gopkg.in/fsnotify.v1 v1.4.7
archive/tar => ./internal/archive/tar
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this actually isn't supported (see golang/go#35283). We need to find a better way to do this, perhaps for now there could be cp -a internal/archive/tar inside of go mod vendor wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

If we keep the files inside vendor/, does go mod vendor delete them, or does it leave them alone?

also wondering if a symlink would work (although Windows may not be happy with that, I recall there were some issues with Windows and symlinks, but don't recall the details)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we keep the files inside vendor/, does go mod vendor delete them, or does it leave them alone?

It deletes them.

also wondering if a symlink would work (although Windows may not be happy with that, I recall there were some issues with Windows and symlinks, but don't recall the details)

The issue with symlinks on Windows is pretty major IMO, a Windows user basically cannot clone a repo with symlinks.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I asked before, but why can't we move vendor/archive/tar to an external module such as github.com/moby/sys/archive/tar and just apply s|archive/tar|github.com/moby/sys/archive/tar|g to the moby/moby source?

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 think it might be worse trying as a follow-up, but here the goal is to make the least number of changes.

Copy link
Member

Choose a reason for hiding this comment

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

@AkihiroSuda In that case, we could as well put it in internal/ in this repository. But I think the reason we didn't "fork" it (but override) is that it may be used indirectly(?). Are we sure that the archive/tar code is never called indirectly (and we would reintroduce the vulnerability?)

@thaJeztah
Copy link
Member

Also opened docker/docker-ce-packaging#611 to do a quick check if the packaging scripts don't blow up 👍

hack/vendor.sh Outdated
Comment on lines 15 to 17
cat > hack/make/.resources-windows/go.mod << EOF
module github.com/docker/docker/autogen/winresources/dockerd
Copy link
Member

@crazy-max crazy-max Dec 13, 2021

Choose a reason for hiding this comment

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

For this I can open a PR to implement goversioninfo like it has been done in docker/cli#3310 so you would not need to add this hack. WDYT @thaJeztah?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, would be great if we could used the same tool.

I'm ok with a temporary hack like this (if it works in the meantime)

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 think it'd be good as a follow-up, but doesn't seem like a blocker...

@errordeveloper errordeveloper force-pushed the go-mod branch 2 times, most recently from 454c66a to 9e83d6c Compare December 13, 2021 19:39
@errordeveloper errordeveloper marked this pull request as ready for review December 13, 2021 19:55
@errordeveloper
Copy link
Contributor Author

This should be good as far as I'm concerned, but let's see what CI might bring...

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.

Thanks! Did some quick testing, and looks like there may be some issues (see comments)

@errordeveloper

This comment has been minimized.

@thaJeztah
Copy link
Member

I noticed that the temporary go.mod files that we generate are not cleaned up after vendor.sh completes. They are added to .gitignore, so not "critical", but perhaps (as a follow up?) we should clean those up, so that running vendor.sh leaves a clean state afterwards.

@errordeveloper
Copy link
Contributor Author

I noticed that the temporary go.mod files that we generate are not cleaned up after vendor.sh completes. They are added to .gitignore, so not "critical", but perhaps (as a follow up?) we should clean those up, so that running vendor.sh leaves a clean state afterwards.

Maybe, but I am not quite sure why this matters. With these files written one can actually use go mod commands directly, without having to always use vendor.sh, which I find quite convenient.

@thaJeztah
Copy link
Member

With these files written one can actually use go mod commands directly, without having to always use vendor.sh, which I find quite convenient.

Ah, good point as well, didn't think of that

@thaJeztah
Copy link
Member

One caveat with that is that it still requires the -modfile flag;

go mod graph | grep ' github.com/BurntSushi/toml'
# nothing

go mod graph -modfile=vendor.mod | grep ' github.com/BurntSushi/toml'
github.com/docker/docker github.com/BurntSushi/toml@v0.3.1
github.com/moby/buildkit@v0.8.2-0.20210615162540-9f254e18360a github.com/BurntSushi/toml@v0.3.1
github.com/urfave/cli@v1.22.2 github.com/BurntSushi/toml@v0.3.1
github.com/urfave/cli@v1.22.1 github.com/BurntSushi/toml@v0.3.1
github.com/urfave/cli@v1.22.4 github.com/BurntSushi/toml@v0.3.1

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

@errordeveloper
Copy link
Contributor Author

There's also some dependencies that we previously were able to avoid (by only consuming certain packages), but are now pulled in because go.mod mentions them and/or because some repositories are using a tools.go (or equivalent) to have an easy way to download test dependencies.

I guess the way I think about this is that new sub-decencies are not a major concern, as long as these aren't actually imported, which I checked for this PR.

@errordeveloper
Copy link
Contributor Author

errordeveloper commented Dec 20, 2021

@thaJeztah thanks for sharing go mod graph results for new deps, I think you need to tweak formatting a little to work with <details/>.

@thaJeztah
Copy link
Member

I think you need to tweak formatting a little to work with <details/>.

🤦 I always forget the empty line; should be fixed now

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

When I run hack/validate/vendor inside the container the vendor.sum file changes significantly. But the validation script itself returns with 0 exit code.

golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.46.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
Copy link
Member

Choose a reason for hiding this comment

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

I see we are now vendoring some new packages that actually never get called. Nothing we can do about it?

Copy link
Member

Choose a reason for hiding this comment

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

No, don't think so unfortunately. Some of these may be test dependencies or a dependency using a "tools.go" file to force it being included. (also see my comment above)

IFS=$'\n'
# shellcheck disable=SC2207
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.sum' 'vendor.mod' 'vendor/' || true) )
Copy link
Contributor Author

@errordeveloper errordeveloper Dec 21, 2021

Choose a reason for hiding this comment

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

@tonistiigi thanks for checking this, well spotted! I have looked into this and it doesn't seem to detect uncommitted changes to any of these files, it seems to be just getting a list of files that changed between origin/HEAD and HEAD.

When I ran bash -x hack/validate/vendor, the command it called was this:

+ git diff 088afc99e4bf8adb78e29733396182417d67ada2...0089b1ffb718e9c413a0687dd714dfc5c0829cb4 --diff-filter=ACMR --name-only -- vendor.sum vendor.mod vendor/

Where 088afc9 is what's in master right now, and 0089b1f is the head of my branch.

I think that changing the way this script functions would be out of scope for this PR, so I'd rather leave it as is. I know that overall diff in this script is quite big already, but I was aiming to avoid changing the logic of the checks.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't at least line 21 need vendor.mod and vendor.sum as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't at least line 21 need vendor.mod and vendor.sum as well?

You are right, that looks like where detection of uncommitted changes happens.

I can also see what validate_diff is all about, it checks what files changed in HEAD vs origin/HEAD.
I just tend to use git diff to check for uncommitted changes, so I too quickly assumed that's what validate_diff might be for, the function name isn't very specific...

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've updated this script just now.

@errordeveloper
Copy link
Contributor Author

When I run hack/validate/vendor inside the container the vendor.sum file changes significantly. But the validation script itself returns with 0 exit code.

I've committed an update to vendor.sum just now, see #43075 (comment) regarding the behaviour of the validation script...

- use `vendor.mod` instead of `go.mod` to avoid issues to do with
  use of CalVer, not SemVer
- ensure most of the dependency versions do not change
  - only zookeeper client has to change (via docker/libkv#218) as
    previously used version is no longer maintained and has missing
    dependencies

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
@errordeveloper errordeveloper force-pushed the go-mod branch 2 times, most recently from ba0a704 to 38fe32e Compare December 22, 2021 12:17
- all changes here are attributed to difference in behaviour between,
  namely:
  - resolution of secondary test dependencies
  - prunning of non-Go files

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
@thaJeztah
Copy link
Member

@errordeveloper I was a bit in doubt in which order we should merge the PR's;

#42247 was green now (with the test-fixes merged), and has some commits that remove a couple of dependencies. I gave it a quick try to rebase this (your) PR on top of that one, to see how easy we can do a rebase (and update the vendor.mod etc accordingly; #43101

I can also do a try to see what the "reverse" will look like (have not tried yet)

@errordeveloper
Copy link
Contributor Author

@thaJeztah ok, do give it a go! I can pick this back up on Friday, if needed.

@errordeveloper
Copy link
Contributor Author

closing in favour of #43101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/project kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants