GCP Cloud 构建忽略超时设置 [英] GCP Cloud build ignores timeout settings
问题描述
我使用 Cloud Build 从存储复制配置文件并将应用部署到 App Engine flex
.问题是每次持续时间超过 10 分钟时,构建都会失败.我在我的 cloudbuild.yaml 中指定了超时,但看起来它被忽略了.另外,我配置了 app/cloud_build_timeout
并将其设置为 1000.有人可以向我解释这里有什么问题吗?
I use Cloud Build for copying the configuration file from storage and deploying the app to App Engine flex
.
The problem is that the build fails every time when it lasts more than 10 minutes. I've specified timeout in my cloudbuild.yaml but it looks like it's ignored. Also, I configured app/cloud_build_timeout
and set it to 1000. Could somebody explain to me what is wrong here?
我的cloudbuild.yaml
是这样的:
steps:
- name: gcr.io/cloud-builders/gsutil
args: ["cp", "gs://myproj-dev-247118.appspot.com/.env.cloud", ".env"]
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: 1000s
timeout: 1600s
我的 app.yaml
使用从 Dockerfile 构建它的自定义环境,如下所示:
My app.yaml
use custom env that build it from Dockerfile and looks like this:
runtime: custom
env: flex
manual_scaling:
instances: 1
env_variables:
NODE_ENV: dev
Dockerfile 也没有什么特别的,只是安装依赖和应用程序构建:
Dockerfile also contains nothing special, just installing dependencies and app building:
FROM node:10 as front-builder
WORKDIR /app
COPY front-end .
RUN npm install
RUN npm run build:web
FROM node:12
WORKDIR /app
COPY api .
RUN npm install
RUN npm run build
COPY .env .env
EXPOSE 8080
COPY --from=front-builder /app/web-build web-build
CMD npm start
推荐答案
当直接为 App Engine Flex 应用运行 gcloud app deploy
时,例如从本地机器,它会在后台生成一个Cloud Build 作业构建映像,然后将其部署到 GAE(您可以在 Cloud Console > Cloud Build 中看到该构建).此版本有 10 分钟的超时时间,可以通过以下方式自定义:
When running gcloud app deploy
directly for an App Engine Flex app, from your local machine for example, under the hood it spawns a Cloud Build job to build the image that is then deployed to GAE (you can see that build in Cloud Console > Cloud Build). This build has a 10min timeout that can be customized via:
gcloud config set app/cloud_build_timeout 1000
现在,这里的问题是您从 Cloud Build 内部发出 gcloud app deploy
命令.由于每个单独的 Cloud Build 步骤都在自己的 Docker 容器中运行,因此您不能只添加上一步来自定义超时,因为下一个步骤将使用默认的 gcloud
设置.
Now, the issue here is that you're issuing the gcloud app deploy
command from within Cloud Build itself. Since each individual Cloud Build step is running in its own Docker container, you can't just add a previous step to customize the timeout since the next one will use the default gcloud
setting.
您有多种选择来解决这个问题:
You've got several options to solve this:
- 添加构建步骤以首先使用
docker build
构建映像,然后将其上传到 Google Cloud Registry.您可以在这些步骤上设置自定义超时以满足您的需要.最后,使用glcoud app deploy --image-url=IMAGE-URL
部署您的应用. - 创建您自己的自定义 gcloud 构建器,其中
app/cloud_build_timeout
设置为您的自定义值.您可以从 default gcloud builder Dockerfile 派生它并添加/builder/google-cloud-sdk/bin/gcloud config set app/cloud_build_timeout 1000
- Add a build step to first build the image with
docker build
, upload it to Google Cloud Registry. You can set a custom timeout on these steps to fit your needs. Finally, deploy your app withglcoud app deploy --image-url=IMAGE-URL
. - Create your own custom gcloud builder where
app/cloud_build_timeout
is set to your custom value. You can derive it from the default gcloud builder Dockerfile and add/builder/google-cloud-sdk/bin/gcloud config set app/cloud_build_timeout 1000
这篇关于GCP Cloud 构建忽略超时设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!