Home > Blockchain >  Deploy an ReactJS app to Google Cloud Run with enviroment variables using "--set-env-vars"
Deploy an ReactJS app to Google Cloud Run with enviroment variables using "--set-env-vars"

Time:11-28

I am trying to deploy a image that I have stored on Google at eu.gcr.io. I want to set the enviroment variable NODE_ENV to production.

My command:

gcloud beta run deploy my-app-frontend --image=eu.gcr.io/my-project/my-app-frontend/my-app-frontend:abcdefghijklmnopqrstuvwxyz123 --execution-environment=gen2 --region=europe-north1 --project=my-project && gcloud run services update-traffic my-app-frontend --to-latest --set-env-vars=[NODE_ENV=production]

Error:

OK Deploying... Done.                                                             
  OK Creating Revision...                                                         
  OK Routing traffic...
Done.
Service [my-app-frontend] revision [my-app-frontend-00024-nub] has been deployed and is serving 100 percent of traffic.
Service URL: https://my-app-frontend-abcdefghij-ab.a.run.app
ERROR: (gcloud.run.services.update-traffic) unrecognized arguments:
  --set-env-vars (did you mean '--set-tags'?)
  NODE_ENV=production
  To search the help text of gcloud commands, run:
  gcloud help -- SEARCH_TERMS

I have read the manual and set-env-vars is a part of it: https://cloud.google.com/sdk/gcloud/reference/run/deploy#--set-env-vars

What am I missing?

CodePudding user response:

You've combined 2 commands - gcloud beta run deploy, gcloud run services update-traffic

--set-env-var is only applicable to the first command.

You can try this (I moved the flag to be part of the first command)

gcloud beta run deploy my-app-frontend --image=eu.gcr.io/my-project/my-app-frontend/my-app-frontend:abcdefghijklmnopqrstuvwxyz123 --execution-environment=gen2 --region=europe-north1 --set-env-vars=[NODE_ENV=production] --project=my-project && gcloud run services update-traffic my-app-frontend --to-latest

or you can run the 2 commands one after the other (I prefer to always include the -project flag when running commands to ensure I run it against my intended target)

a. First Command

gcloud beta run deploy my-app-frontend --image=eu.gcr.io/my-project/my-app-frontend/my-app-frontend:abcdefghijklmnopqrstuvwxyz123 --execution-environment=gen2 --region=europe-north1 --set-env-vars=[NODE_ENV=production] --project=my-project

b. Second command

gcloud run services update-traffic my-app-frontend --to-latest --project=my-project

  • Related