Angular universal timeout with cloud build on firebase function

322 Views Asked by At

I have Angular Universal project deployed on firebase and using firebase functions to serve the server-side also using cloud build to trigger the build , the problem it just stuck in server build command for angular universal although sometimes it works just keep retrying , also it does work locally but on cloud sometimes it pass other times not

Cloud build YAML

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t' , 'gcr.io/$PROJECT_ID/firebase' , './dockerfiles/firebase']
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'use', '$_PROJECT_NAME','--token', '${_FIREBASE_TOKEN}']
- name: 'node:12.18.3'
  entrypoint: npm
  args: ['install']
- name: 'node:12.18.3'
  entrypoint: npm
  args: ['install','--prefix','functions']
- name: 'node:12.18.3'
  entrypoint: npm
  args: ['link']
- name: 'node:12.18.3'
  entrypoint: npm
  dir:  'functions'
  args: ['install','-g', 'firebase-tools@latest']
- name: 'node:12.18.3'
  entrypoint: npm
  args: ['run-script','stage-browser']
- name: 'node:12.18.3'
  entrypoint: npm
  args: ['run-script','--debug','stage-server']
- name: 'node:12.18.3'
  entrypoint: npm
  dir:  'functions'
  args: ['run-script','copyAndRename']
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'deploy','--debug', '--token', '${_FIREBASE_TOKEN}']
timeout: 2000s

Firebase docker file

FROM node:carbon

RUN npm install -g firebase-tools@latest

ENTRYPOINT ["/usr/local/bin/firebase"] 

build log it just stuck there forever too long to be added here

https://justpaste.it/30aoi

run-script command

    "stage-browser": "node --max_old_space_size=16384 ./node_modules/@angular/cli/bin/ng build --prod --configuration=stage --aot --vendor-chunk --common-chunk --delete-output-path",
    "stage-server": "node --max_old_space_size=16384 ./node_modules/@angular/cli/bin/ng run sf-mini:server:stage",
    "copyAndRename": "node cp-angular.js",
1

There are 1 best solutions below

3
On

As per the error message this can be due to permissions within the VM created by cloud build to perform the steps.

what you can do to avoid having these permissions issue is to call the commands with sudo

when doing it with sudo it'll be like this:

- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t' , 'gcr.io/$PROJECT_ID/firebase' , './dockerfiles/firebase']
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'use', '$_PROJECT_NAME','--token', '${_FIREBASE_TOKEN}']
- name: 'node:12.18.3'
  entrypoint: bash
  args: ['sudo','npm','install']
- name: 'node:12.18.3'
  entrypoint: bash
  args: ['sudo','npm','install','--prefix','functions']
- name: 'node:12.18.3'
  entrypoint: bash
  args: ['sudo','npm','link']
- name: 'node:12.18.3'
  entrypoint: bash
  dir:  'functions'
  args: ['sudo','npm','install','-g', 'firebase-tools@latest']
- name: 'node:12.18.3'
  entrypoint: bash
  args: ['sudo','npm','run-script','stage-browser']
- name: 'node:12.18.3'
  entrypoint: bash
  args: ['sudo','npm','run-script','--debug','stage-server']
- name: 'node:12.18.3'
  entrypoint: bash
  dir:  'functions'
  args: ['sudo','npm','run-script','copyAndRename']
- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'deploy','--debug', '--token', '${_FIREBASE_TOKEN}']
timeout: 2000s