Search code examples
google-cloud-platformgoogle-cloud-run

NODE_ENV changed for cloud run services


I had multiple nodejs services deployed on Cloud Run. The value of NODE_ENV was production initially. However, it suddenly changed to development for all the services.

  1. What could be the reason for this?
  2. How can I revert the value back to production?

Attaching the log screenshot from one of the services. enter image description here

Some additional info if it might help :

  1. The services are using Nest.js
  2. I am not setting the NODE_ENV variable during deployment

Solution

  • We had similar issue. I tried to re-deploy cloud functions from our pipeline from the previous week using updated env variables. The deployment was successful on previous week and now it failed. We use latest as the google/cloud-sdk version.

    Found this link and was able to fix the deployment: https://pullanswer.com/questions/dont-set-google_experimental_nodejs_npm_build_enabled-by-default

    Google Cloud Build now sets GOOGLE_EXPERIMENTAL_NODEJS_NPM_BUILD_ENABLED=true as default and that triggers the NPM build automatically. Also NODE_ENV changed from production to development as a side effect. Adding GCP script to package.json didn't help as the deployment was still run as development. Cloud Build installs dev dependencies and then prunes those later. To get similar results as before, we had to set these environment variables to the cloud function deployment:

    GOOGLE_NODE_RUN_SCRIPTS: ''
    NODE_ENV: 'production'