GCP 云构建忽略超时设置

GCP Cloud build ignores timeout settings

我使用 Cloud Build 从存储中复制配置文件并将应用程序部署到 App Engine flex。 问题是每次持续超过 10 分钟时构建都会失败。我在 cloudbuild.yaml 中指定了超时,但它似乎被忽略了。另外,我配置了 app/cloud_build_timeout 并将其设置为 1000。有人可以向我解释这里有什么问题吗?

我的 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 构建它的自定义环境,如下所示:

runtime: custom
env: flex

manual_scaling:
  instances: 1
env_variables:
  NODE_ENV: dev

Dockerfile 也没有什么特别的,只是安装依赖项和应用程序构建:

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

当 运行 gcloud app deploy 直接用于 App Engine Flex 应用程序时,例如从您的本地计算机,它会在后台生成一个 Cloud Build 作业来构建图像,然后将其部署到 GAE (您可以在 Cloud Console > Cloud Build 中看到该构建)。此版本有 10 分钟的超时时间,可以通过以下方式自定义:

gcloud config set app/cloud_build_timeout 1000

现在,这里的问题是您从 Cloud Build 本身发出 gcloud app deploy 命令。由于每个单独的 Cloud Build 步骤 运行 在其自己的 Docker 容器中,您不能只添加前一个步骤来自定义超时,因为下一个步骤将使用默认 gcloud 设置。

您有多种选择来解决这个问题:

  • 添加构建步骤以首先使用 docker build 构建映像,将其上传到 Google Cloud Registry。您可以为这些步骤设置自定义超时以满足您的需要。最后,使用 glcoud app deploy --image-url=IMAGE-URL.
  • 部署您的应用程序
  • 创建您自己的 custom gcloud builder where app/cloud_build_timeout is set to your custom value. You can derive it from the default gcloud builder Dockerfile 并添加 /builder/google-cloud-sdk/bin/gcloud config set app/cloud_build_timeout 1000

以防万一,如果您正在使用 Google Cloud Build with Skaffold,请记住检查 skaffold.yaml 如果您在 googleCloudBuild 部分中设置了 timeout 选项 build。例如:

build: 
  googleCloudBuild: 
    timeout: 3600s

Skaffold 将忽略您所在机器的 gcloud 配置 运行 部署。例如,它将忽略此 CLI 命令:gcloud config set app/cloud_build_timeout 3600