How to Vendor Golang Dependencies with Docker — No git, GOPATH or godep required
Update: took this a step further and made a Go tool for this.
Now you may be asking yourself “why in the hell would I want to do that?” Let me explain.
While writing the Go example for this post and the readme for this IronWorker, I kept finding myself trying to hack things together to make it easy for other people to just clone the repo and have it work. This is not as easy as it sounds with Go. Other languages are much easier to work with since they don’t force you to have a GOPATH or to have your code structured into particular directories inside that path. And to make matters worse, you have to install another tool like godep to vendor your dependencies and that has it’s own set of issues like forcing you to have your code in git. Anyways, it’s a royal PIA.
Docker to the Rescue
If you have Docker, you can vendor all your dependencies pretty easily. Heck, you don’t even need Go installed to do any of this. Take any Go program with dependencies, in any directory, and use the following commands to vendor, build and run.
If you want to test this on something, here’s simple example you can clone (into any directory) and try it.