Reputation: 11
An ASP.NET Core API project with Angular can be built in less than one minute in the local machine, but when I use Build Trigger of Google Cloud Builder to automatize the process it takes forever. I am setting the cloudbuild.yaml as following. The project uses .NET Core 2.2 and Angular. What can I do to make Cloud Build run well again?
I have tried to modify CloudBuild.yaml file, like increasing timeout, that did not help either.
This is the cloudbuild.yaml used to deploy the application to AppEngine Flexible. It first installs the dependencies of Angular, then builds it, publish API and deploy the application.
steps:
# run npm install for Angular
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
dir: 'PPlus.Web/ClientApp'
# build Angular for production
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build','--','--prod']
dir: 'PPlus.Web/ClientApp'
# publish asp.net core solution
- name: microsoft/dotnet:2.2-sdk
args: ['dotnet', 'publish','-c','Release']
# deploy the webapi to the AppEngine
- name: gcr.io/cloud-builders/gcloud
args: ['app', 'deploy',
'./PPlus.Web/bin/Release/netcoreapp2.2/publish/app.yaml','--version','staging']
timeout: 1800s
Since it takes a few seconds to build it in local, it should not take more than a few minutes with Cloud Builder.
The logs of Cloud Build only shows a message indicating Time Out, but the more I increase the timeout limit, the more it takes time without completing.
Upvotes: 1
Views: 961
Reputation: 557
To reduce the time you need to resolve the NPM dependencies, first of all include in your package.json
under dependencies
only the dependencies required for your build and leave the rest under devDependencies
.
Secondly, if the enviroment you deploy the project is the same with your dev enviroment, generate and include in your repo the package-lock.json
.
Now you can run npm ci --only=prod
instead of npm install
.
This will skip calculating and fetching the dependencies and start fetching the ones you need right away.
It reduces the NPM module dependencies resolvement dramatically.
Now about the prod. build issue. Sometimes the Node process doesn't allocate enough resources, the process freezes and it doesn't provide feedback.
Try running this instead of npm run build --prod
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod
Hope it helps!
Upvotes: 0