Google App Engine: Modify Cloud Run Environment
I'm trying to deploy a Next.js app which uses a custom Node.js server. I want to inject custom build variables into the app: next.config.js const NODE_ENV = process.env.NODE_ENV;
Solution 1:
Don't use NODE_ENV, create your own environment variable and use that:
App.yaml
env_variables:ST_ENV:Production
next.config.js
const environment = process.env.ST_ENV;
const envType = environment === `production` ? `production` : `staging`;
const envPath = `./config/${envType}`;
const { env } = require(envPath);
module.exports = {
env: { ...env },
};
Solution 2:
I had the same issue, at the end I solved setting NODE_ENV=production
in the package.json script, so in your case just use:
{"gcp-build":"NODE_ENV=production yarn build"}
otherwise you can create a Cloud Build configuration file, check the docs, it supports an env
section where you can define environmental variables
Solution 3:
I had the same problem and ended up using an approach similar to Luca's answer, but with a mechanism to substitute the correct variable in package.json
before the deploy (using the microsoft/variable-substitution
GitHub action in my case).
Post a Comment for "Google App Engine: Modify Cloud Run Environment"