Angularfire项目的Google Cloud Build超时

问题描述 投票:0回答:1

[尝试构建有角度+ firebase项目的产品时,它总是超时。我看到它快要完成了,但是构建angular应用产品版本的步骤已经占用了8分钟以上的时间。在本地构建时,只需50秒钟。

cloud build steps image

这些是我在cloudbuild.yaml中使用的步骤:

steps:
##########
# FUNCTIONS
##########
# Install
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: ['install']
  dir: 'functions'

##########
# HOSTING
##########
# Install
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: ['install']
  dir: 'hosting'
# Build
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: ['run', 'build', '--', '--prod=$_IS_PRODUCTION']
  dir: 'hosting'
  env:
    - some environment variables here containing api keys etc...

##########
# DEPLOY
##########
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: ['deploy', '-P', '$_BUILD_LINE']

非生产版本运行正常,总共仅花费4分钟(所有步骤)。

关于为什么角度产品生成的云构建需要这么长时间以及如何减少它的任何想法?

angular angularfire google-cloud-build
1个回答
0
投票

我对此进行了调查,并在这里复制了您的问题,这是我的分析:

  • 步骤的默认超时为10分钟
  • 由于构建过程分为多个步骤,所以每个步骤都会复制上一步产生的资产。
  • 我怀疑步骤2超时,因为它正在复制很多文件,而且我猜它们的大小很大。

我建议以这种方式将“timeout” option添加到构建步骤:

# Build
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: ['run', 'build', '--', '--prod=$_IS_PRODUCTION']
  timeout: 900s
  dir: 'hosting'
  env:
    - some environment variables here containing api keys etc…

我把它放在这里900秒,这是15分钟,您可以更改它以满足您的需求。

无论如何,都需要考虑一些best practices:构建是否花费了很多时间:

  • 构建更精简的容器
  • 使用Kaniko缓存
  • 使用缓存的Docker映像
  • 使用Google Cloud Storage缓存目录
  • 使用自定义虚拟机大小
  • 避免上载不必要的文件
© www.soinside.com 2019 - 2024. All rights reserved.