building React app very slow on Cloud Build

I have a CD/CI pipeline on Cloud Build for a React app:

 

id: Build docker image
name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/.../...-cloudbuild:$SHORT_SHA', '.' ]

 

This kicks off the Dockerfile of the React app:

 

FROM node:16.19.1 AS ui-build
WORKDIR /usr/src/app
COPY . .
RUN npm install --force
RUN npm run build --verbose

FROM nginx:alpine
COPY --from=ui-build /usr/src/app/build/ /usr/share/nginx/html

ENTRYPOINT ["sh", "-c", "cd /usr/share/nginx/html/ && ./set-env.sh && nginx -g 'daemon off;'"]

 

The npm run build command takes about 25 minutes to complete. The verbose flag didn't give out anything useful. Did anyone experience this? Is it because the build instance that runs this is too basic?

0 1 958
1 REPLY 1

Looking at the Google Cloud Build documentation found here in the page called Increase vCPU for builds ... we see that there are options for specifying the machine type that is used to perform the build.  If the time it is taking for your step to run is too slow, then we are likely going to have to examine the environment and determine what we are blocked on and tune accordingly.  Possibilities include memory, CPU, disk I/O and networking.    I'd be tempted to suggest that choose a low end Compute Engine and run an instance of the Container Optimized OS on it.  From there, we can load your source artifacts and see how long it takes to perform a step on this system.  This will give us a baseline.

Alternatively, simply run your build with a higher end machine and see what effect it has on your duration.