4

I'm wondering if there are any convenient ways to automate deployment of code to a live server in GO, either standard built-in methods, or otherwise.

I want something google app engine like, I just run the command and it uploads to the server and triggers a restart.

(Ultimately I want a git commit to trigger a rebuild and redeploy, but thats for down the track in the future)

2
  • The nice thing about Go is that you don't need to run Git on the receiving end: which makes worrying about versioning, keeping your server in-sync with your dev environment (etc) a non-issue. Set up a post-commit hook on your local git server(s) and/or use a CI system like Travis CI (as per @Fabio Gomes' answer) run your tests, build your app and push the binary only to your server. Stop the existing, start the new one and off you go. No need to install/config a git server or Go on the server! Commented May 24, 2014 at 10:12
  • 1
    @elithrar yes, that's one of the best things about Go. And as you pointed it out, most CI servers like Travis can deploy using FTP for example: docs.travis-ci.com/user/deployment/custom so if you'd like to deploy to a custom server or a vps you just need to use Travis to build and deploy the binary. Commented May 24, 2014 at 12:35

1 Answer 1

5

I recommend Travis CI + Heroku.

You can deploy to heroku directly with just a git push, but I like to use Travis to build and run the tests before that.

There are some guides online but I'll try to go directly to the point:

What you will need?

  • Github account
  • Travis account (linked with github, free if open source)
  • Empty Heroku app (Free dyno works great)

Setup

In your github repo, create the following files:

After that go to your Travis account, add your repository and enabled the build for it.

Here is a sample minimal config file content (based on my app that I deploy to heroku):

.travis.yml

language: go
go:
  - tip
deploy:
  provider: heroku
  buildpack: https://github.com/kr/heroku-buildpack-go.git
  api_key:
    secure: <your heroku api key encripted with travis encrypt>
  on: master 

Procfile

worker: your-app-binary

.go-dir

your-app-binary

Procfile and .go-dir are heroku configs so it can vary if you are deploying a web app, you can read more at the heroku documentation

One important and easily missed point is the build pack, without it the deploy will not work.

Read the Travis docs to see how to encrypt the heroku key

How it works?

Basically, every push to your repository will trigger the Travis CI build, if it passes it will deploy the app to heroku, so you set this up once and build + deploy is just a push away ;)

Also Travis will build and updated the status of all Pull Requests to your repository automagically.

To see my config and build, please take a look at my Travis build and my repository with my working configs

Sign up to request clarification or add additional context in comments.

3 Comments

Very good answer. Some extra tools that may be worth looking into are github.com/etsy/deployinator , github.com/racker/dreadnot .
Heroku does not support GO. Travis CI costs $129US per year for a small organisation/startup.
@Jacob Heroku doesn't support oficially, buit it supports custom build packs and there is a very good one for Go. Also, that's what I recommend based on simplicity of deployment and "hassle free" solution. If you'd like a free solution there's plenty around and as Go compiles to a single binary, you can always write your own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.