英文:
How do I deploy a Go application to Heroku with main package in subdirectory?
问题
我目前正在尝试使用wercker将Go应用程序部署到Heroku。Heroku希望main.go位于存储库的根目录,但如果可能的话,我希望我的存储库目录看起来像这样。
project/
cmd/
my-server/
main.go
lib1/
lib2/
Procfile
...
理想情况下,我希望Procfile看起来像这样:
web: my-server -port $PORT
我已经阅读了这篇文章,但由于我正在使用wercker Go box来部署到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?
答案1
得分: 5
你正在使用一个文件结构来组织你的Go项目,这导致你无法在构建过程中使用godep
,从而使构建过程变得更慢。
鉴于此,你需要创建一个.godir
文件,其中指定了你的进程所在的模块名称。
创建一个包含以下内容的.godir
文件:
project/cmd/my-server
并保持你的Procfile不变:
web: my-server -port $PORT
我甚至不需要提醒你需要使用Go自定义构建包:https://github.com/kr/heroku-buildpack-go.git
有了这个.godir
文件,你就可以推送和部署你的应用程序了。
有关使用自定义构建包的godep
的更多信息,请查阅这个指南[1]。
[1] http://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku.html
英文:
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
答案2
得分: 0
对我来说有效的方法是
godep save ./cmd/...
然后将供应商文件夹中的所有内容添加到存储库中。
英文:
What worked for me is
godep save ./cmd/...
Then add all the stuff in the vendor folder into the repo.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论