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條經驗 獲得超8個贊
另一種選擇是也使用 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 關注
- 145 瀏覽
添加回答
舉報