Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV vars are ignored (sometimes) #241

Open
evil-shrike opened this issue Feb 28, 2023 · 5 comments
Open

ENV vars are ignored (sometimes) #241

evil-shrike opened this issue Feb 28, 2023 · 5 comments

Comments

@evil-shrike
Copy link

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

  • ./cloud-run-hooks/prebuild.sh
    ^C
    sergei@cloudshell:~ (myproject1)$ cd cloud-run-button-test/
    sergei@cloudshell:~/cloud-run-button-test (myproject1)$ cat app.json
    {
    "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": ""
    }
    },
    ...
    }
@jamesward
Copy link
Contributor

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
Copy link
Author

evil-shrike commented Feb 28, 2023

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
Copy link
Contributor

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

Glad your workaround works. :)

@evil-shrike
Copy link
Author

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

@jamesward
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants