Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distribute a Go app?

Tags:

go

I've written an application in Go. It has two external dependencies that would need to be met before compiling. In the Go ecosystem, what is the best way to package this app for a simple installation process that includes installing those remote deps? How would a user install my app?

like image 681
Carson Avatar asked Oct 09 '13 23:10

Carson


People also ask

How do I distribute my go app?

If you have assets that you want to provide alongside the application (a config file, for example) then either: a) package the binary with the assets and tar/zip it up; b) base64 encode the assets and compile them into the binary see here for a good example or c) create a build/install script that does this for the ...

Does go run compile?

The go run command combines both the compilation and execution of code. This allows to quickly check the output of updated code. go run will NOT create an executable file in our current folder.


3 Answers

  • If you are expecting a user to compile your application, and that application relies on third party packages or assets, then I'd suggest just cross-compiling for the supported platforms and providing binaries.

  • If you have assets that you want to provide alongside the application (a config file, for example) then either: a) package the binary with the assets and tar/zip it up; b) base64 encode the assets and compile them into the binary see here for a good example or c) create a build/install script that does this for the user.

If you can clarify your exact requirements it'll be easier to answer more directly.

like image 63
elithrar Avatar answered Sep 29 '22 17:09

elithrar


Go binaries do not have runtime dependencies other than any you might impose in your code. (Its runtime libraries are included in the compiled executable.)

So you would distribute your app the way you would any other statically-linked binary compiled from C, C++ or other code.

On Linux you might create an .rpm or .deb file using the appropriate tooling for that. On Windows you could create an installer using a tool like InnoSetup.

like image 40
Brad Peabody Avatar answered Sep 29 '22 17:09

Brad Peabody


Go produces a single binary. If your external dependencies are compile time dependencies, then your users do not need to worry about them - they're already compiled in.

If they're run time dependencies, then it is a matter of distributing an exe and related resources, which any installer can do for you - whether the exe was written in Go or not is irrelevant. EDIT: If it absolutely must be a single binary even with run time dependencies, then you need to convert your run time dependencies to compile time ones. One method is the one elithrar has suggested.

The only thing you need to worry about from Go's point of view is that you have compiled your code for your user's platform.

like image 38
Carl Avatar answered Sep 29 '22 17:09

Carl