Ste*_*eve 5 google-app-engine go google-cloud-platform
我一直在更新我的整个 go gae 标准项目以使用 go 1.11 的模块。
主目录结构
app.yaml
app.go
go.mod
go.sum
Run Code Online (Sandbox Code Playgroud)
应用程序
package main
import "bitbucket.org/myPrivateRepo"
func main() {
myImportantModule.Run()
}
Run Code Online (Sandbox Code Playgroud)
去.mod
module myProject
require bitbucket.org/myPrivateRepo v0.0.1
Run Code Online (Sandbox Code Playgroud)
错误
如果我尝试 gcloud 应用程序部署:
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build <GUI>
status: FAILURE.
Build error details: go: bitbucket.org/myPrivateRepo@v0.0.1:
https://api.bitbucket.org/2.0/repositories/myPrivateRepo?fields=scm:
403 Forbidden
Run Code Online (Sandbox Code Playgroud)
(注意:显然我使用的 repo 有一个真实的名字)。
那么我可以这样做吗?我承认我没有完全理解迁移文档,特别是当它谈到“将文件移动到你的 GOPATH”时。 https://cloud.google.com/appengine/docs/standard/go111/go-differences
我的意思是,我认为新模块系统的好处之一是您不需要 go 路径下的所有内容。例如,当我阅读https://github.com/golang/go/wiki/Modules 时,它很早就说“在 GOPATH 之外创建一个目录:”
所以,要清楚的是,现在我所有的代码都在 go 路径之外,但一切都在本地构建得很好。
我认为这一切都有效,因为当我运行 go mod tidy / go build 等时,go 会自动下载并缓存 go 路径中的内容。
然而,当我尝试 gcloud app deploy 时它失败了。无论如何,谷歌云构建系统如何访问我的私人存储库?我显然错过了一些重要的东西。我还读到你不应该将 vendoring 与新的模块系统结合起来,所以不可能。
如果这行得通,我会很高兴,因为使用 DEP 迫使我非常笨拙地使用 goapp deploy。
谢谢!
更新:Go 1.14 已经发布,Google 有一些更好的文档: https: //cloud.google.com/appengine/docs/standard/go/specifying-dependencies
\n我的解决方案:
\n我没有处理凭据,而是使用 go 的模块替换功能来指示 GAE 使用我的本地代码。这运作良好。
\n目录结构:
\nmyService/\n src/\n service.go // has a run() function to set up routers etc.\n go.mod // depends on my private module in bitbucket and other things\n \xe2\x80\xa6 // other source files\n build/\n gae/\n src/ // simlink to ../../src\n modules/ // git ignored, I clone or copy my modules in build scripts.\n app.go // see below\xe2\x80\xa6\n go.mod // has main() which calls service.run() and appEngine.Main()\n app.yaml\n
Run Code Online (Sandbox Code Playgroud)\n方法
\n我使用 git module replacement 以便 GAE 使用我的本地代码。在构建之前,我解析 myService/src/go.mod 以找到我的私有模块的正确版本,然后将其克隆到模块文件夹中。我还选择复制 wip 模块源代码以在本地进行调试,而无需提交到我的模块存储库。
\ngae 目录中的 go.mod:
\nmodule myServiceGAE\n\nrequire (\n bitbucket.org/me/myService v0.0.0\n google.golang.org/appengine v1.4.0\n)\n\nreplace bitbucket.org/me/myService => ./src\n\nreplace bitbucket.org/me/myModule => ./modules/utils\n
Run Code Online (Sandbox Code Playgroud)\n优点
\nmyService 下的包没有 GAE 的引用或知识,因此我可以轻松地将其构建到 docker 等中。我认为解析服务 go.mod 文件就像创建我自己的依赖项管理器一样,破坏了 go 模块的好处。
\n缺点
\n如果我有一个依赖于另一个私有模块的私有模块,我认为事情会变得太复杂。
\n