3 回答

TA贡献1811条经验 获得超4个赞
更新:现在 go 1.14 已经发布,Google 有一些更好的文档: https: //cloud.google.com/appengine/docs/standard/go/specifying-dependencies
我的解决方案:
我没有处理凭据,而是使用 go 的模块替换功能来指示 GAE 使用我的本地代码。这运作良好。
目录结构:
myService/
src/
service.go // has a run() function to set up routers etc.
go.mod // depends on my private module in bitbucket and other things
… // other source files
build/
gae/
src/ // simlink to ../../src
modules/ // git ignored, I clone or copy my modules in build scripts.
app.go // see below…
go.mod // has main() which calls service.run() and appEngine.Main()
app.yaml
方法
我使用 git module replace 以便 GAE 使用我的本地代码。在构建之前,我解析 myService/src/go.mod 以找到我的私有模块的正确版本,然后将其克隆到模块文件夹中。我还选择了复制 wip 模块源代码以在本地进行调试,而无需提交到我的模块存储库。
gae 目录中的 go.mod:
module myServiceGAE
require (
bitbucket.org/me/myService v0.0.0
google.golang.org/appengine v1.4.0
)
replace bitbucket.org/me/myService => ./src
replace bitbucket.org/me/myModule => ./modules/utils
优点
myService 下的包没有 GAE 的引用或知识,所以我可以轻松地将它构建到 docker 等中。我认为解析服务 go.mod 文件就像创建我自己的依赖管理器一样,破坏了 go 模块的好处。
缺点
如果我有一个依赖于另一个私有模块的私有模块,我认为事情会变得太复杂。

TA贡献1725条经验 获得超7个赞
另一种选择是也使用 Google Cloud Secret Manager
Google Cloud 将有一个 SSH 密钥来访问和拉取您的私有存储库。

TA贡献1828条经验 获得超6个赞
在部署之前设置 git 凭据:
git config credential.helper '!f() { sleep 1; echo "username=${GIT_USER}\npassword=${GIT_PASSWORD}"; }; f'
export GIT_USER=put_git_user_here
export GIT_PASSWORD=put_git_password_here
gcloud app deploy
- 3 回答
- 0 关注
- 114 浏览
添加回答
举报