Over a million developers have joined DZone.

Releasing Cross-platform Go Binaries Using Goxc and BinTray in 5 Minutes

Here’s how to quickly setup your Golang project to build and easily deploy binaries.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

I see many Go projects on GitHub that mention publicly releasing binaries for their projects in the future when time permits.  After releasing Depcon and Docker Volume Netshare I wanted an easy way to release updates so users could quickly grab the latest binary regardless of their platform.

There are many ways to do this and after researching various cross-compilation options and a place to store built binaries I settled on Goxc for compilation and Bintray to store the final binaries and packages.

Here’s how to quickly setup your Golang project to build and easily deploy binaries.

1. Setting up Bintray

Bintray allows developers to store, publish, download, promote, and distribute software with advanced features that fully automate the software distribution process.

  1. If you don’t have an account already you can sign up for free here.
  2. Once you have signed in or created an account you will want to create a generic repository that categories your project. For example if the project it orientated towards Docker you could call your repository “docker”.
  3. Click into your newly created or existing repository and create a new package.  This should ideally be the project name of where you’ll be publishing your binaries too.
  4. Now that you have a repository and package for your project, you’ll want to copy your API Key for the steps below.  This can be done by editing your profile and selecting the vertical tab called “API Key” as shown below.Screen Shot 2015-11-28 at 11.09.41 PM

Exporting the API Key:

The steps below will require the API Key to successfully authenticate with Bintray upon a release of new artifacts.  Copy the API Key from your bintray into your clipboard.

So the the API Key is available in the step below run the following in your current terminal:

  1. Execute: export BINTRAY_APIKEY="MYAPI_KEY" >> ~/.bash_profile
  2. Execute: source ~/.bash_profile

2. Setting up Goxc

Installing Goxc is quite easy.  This guide assumes you already have a Go environment setup.  The following will add the Goxc executable to your $GOPATH.

go get github.com/laher/goxc

Next we want to install the toolchains for all platforms. This adds support to compile against different operating systems with Goxc. This can take a few minutes to complete.

goxc -t

3. Creating the .goxc.json build file

The .goxc.json file sets up metadata for tasks within Goxc. The example below is a simplified artifact that can be tailored to quickly deploy cross platform binaries to bintray. For more advanced examples refer to the .goxc.json file within docker-volume-netshare which also adds sysinit scripts for debian based packages.

 "ArtifactsDest": "build",
 "ConfigVersion": "0.9",
 "PackageVersion": "0.1",
 "TaskSettings": {
  "bintray": {
   "user": "bintray-username",
   "package": "my-project",
   "repository": "my-repo"

Explanation of the example above:

  • PackageVersion: the version of the binary to be released
  • bintray -> user: your bintray username
  • bintray -> package: the bintray package name create above to deploy the artifacts under
  • bintray -> repository: the bintray repository name

4. Creating a Makefile

The Makefile will be used to release your binaries.  I personally add extra targets to automatically build and format the Go source code and an additional call to release the binaries to bintray.

GO_FMT = gofmt -s -w -l .
GO_XC = goxc -os="linux freebsd openbsd netbsd"

GOXC_FILE = .goxc.local.json

all: deps compile

compile: goxc

        $(shell echo '{\n "ConfigVersion": "0.9",' > $(GOXC_FILE))
        $(shell echo ' "TaskSettings": {' >> $(GOXC_FILE))
        $(shell echo '  "bintray": {\n   "apikey": "$(BINTRAY_APIKEY)"' >> $(GOXC_FILE))
        $(shell echo '  }\n } \n}' >> $(GOXC_FILE))

        go get


        $(GO_XC) bintray


5. Putting it all together

Now that you have setup Bintray, Goxc and created a Makefile you can simply run the repeatable steps below to format & compile and release your newest binaries to Bintray.

Formatting and Building: make
Uploading to Bintray: make bintray

Thats it! I hope this guide has helped you quickly evolve your current Golang project into a releasable binary project.  Since the $BINTRAY_APIKEY is a local environment, no confidential information is exposed and all changes can be checked in to your local repo without exposing private information.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

go programming,web dev,bintray,golang

Published at DZone with permission of Jeremy Unruh, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}