登录
首页 >  Golang >  Go问答

在 Google Cloud Build 上部署 Golang AppEngine 会产生无限构建

来源:stackoverflow

时间:2024-04-30 18:12:36 249浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习Golang相关编程知识。下面本篇文章就来带大家聊聊《在 Google Cloud Build 上部署 Golang AppEngine 会产生无限构建》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发!

问题内容

我正在尝试设置 cloud build 管道以将 golang 应用部署到 app engine,但它似乎会生成无限版本的自身,然后超时。

首先,这是我的配置。

steps:
- name: "gcr.io/cloud-builders/go"
  args:
    - get
    - "-u"
    - "-d"
    - "github.com/didip/tollbooth"
    - "github.com/lib/pq"
    - "github.com/stretchr/testify"
    - "github.com/go-redis/redis"
    - "cloud.google.com/go/pubsub"
  dir: "/workspace"
  volumes:
    - name: 'go'
      path: '/gopath'
  env:
    - "gopath=/gopath"
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy", "--stop-previous-version"]
  dir: "/workspace"
  volumes:
    - name: 'go'
      path: '/gopath'
  env:
    - "gopath=/gopath"

这是 app.yaml 的相关部分:

service: "myservice"
runtime: custom
env: flex

当我部署到分支时,我已将其配置为监视,它很好地开始构建,并完成步骤 0。然后它开始步骤 1,即 gcloud 应用程序部署,它似乎递归地生成另一个实例管道(参见下面的日志)。这一直持续到一切超时为止。

这是日志的开头(到最后您会看到它再次在步骤 1 中递归地开始步骤 0)。

starting build "e5ad47ed-5332-4bc7-b4ac-618e243f05a5"

fetchsource
fetching storage object: gs://staging.myproject-event.appspot.com/asia.gcr.io/myproject-event/appengine/myservice.20190130t095428:latest#1548842070817530
copying gs://staging.myproject-event.appspot.com/asia.gcr.io/myproject-event/appengine/myservice.20190130t095428:latest#1548842070817530...
/ [0 files][ 0.0 b/ 10.9 kib] 
-
- [1 files][ 10.9 kib/ 10.9 kib] 
operation completed over 1 objects/10.9 kib. 
build
starting step #0
step #0: already have image (with digest): gcr.io/cloud-builders/go
step #0: documentation at https://github.com/googlecloudplatform/cloud-builders/blob/master/go/readme.md
step #0: running: go get -u -d github.com/didip/tollbooth github.com/lib/pq github.com/stretchr/testify github.com/go-redis/redis cloud.google.com/go/pubsub
finished step #0
starting step #1
step #1: already have image (with digest): gcr.io/cloud-builders/gcloud
step #1: services to deploy:
step #1: 
step #1: descriptor: [/workspace/app.yaml]
step #1: source: [/workspace]
step #1: target project: [myproject-event]
step #1: target service: [myservice]
step #1: target version: [20190130t095546]
step #1: target url: [https://myservice-dot-myproject-event.appspot.com]
step #1: 
step #1: 
step #1: do you want to continue (y/n)? 
step #1: warning: unable to verify that the appengine flexible api is enabled for project [myproject-event]. you may not have permission to list enabled services on this project. if it is not enabled, this may cause problems in running your deployment. please ask the project owner to ensure that the appengine flexible api has been enabled and that this account has permission to list enabled apis.
step #1: beginning deployment of service [myservice]...
step #1: building and pushing image for service [myservice]
step #1: started cloud build [b41069a6-2ef7-4eaf-8b49-de36bc620be2].
step #1: to see logs in the cloud console: https://console.cloud.google.com/gcr/builds/b41069a6-2ef7-4eaf-8b49-de36bc620be2?project=954549095871
step #1: ----------------------------- remote build output ------------------------------
step #1: starting build "b41069a6-2ef7-4eaf-8b49-de36bc620be2"
step #1: 
step #1: fetchsource
step #1: fetching storage object: gs://staging.myproject-event.appspot.com/asia.gcr.io/myproject-event/appengine/myservice.20190130t095546:latest#1548842148386512
step #1: copying gs://staging.myproject-event.appspot.com/asia.gcr.io/myproject-event/appengine/myservice.20190130t095546:latest#1548842148386512...
step #1: / [0 files][ 0.0 b/ 10.9 kib] 
/ [0 files][ 10.9 kib/ 10.9 kib] 
-
- [1 files][ 10.9 kib/ 10.9 kib] 
step #1: operation completed over 1 objects/10.9 kib. 
step #1: build
step #1: starting step #0
step #1: step #0: already have image (with digest): gcr.io/cloud-builders/go
step #1: step #0: documentation at https://github.com/googlecloudplatform/cloud-builders/blob/master/go/readme.md
step #1: step #0: running: go get -u -d github.com/didip/tollbooth github.com/lib/pq github.com/stretchr/testify github.com/go-redis/redis cloud.google.com/go/pubsub
step #1: finished step #0
step #1: starting step #1
step #1: step #1: already have image (with digest): gcr.io/cloud-builders/gcloud
step #1: step #1: services to deploy:

这种情况一直持续到我手动终止最后一个构建:

Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Copying gs://staging.solution360-event.appspot.com/asia.gcr.io/solution360-event/appengine/authproxy.20190130t100329:latest#1548842611410114...
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: / [0 files][ 0.0 B/ 10.9 KiB] 
-
- [1 files][ 10.9 KiB/ 10.9 KiB] 
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Operation completed over 1 objects/10.9 KiB. 
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: BUILD
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Starting Step #0
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Already have image (with digest): gcr.io/cloud-builders/go
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Documentation at https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/go/README.md
Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Running: go get -u -d github.com/didip/tollbooth github.com/lib/pq github.com/stretchr/testify github.com/go-redis/redis cloud.google.com/go/pubsub

我尝试过的:

  • 从命令中删除“--stop-previous-versions”标志。
  • gopath 安装在不同的卷中,以防导致 gcloud 递归下降到其中。
  • 仅运行第 1 步,结果相同。

请参阅随附的实际生成生成的屏幕截图:


解决方案


事实证明,这是 Google Cloud Build 如何处理配置文件 cloudbuild.yaml 的问题。每次看到一个版本时,它都必须生成一个新版本,无论它是否已经被看到。

就我而言,由于项目很小,因此 cloudbuild.yaml 和我的 go 源代码都位于项目的根目录。这导致了以下情况:

  • 初始 git Push 会触发构建,该构建会读取 cloudbuild.yaml
  • 构建发现当前工作目录中有一个 cloudbuild.yaml 并为此生成一个新的构建。

我认为这很有用,因为您可以为项目中的各种事物拥有多个构建配置,这些配置将在遇到时构建。

将 go 源移至 src/(远离 cloudbuild)解决了该问题。

tl;dr 不要将您的 cloudbuild.yaml 放入工作目录中。

我无法重新创建无限构建,但有一些事情

以上就是《在 Google Cloud Build 上部署 Golang AppEngine 会产生无限构建》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>