Hi, I’m trying to understand how import from URL worls in moby/moby repository. The source files under moby/moby github repository have import paths like the following:
From what I understand is that whenever we want to import any external package we have to first perform go get <package URL> and then add that URL path under import in the source file. But I’m able to simply clone the moby/moby repo and compile code directly without performing ‘go get…’ prior to it and the compilation just happens fine. I do see a github.com folder in my GOPATH but DO NOT see any child folders like docker/swarmkit/ in it. So, I can’t understand how were the external packages fetched from those URLs? Is it the case that these packages are fetched during the build process and then the local folders are deleted as soon as the build finishes?
The repository uses vendoring, which means that a copy of all the dependencies (or more factually; all the files of the dependencies that are actually used) are included in the repository inside the “vendor” directory; https://github.com/moby/moby/tree/master/vendor
vendoring allows building the project with a guarantee that you’ll always have the exact same version of the dependencies, and also makes sure that we don’t have to rely on the repositories where those dependencies live (they may be unavailable at times, or bad things could happen, such as someone deleting those repositories, or force-pushing changes)
if you want to make changes to those files; it’s best to make a fork of the dependency repository that you want to modify, make the changes there, and specify your fork as source for the dependency; that way you don’t have to change the import paths; you can find an example of a dependency that’s currently using a fork at this line; https://github.com/moby/moby/blob/6f234db9fef23c591d8376f96db062e7107b658f/vendor.conf#L5
@thaJeztah Thanks you for the detailed explanation. Initially I could not get the changes to reflect in the binary just by updating vendor.conf with the URL of the fork. It’s only when I ran vndr from my root repository on the link you shared https://github.com/lk4d4/vndr that I could solve this issue. I assumed that running vndr command was not required initially.