在 Google Cloud Build 上部署 Golang AppEngine 产生无限构建
Deploying Golang AppEngine on Google Cloud Build spawns infinite builds
我正在尝试设置 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 app deploy
,似乎递归生成管道的另一个实例(请参阅下面的日志)。这一直持续到一切超时。
这是日志的开头(接近尾声时,您会看到它再次在步骤 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 步,结果相同。
请参阅所附的实际生成生成的屏幕截图:
我无法重新创建无限构建,但有几件事
自定义运行时需要 Dockerfile,您是否在 go 运行时中尝试过 运行 您的服务?
您使用卷而不是仅仅在环境中设置项目根目录是否有特定原因?
您无权部署应用程序和启用 Appenginge Flexible API。
在日志中,有一个警告:
WARNING: Unable to verify that the Appengine Flexible API
is enabled for project [project-name].
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.
简化 AppEngine 灵活应用部署的步骤:
- As a project owner: enable Appengine Flexible API + deploy app for the first time, and:
- Grant permissions to deploy AppEngine app for the user that you are using to perform that tasks.
所以这原来是 Google Cloud Build
如何处理配置文件 cloudbuild.yaml
的问题。它必须在每次看到一个新版本时生成一个新版本,无论它是否已经被看到。
在我的例子中,由于项目很小,cloudbuild.yaml
和我的 go 源代码都在项目的根目录下。这导致了以下情况:
- 初始
git push
触发构建,读取 cloudbuild.yaml
。
- 构建发现当前工作目录中有一个
cloudbuild.yaml
并为此生成一个新构建。
我想这很有用,因为您可以为项目中的各种事物设置多个构建配置,这些配置将在遇到时构建。
将 go 源移动到 src/
(远离 cloudbuild)解决了这个问题。
tl;dr
不要将您的 cloudbuild.yaml
放入工作目录。
我正在尝试设置 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 app deploy
,似乎递归生成管道的另一个实例(请参阅下面的日志)。这一直持续到一切超时。
这是日志的开头(接近尾声时,您会看到它再次在步骤 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 步,结果相同。
请参阅所附的实际生成生成的屏幕截图:
我无法重新创建无限构建,但有几件事
自定义运行时需要 Dockerfile,您是否在 go 运行时中尝试过 运行 您的服务?
您使用卷而不是仅仅在环境中设置项目根目录是否有特定原因?
您无权部署应用程序和启用 Appenginge Flexible API。
在日志中,有一个警告:
WARNING: Unable to verify that the Appengine Flexible API
is enabled for project [project-name].
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.
简化 AppEngine 灵活应用部署的步骤:
- As a project owner: enable Appengine Flexible API + deploy app for the first time, and:
- Grant permissions to deploy AppEngine app for the user that you are using to perform that tasks.
所以这原来是 Google Cloud Build
如何处理配置文件 cloudbuild.yaml
的问题。它必须在每次看到一个新版本时生成一个新版本,无论它是否已经被看到。
在我的例子中,由于项目很小,cloudbuild.yaml
和我的 go 源代码都在项目的根目录下。这导致了以下情况:
- 初始
git push
触发构建,读取cloudbuild.yaml
。 - 构建发现当前工作目录中有一个
cloudbuild.yaml
并为此生成一个新构建。
我想这很有用,因为您可以为项目中的各种事物设置多个构建配置,这些配置将在遇到时构建。
将 go 源移动到 src/
(远离 cloudbuild)解决了这个问题。
tl;dr
不要将您的 cloudbuild.yaml
放入工作目录。