Sergei Basharov Sergei Basharov - 24 days ago 4
Git Question

Repeatable installs of a Go application?

I am from the NodeJS/JavaScript world where I have

and dependencies written down in the
. When I deploy it, I know that I just need to run
npm install
and all the dependencies consumed by the app will be installed.

How is it supposed to be done for a Go project? Suppose I have a source code of the app which I deploy remotely by, say, running
git pull
. Now, how do I make sure the dependencies are present? What I see is I need to install a package manager manually then install dependencies using it?

What's a standard way of deploying a Go app on a server?


First of all, you're indeed thinking like a JS developer. Go is compiled, and thus the proper way to deploy a Go app is not to use the source code at all - you build it on your build server, and deploy a binary. So on the server level you simply don't care anymore, the only place where you need dependencies is the build system.

Now, the standard way to do this in go is to vendor dependencies with your source, that is make sure they are included in the git repo. Another approach is the express them in a manifest file and fetch them with an external tool. These are both more reliable than the naive approach, of simply using go get in build time, fetching the current version of your dependencies (this requires no manifest file).

There are many tools for vendoring management, to name two: Godep and gb