1

我有一个以前构建良好的 Java Spring Boot 应用程序,但我们现在遇到了问题。

我们正在使用 GCP,当我们推送到 GCP 中的某些分支时,云构建功能会自动触发构建。目标是让应用程序自行构建,然后部署到应用程序引擎。在多次试验和错误之前的各种迭代中,我们成功地做到了这一点。

该应用程序已成功构建和部署。这意味着如果我推送代码,它就会构建并工作。但是云构建工具不断报告构建失败。

我们的 cloudbuild.yaml

steps:
- id: 'Stage app using mvn appengine plugin on mvn cloud build image'   
  name: 'gcr.io/cloud-builders/mvn'
  args: ['package', 'appengine:stage', '-Dapp.stage.appEngineDirectory=src/main/appengine/$_GAE_YAML', '-P cloud-gcp']
  timeout: 1600s
- id: "Deploy to app engine using gcloud image"
  name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy', 'target/appengine-staging/app.yaml',
         '-q', '$_GAE_PROMOTE', '-v', '$_GAE_VERSION']
  timeout: 1600s
- id: "Splitting Traffic"
  name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'services', 'set-traffic', '--splits', '$_GAE_TRAFFIC']
timeout: 3200s

这里是一个 app.yaml 供参考

runtime: java
env: flex
runtime_config:
  jdk: openjdk8
env_variables:
  SPRING_PROFILES_ACTIVE: "dev"
handlers:
  - url: /.*
    script: this field is required, but ignored
    secure: always
manual_scaling:
  instances: 1
resources:
  cpu: 2
  memory_gb: 2
  disk_size_gb: 10
  volumes:
    - name: ramdisk1
      volume_type: tmpfs
      size_gb: 0.5

第一步完成得很好,或者看起来是这样。

该应用程序在该特定版本上可用并且运行良好。

这是我们当前面临的“失败”,在第二步失败构建的输出中找到:

--------------------------------------------------------------------------------
Updating service [default] (this may take several minutes)...

ERROR: (gcloud.app.deploy) Error Response: [9] An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2021-11-04T14:55:50.087Z257173.in.0:
There was an error while pulling the application's docker image: the image does
not exist, one of the image layers is missing or the default service account
does not have  permission to pull the image. Please check if the image exists.
Also check if the default service account has the role Storage Object Viewer
(roles/storage.objectViewer) to pull images from Google Container
Registry or Artifact Registry Reader (roles/artifactregistry.reader) to pull
images from Artifact Registry. Refer to https://cloud.google.com/container-registry/docs/access-control
in granting access to pull images from GCR. Refer to https://cloud.google.com/artifact-registry/docs/access-control#roles
in granting access to pull images from Artifact Registry.

我们在构建缓存方面一直存在相当一致的问题,以至于过去我们推送新代码并启动旧版本的代码。我想这可能都是相关的。

我们已尝试清除应用程序特定版本的整个容器注册表缓存,这就是该特定问题开始发生的时间。我有一种感觉,它只是构建和启动应用程序的一个版本,然后返回并尝试在此之上启动应用程序的不同版本。寻找一种至少获得更详细日志记录的方法,但这主要是我卡住的地方。

如何调整“名称:'gcr.io/cloud-builders/gcloud'”步骤以正确指示部署有效?这是正确的方法吗?

4

2 回答 2

0

在这里回答我自己的问题。

事实证明,应用程序正在部署但侦听错误的端口。我们刚刚添加server.port=8080到 application.properties 文件,事情又开始工作了。

我确实相信上面关于我的问题的评论中提到的 Chanseok Oh 也是正确的。尽管更改端口似乎是解决此问题的唯一方法。

GCP 试图进行准备检查,但没有得到任何回报。目前尚不清楚为什么这与工件的缓存有关,如果有的话。

于 2021-11-16T00:10:45.683 回答
0

错误响应代码 9(应用程序启动错误)是一个相当普遍的错误消息,表明部署的程序由于某种原因无法启动,因此没有正常运行(或者 VM 认为如此)。根据您的指示,该应用程序似乎已部署到虚拟机,但由于应用程序无法启动,虚拟机在一段时间后出现故障。

有关崩溃原因的更多信息,请查看Cloud Console中的服务器日志。

使用 gcloud components update 命令更新 gcloud 组件后,尝试部署您的应用程序。

确保 SDK 以管理员身份运行。

如果错误仍然存​​在,请尝试运行命令 gcloud app deploy app.yaml —verbosity=debug 以查看是否可以获得更具体的错误。

现在根据错误消息,docker 镜像似乎存在问题,建议检查该镜像是否存在。根据错误消息,我找到了可以帮助您的Docker文档。在错误之后,它还提到服务帐户没有拉取图像的权限,这里也是如何要求权限的文档。

配置有助于权限和角色的访问控制文档、授予 IAM 权限和配置对图像的公共访问权限。

错误消息末尾推荐的其他Artifact Registry文档是 Google Cloud 推荐的容器映像存储和管理解决方案。

Artifact Registry 通过提供支持容器映像和非容器工件的完全托管服务来扩展 Container Registry 的功能。

于 2021-11-05T21:41:45.367 回答