GoogleCloudPlatform / cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
https://cloud.run
Apache License 2.0
523 stars 91 forks source link

ENV vars are ignored (sometimes) #241

Open evil-shrike opened 1 year ago

evil-shrike commented 1 year ago

I have a repo with app.json. That app.json contains the "env" section with a variable. After I introduced the variable it worked and it was asked. But during all subsequent runs the variable is ignored (not being asked).

  "env": {
    "USE_GOOGLE_ADS_CONFIG": {
      "description": "Would you like to use a google-ads.yaml (Y) - please upload one, otherewise (N) you'll be asked to enter credentials later",
      "required": true,
      "value": ""
    }
  },

I tried both required true/false, with and without value. If I rename it, it starts working again. But if I rename it back it stops.

All that I'm doing with the var is checking for its value in my prebuild.sh:

if [[ $USE_GOOGLE_ADS_CONFIG = "Y" || $USE_GOOGLE_ADS_CONFIG = "y" ]]; then
...

It's really weir behavior and can't tell exact reproducing steps.

Here's an example of a deployment log (the var is there, see app.json, but it wasn't promted):

Welcome to Cloud Shell! Type "help" to get started. To set your Cloud Platform project in this session use “gcloud config set project [PROJECT_ID]” sergei@cloudshell:~$ cloudshell_open --repo_url "https://github.com/evil-shrike/cloud-run-button-test.git" --page "shell" --force_new_clone [ ✓ ] Cloned git repository https://github.com/evil-shrike/cloud-run-button-test.git. [ ✓ ] Queried list of your projects [ ✓ ] Found 11 projects in your GCP account. [ ? ] Choose a project or press ctrl-c to create a new project: myproject1 [ ✓ ] Enabled Cloud Run API on project myproject1 [ ? ] Choose a region to deploy this application: us-central1 [ ! ] Running command: ./cloud-run-hooks/prebuild.sh

jamesward commented 1 year ago

Cloud Run Button only asks for env vars which are not already set: https://github.com/GoogleCloudPlatform/cloud-run-button/blob/master/cmd/cloudshell_open/main.go#L303-L316

It might be nice to have a param on the env var to control that behavior. I'm not sure if there is a good workaround right now since all the hooks run after the env var handling. So you couldn't delete the hook at the right time. However, I think that hooks support stdin so you could do your own env var handling in a hook script.

evil-shrike commented 1 year ago

I wonder how that variable did manage to be defined if it's in an ephemeral VM and it did work at first. And USE_GOOGLE_ADS_CONFIG obviously isn't a standard envvar.

Handling input in hooks is an option, thanks for the suggestion, but the styling for hook scripts is ugly (no coloring and very dark by default):

image

UPDATE: ah, no, coloring works, just missed -e echo option

jamesward commented 1 year ago

If the service exists then it will find the env var on a second run.

Glad your workaround works. :)

evil-shrike commented 1 year ago

hold on, are these envvars taken from an existing CRun service? :-( ) So, it's not just vars inside a Shell VM?

jamesward commented 1 year ago

Yeah, the env vars in Cloud Run Button are for setting env vars on Cloud Run services.