部署到 google App Engine 柔性环境时出现 gcloud 错误

gcloud error when deploying to google app engine flexible environment

最近我需要将网络套接字添加到我目前托管在 Google App Engine (GAE) 标准环境中的后端应用程序中。由于网络套接字是仅在 GAE 的灵活环境中可用的功能,因此我一直在尝试重新部署但收效甚微。

为了更改为灵活的环境,我更新了 app.yaml 文件

runtime: nodejs10
env: standard

runtime: nodejs
env: flex

之前在标准环境中工作,现在使用 env: flex 当我 运行 命令 gcloud app deploy --app-yaml=app-staging.yaml --verbosity=debug 我得到以下堆栈跟踪:

Do you want to continue (Y/n)?  Y

DEBUG: No bucket specified, retrieving default bucket.
DEBUG: Using bucket [gs://staging.finnsalud.appspot.com].
DEBUG: Service [appengineflex.googleapis.com] is already enabled for project [finnsalud]
Beginning deployment of service [finnsalud-staging]...
INFO: Using ignore file at [~/checkouts/twilio/backend/.gcloudignore].
DEBUG: not expecting type '<class 'NoneType'>'
Traceback (most recent call last):
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 982, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 809, in Run
    resources = command_instance.Run(args)
  File "/google-cloud-sdk/lib/surface/app/deploy.py", line 115, in Run
    return deploy_util.RunDeploy(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 669, in RunDeploy
    deployer.Deploy(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 428, in Deploy
    source_files = source_files_util.GetSourceFiles(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/source_files_util.py", line 184, in GetSourceFiles
    return list(it)
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/util/gcloudignore.py", line 233, in GetIncludedFiles
    six.ensure_str(upload_directory), followlinks=True):
  File "//google-cloud-sdk/lib/third_party/six/__init__.py", line 884, in ensure_str
    raise TypeError("not expecting type '%s'" % type(s))
TypeError: not expecting type '<class 'NoneType'>'
ERROR: gcloud crashed (TypeError): not expecting type '<class 'NoneType'>'

在此堆栈跟踪中,它提到了 google-cloud-sdk/lib/googlecloudsdk/command_lib/util/gcloudignore.py 中的一个错误,因此我也检查了我的 .gcloudignore 文件,但找不到任何不合适的地方:

.gcloudignore
.git
.gitignore
node_modules/

为了解决此错误,我尝试删除导致不同错误的 .gcloudignore 文件,但仍然失败:

Do you want to continue (Y/n)?  Y

DEBUG: No bucket specified, retrieving default bucket.
DEBUG: Using bucket [gs://staging.finnsalud.appspot.com].
DEBUG: Service [appengineflex.googleapis.com] is already enabled for project [finnsalud]
Beginning deployment of service [finnsalud-staging]...
DEBUG: expected str, bytes or os.PathLike object, not NoneType
Traceback (most recent call last):
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 982, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 809, in Run
    resources = command_instance.Run(args)
  File "/google-cloud-sdk/lib/surface/app/deploy.py", line 115, in Run
    return deploy_util.RunDeploy(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 669, in RunDeploy
    deployer.Deploy(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 428, in Deploy
    source_files = source_files_util.GetSourceFiles(
  File "/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/source_files_util.py", line 184, in GetSourceFiles
    return list(it)
  File "/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/util.py", line 165, in FileIterator
    entries = set(os.listdir(os.path.join(base, current_dir)))
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
ERROR: gcloud crashed (TypeError): expected str, bytes or os.PathLike object, not NoneType

我想这可能是与我的 CLI 版本有关的错误,我还 运行 尝试更新以下命令:

gcloud app update
gcloud components update

不幸的是,这对输出没有任何影响。

我注意到,当我 运行 此命令将 app.yaml env 值设置为 flexible 时,[=] 上的日志记录部分没有更新63=] 云并且没有更改上传到项目存储桶的文件。对我来说,这表明在与 google 云服务进行任何通信之前,CLI 中发生了崩溃。如果这是正确的,那么错误的原因似乎不太可能与 google 云上的错误配置有关,而必须与我本地计算机上的某些东西(软件或配置)有关。

我也曾尝试在灵活环境“Getting Started”页面上使用 'Hello World' app.yaml 配置来排除我自己的应用程序 app.yaml 的配置错误,但这输出也没有变化。

最后,如果我在任何时候将 env: flex 改回 env: standard,那么问题就会消失。不幸的是,如上所述,这不适用于部署我的网络套接字功能。

这让我想到错误可能是由于 gcloud cli 应用程序的错误造成的。但是,如果是这种情况,我希望看到其他同样使用 GAE 灵活环境的人针对此问题报告更多错误。

无论如何,鉴于此堆栈跟踪指向 gcloud cli 中的代码,我已经使用 google 打开了一个错误票证,可以在此处找到:https://issuetracker.google.com/issues/176839574

我也看到过类似的 SO post,但这不是我遇到的确切错误并且仍未解决:gcloud app deploy fails with flexible environment

如果有人对解决此问题的其他尝试步骤或方法有任何想法,请在此留言 post,我将不胜感激。谢谢!

我使用 Quickstart for Node.js in the standard environment

部署了一个 nodejs 应用程序

然后我将 app.yaml 文件从 :

更改为
runtime: nodejs10

runtime: nodejs
env: flex

一切都按预期进行。

这可能与您的具体用例有关。

令人惊讶的是,这个问题似乎确实与 gcloud cli 中的错误有关。但是,似乎确实有解决方法。

当为 flex 环境的部署指定了 --appyaml 标志时,CLI 会崩溃并显示上述问题中概述的消息。但是,如果您将 .yaml 文件重命名为 app.yaml(默认值)并在部署时删除此 --appyaml 标志,则构建将继续进行而不会出现错误。

如果您也遇到此错误,请关注 google issue,因为我正在与 google 工程师合作,以确保他们重现并最终修复此错误。