首页 > 解决方案 > Google Cloud Build 中的 Spring Boot 应用程序出错 - 创建工作版本但报告构建失败

问题描述

我有一个以前构建良好的 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'”步骤以正确指示部署有效?这是正确的方法吗?

标签: spring-bootgoogle-cloud-platformgoogle-cloud-buildspring-cloud-gcpcloudbuild.yaml

解决方案


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

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

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

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


推荐阅读