When trying to build a prod build of an angular + firebase project, it always times out. I see that it is nearly finished, but the step for building the prod version of the angular application is already taking up > 8 min. When building it locally it takes only 50s.
These are the steps I use in the 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']
The non-production build is working fine and taking up only 4 mins in total (for all steps).
Any ideas why the cloud build of the angular prod build takes so long and how I can reduce it?
After a lot of tries with different solutions I found one that is working: Thanks to Methkal Khalawi's hint regarding "every step copy the assets that produced from the previous step" I modified the build to install all dependencies and then run the build in one step:
Add script in package.json:
"build-from-scratch": "npm install && npm run build"
Then execute this script in the cloudbuild.yaml:
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
args: ['run', 'build-from-scratch', '--', '--prod=$_IS_PRODUCTION']
timeout: 600s
dir: 'hosting'
Since the npm modules do not have to be copied from the install to the build step now, the build just takes ~3min now.