cloud-run-button
cloud-run-button copied to clipboard
ENV vars are ignored (sometimes)
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": "" } }, ... }
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.
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):

UPDATE:
ah, no, coloring works, just missed -e echo option
If the service exists then it will find the env var on a second run.
Glad your workaround works. :)
hold on, are these envvars taken from an existing CRun service? :-( ) So, it's not just vars inside a Shell VM?
Yeah, the env vars in Cloud Run Button are for setting env vars on Cloud Run services.