如果 go.mod 在不同的目录中,gcloud app deploy 找不到 app.yaml

gcloud app deploy cannot find app.yaml if go.mod is in a different directory

我已经有一个星期无法将我的 Go 应用程序部署到 Google App Engine Flexible,尽管我不记得更改过任何相关内容。 go.mod 和 go.sum 文件在顶层目录中,而 app.yaml 在 ./cmd/app/.

gcloud app deploy 上的错误消息:

Services to deploy:

descriptor:                  [/Users/me/go/src/github.com/me/project/cmd/app/app.yaml]
source:                      [/Users/me/go/src/github.com/me/project/cmd/app]
target project:              [project-us-central1]
target service:              [default]
target version:              [20220118t234216]
target url:                  [https://project-us-central1.uc.r.appspot.com]
target service account:      [App Engine default service account]


Do you want to continue (Y/n)?  

Beginning deployment of service [default]...

ERROR: (gcloud.app.deploy) Required file is not uploaded: [app.yaml]. 
This file should not be added to an ignore list 
(https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore)

(当然,app.yaml 从未在忽略列表中。)

我尝试了以下方法:

  1. !app.yaml 添加到 .gcloudignore file
  2. 删除.gcloudignore个文件
  3. gcloud config set gcloudignore/enabled false
  4. 等待 gcloud 的新版本发布(Google Cloud SKD 368.0.0)。

请注意,这既发生在我现有的 Go 应用程序上,该应用程序在过去几年中多次成功部署(最后一次是在 2021 年 11 月),也发生在同一目录结构下新创建的简单 Web 服务器应用程序上.但是,如果我创建一个没有 Go 模块的简单应用程序(go.mod、so.sum),gcloud app deploy 会按预期工作。

我刚刚在发布此问题时找到了解决方法。最初,这似乎有效:

gcloud app deploy --appyaml=app.yaml

但是,大约 30 分钟后,部署总是失败并出现以下错误:

Updating service [default] (this may take several minutes)...failed.                                                                                  
ERROR: (gcloud.app.deploy) Error Response: [13] The system encountered a fatal error

部署的版本似乎是 运行,但它对任何请求都是 returns HTTP 404。在控制台中停止并重新启动该版本后,它仍然无法运行:它 returns 主要是 HTTP 502,有时是 HTTP 503 和“服务错误 -27”。我可以在日志中看到 /readiness_check 调用全部失败并返回 503,failReason:"null"

经过一番努力后,问题出在 ./cmd/app/app.yaml 文件与 ./go.mod./go.sum 文件不在同一目录中。

我的解决方法是在调用 gcloud app deploy 之前临时重命名 go.mod,然后在部署完成后将其移回。这样一切又都正常了。