9

I'm writing some new web services in Go.

What are some deployment strategies I can use, regardless of the target platform? For example, I'm developing on a Mac, but the staging/production servers will be running Linux.

Are there some existing deployment tools I can use that support Go? If not, what are some things I can do to streamline the process?

I use LiteIDE for development. Is there any way to hook LiteIDE into the deployment process?

Luke
  • 13,678
  • 7
  • 45
  • 79
Daniele B
  • 19,801
  • 29
  • 115
  • 173

4 Answers4

9

Unfortunately since Go is such a young language not much exists yet, or at least they've been hard to find. I would also be interested in the development of such tools for Go.

What I have found is that some people have been doing it themselves, or they've adapted other tools, such as Capistrano, to do it for them.

Most likely it's something you'll have to do yourself. And you don't have to limit yourself to shell scripts - do it in Go! In fact many of the Go tools are written in Go. You should avoid compiling on the target system as it's usually a bad practice to have build tools on your production system. Go makes it really easy to cross compile binaries. For example, this is how you compile for ARM & Linux:

GOARCH=arm GOOS=linux go build myapp

One thing you could do is hop on the #go-nuts freenode IRC channel or join the Go mailing list and ask other Gophers what they're doing.

Luke
  • 13,678
  • 7
  • 45
  • 79
1

Capistrano sounds like a good idea for deployment alone. You can also do cross-compilation as Luke suggested. Both will work just fine.

More generally though... I'm also kind of torn between OS X (development) and Linux (deployment) and in fact I ended just developing in a virtual machine via VirtualBox and Vagrant. I'm using TextMate 2 for text editing but installing many of development tools on a Mac is just a major PITA and I'm just more comfortable with having Debian or the like running somewhere in the background. The bonus is - this virtual environment can mirror deployment environment so I can avoid surprises when I deploy my code, whatever the language.

Marcin Wyszynski
  • 2,188
  • 1
  • 17
  • 16
0

I haven't tried it myself, but it appears you can cross compile golang (either with goxc or Dave Cheney's golang-crosscompile), albeit with some caveats.

But if you need to match the environment with production, which probably you should most of the time, it's safest to go as Marcin suggested.

You can find some prebuilt VirtualBox images on http://virtualboxes.org/images/ although creating one yourself is pretty easy.

widyakumara
  • 1,065
  • 1
  • 9
  • 14
0

what are some things I can do to streamline the process?

The cross-compilation idea should be even more appealing with Go 1.5 (Q3 2015), as Dave Cheney details in "Cross compilation just got a whole lot better in Go 1.5":

Before:

For successful cross compilation you would need

  • compilers for the target platform, if they differed from your host platform, ie you’re on darwin/amd64 (6g) and you want to compile for linux/arm (5g).
  • a standard library for the target platform, which included some files generated at the point your Go distribution was built.

After (Go 1.5+):

With the plan to translate the Go compiler into Go coming to fruition in the 1.5 release the first issue is now resolved.

package main

import "fmt"
import "runtime"

func main() {
        fmt.Printf("Hello %s/%s\n", runtime.GOOS, runtime.GOARCH)
}

build for darwin/386

% env GOOS=darwin GOARCH=386 go build hello.go
# scp to darwin host
$ ./hello
Hello darwin/386

Or build for linux/arm

% env GOOS=linux GOARCH=arm GOARM=7 go build hello.go
# scp to linux host
$ ./hello
Hello linux/arm

I'm developing on a Mac, but the staging/production servers will be running Linux.

Considering the compiler for Go is in Go, the process to produce a Linux executable from your Mac should become straightforward.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250