douweida2669
2014-11-10 10:12
浏览 45
已采纳

如何使用子目录中的主包将Go应用程序部署到Heroku?

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?

图片转代码服务由CSDN问答提供 功能建议

我目前正在尝试使用Wercker将Go应用程序部署到Heroku。 Heroku希望main.go位于存储库根目录中,但如果可能,我希望存储库目录看起来像这样。

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

理想情况下,我希望Procfile看起来 像这样的东西:

  web:我的服务器-端口$ PORT 
   
 
 

我已阅读这篇文章,但由于我使用的是Wercker Go盒,因此无法部署到Heroku,所以我不确定什么是最好的方法 配置它。 是否已经成功部署了这样的应用程序?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • douqi0090 2014-11-28 15:50
    最佳回答

    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

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题