3

I am currently trying to deploy a Go application to Heroku using wercker. Heroku expects the main.go to be at the repository root directory but if possible I would like my repository directory to look something like this.

project/
  cmd/
    my-server/
      main.go
  lib1/
  lib2/
  Procfile
  ...

Ideally, I would like the Procfile look something like this:

web: my-server -port $PORT

I have read this article but since I'm using the wercker Go box to deploy to Heroku, I'm not sure what's the best way to configure this. Anyone that has successfully deployed a application like this?

Marcus
  • 153
  • 2
  • 12

2 Answers2

5

You are using a file structure for your Go project, which disallows you to use godep for the build process, making it much slower.

Given this, what you need is creating a .godir, which specifies the module name where your process lives in.

Create a .godir file with this content:

project/cmd/my-server

And keep your Procfile as it is:

web: my-server -port $PORT

I don't even need to mention that you need to use the Go custom buildpack: https://github.com/kr/heroku-buildpack-go.git

With this .godir file you will be able to push and deploy your application.

Fore more information on godep usage with the custom buildpack, check this guide out [1].

[1] http://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku.html

Fernando Á.
  • 7,295
  • 7
  • 30
  • 32
  • I'm actually using the go-buildpack and Godeps at the moment, having the web.go in the root directory. I'm curious what part of the structure you feel is non-idiomatic. If you're referring to the cmd/my-server, this is the way the standard library is structured. The .godir was new to me though, I will have a look at it! – Marcus Dec 04 '14 at 10:38
  • http://stackoverflow.com/questions/14867452/what-is-a-sensible-way-to-layout-a-go-project – Marcus Dec 04 '14 at 10:48
  • When using Godeps, the buildpack can only execute your root directory as web process in the Procfile. So if you want to execute that server.go file which is inside another directory, you need to use a `.godir` or create a different application where `project/cmd/my-server` is your root directory. – Fernando Á. Dec 04 '14 at 15:24
  • The .godir seems to be what I'm looking for but if I'm to accept your answer, I want to know why you feel that the file structure in the SO post I referred to (the one I'm using) is non-idiomatic. Either that or change your answer to just stating that Heroku simply doesn't support it. Either way, thank you! – Marcus Dec 04 '14 at 20:49
  • It might be my bad, I've never seen this structure before, but I can tell that `camlistore` is a good reference anyway. Normally I use my root package as a command and the inner ones as libraries. And I _never_ use folder names inside my packages like `cmd`, `src` or `lib`. Regarding Heroku and other similar platforms (ftr, I work for cloudControl, an european PaaS), I only have experience executing web processes in the Procfile located in my root domain. `.godir` would work for you. – Fernando Á. Dec 05 '14 at 14:40
  • I edited the answer removing the "unidiomatic" part ;) – Fernando Á. Dec 08 '14 at 12:46
0

What worked for me is

godep save ./cmd/...

Then add all the stuff in the vendor folder into the repo.

nos
  • 19,875
  • 27
  • 98
  • 134