简体   繁体   中英

How do I deploy a Go application to Heroku with main package in subdirectory?

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?

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

What worked for me is

godep save ./cmd/...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM