英文:
Go App On Heroku With Local Packages
问题
我正在尝试使用Go Buildpack将一个Go应用程序部署到Heroku上,当应用程序很基本时,这是可以的,但是一旦我使用了本地包,它就无法编译。以下是一个示例设置:
结构
+ship
+foo
foo.go
main.go
main.go
package main
import (
"os"
"fmt"
"net/http"
"ship/foo"
)
func main() {
foo.Bar()
port := os.Getenv("PORT")
http.HandleFunc("/", root)
http.ListenAndServe(":" + port, nil)
}
func root(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Aloha, world!")
}
foo.go
package foo
func Bar() {}
推送
git push heroku master
初始化仓库,完成。
计算对象数量:20,完成。
使用最多8个线程进行增量压缩。
压缩对象:100%(13/13),完成。
写入对象:100%(20/20),1.53 MiB | 586.00 KiB/s,完成。
共计20个(增量2个),重用0个(增量0个)
-----> 正在获取自定义git构建包... 完成
-----> 检测到Go应用程序
-----> 安装go1.3.1... 完成
-----> 运行:godep go install -tags heroku ./...
main.go:7:3: 找不到包“ship/foo”的任何内容:
/app/tmp/cache/go1.3.1/go/src/pkg/ship/foo(来自$GOROOT)
/tmp/build_4b92e51c-3959-4ddb-8eff-90d72da70729/.heroku/g/src/_/Users/Daryl/Go/src/ship/Godeps/_workspace/src/ship/foo(来自$GOPATH)
/tmp/build_4b92e51c-3959-4ddb-8eff-90d72da70729/.heroku/g/src/ship/foo
godep: go退出状态1
! 推送被拒绝,无法编译Go应用程序
这里发生了什么问题,该如何解决?
英文:
I'm trying to put a Go app on Heroku using the Go Buildpack, which is fine when it's something basic, but as soon as I do a local package it does not compile. Here's an example setup:
Structure
+ship
+foo
foo.go
main.go
main.go
package main
import (
"os"
"fmt"
"net/http"
"ship/foo"
)
func main() {
foo.Bar()
port := os.Getenv("PORT")
http.HandleFunc("/", root)
http.ListenAndServe(":" + port, nil)
}
func root(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Aloha, world!")
}
foo.go
package foo
func Bar() {}
Push
git push heroku master
Initializing repository, done.
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (20/20), 1.53 MiB | 586.00 KiB/s, done.
Total 20 (delta 2), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Go app detected
-----> Installing go1.3.1... done
-----> Running: godep go install -tags heroku ./...
main.go:7:3: cannot find package "ship/foo" in any of:
/app/tmp/cache/go1.3.1/go/src/pkg/ship/foo (from $GOROOT)
/tmp/build_4b92e51c-3959-4ddb-8eff-90d72da70729/.heroku/g/src/_/Users/Daryl/Go/src/ship/Godeps/_workspace/src/ship/foo (from $GOPATH)
/tmp/build_4b92e51c-3959-4ddb-8eff-90d72da70729/.heroku/g/src/ship/foo
godep: go exit status 1
! Push rejected, failed to compile Go app
Any idea what's going on here and how to go about it?
答案1
得分: 1
只是一个提醒,对于在Go 1.6中遇到此问题的任何人。Godep已经改为在Heroku中使用一个vendor文件夹,所以你需要按照这里的文档重置你的Godeps来使用vendor:
https://github.com/tools/godep#go-15-vendor-experiment
Heroku还在这里提供了升级信息:
英文:
Just a note for anyone coming across this issue in go 1.6. Godep has changed to use a vendor folder with Heroku instead, so you will need to reset your Godeps to use vendor as per the docs here:
https://github.com/tools/godep#go-15-vendor-experiment
Heroku also has upgrade info here:
答案2
得分: 0
我有一个对我有效的解决方案,尽管我不喜欢它,也希望这不是正确的做法!
我正在使用vendor。本地和TravisCI都能够构建我的应用程序,但TravisCI无法将其部署到Heroku,因为Heroku也无法找到本地的包。我最终使用vendor获取本地的包:
govendor fetch +local
一旦我再次提交,TravisCI就会构建并将应用程序部署到Heroku,我的应用程序也能正常工作。
我不喜欢这个解决方案的原因是我现在有了重复的代码!我的本地子包可以在<app_directory>/
英文:
I have a solution that worked for me, though I don't like it, and hope its not the correct way to do it!
I'm using vendor. Both locally and TravisCI were able to build my app, but TravisCI could not deploy it to Heroku, as Heroku was having troubles finding local packages as well. What I ended up doing is fetching local packages with vendor:
govendor fetch +local
Once I committed again, TravisCI built and deployed to Heroku, and my app worked.
The reason I don't like this solution is that I now have duplicate code! My local subpackages can be found in <app_directory>/<subpackage>, as well as in vendor: <app_directory>/vendor/<path_to_subpackage>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论