-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Weird interpolation with environment: script not working #120
Comments
Hi @pmiddend This is the expected behavior. What happens:
To achieve the functionality that you are after I would recommend using either Using
|
What a thorough explanation, thank you very much! |
I dont get it, what does global environment do then ?
why does it do that instead of just running the command with environment variables injected in the process ? Referring to your example in 2) why doesn't process-compose find the |
Thanks for the tool, I find it really useful! However it is not clear from the explanation (from @F1bonacc1 ) above what is the purpose of Thanks, Roman |
Stuff you set in environment is present in env during runtime. You can test it by calling env in you script, or by putting your script into an executable file instead of inlining it. The confusing part is the PC does $ variable substitution within the config file at load time so the vars in your inline script are replaced with their values from env (or empty if they are not set) before the script is even ran. The worst part is that there is no way to escape it, which handicaps the usability of inline scripts in PC config files. Hence I never do that and always put scripts in their own files. |
i was bit by this badly yesterday, trying to figure out why a script that i was writing like since fixing the templating would be a breaking change (major even?) it would be beneficial to mention this shortcoming in the docs to save others pain. i can open a PR later if nobody beats me to it |
Will it help if I add the ability to escape env variables with foo:
command: "echo log is $$ENV_TEST"
environment:
- 'ENV_TEST=ready' Output: |
I think adding a global .yml boolean disabling the interpolation would be a better start. |
There are a few disadvantages to the global boolean approach:
|
that would help, yes - "add a |
That’s what Google cloudbuild does for their yaml manifests I’d also love an option to disable env substitution globally which could be done via cli flag to avoid double parsing. |
If it was up to me, I’d disable substitution by default and have it enabled with cli flag. Given how many people get tripped up on this I’d say having it opt in would be better since it someone opting into it would first need to read about it and (hopefully) understand how it works. This would require a major version bump, but so would adding the escaping mechanism so maybe it’s a good opportunity to do both at once. |
Agreed! Hence my suggestion to add the option to disable interpolation via the yaml file first (opt out, no breakage, backward compatible). I would then update devenv process-compose YAML generation to include it. This would immediately fix the surprise of the Then after a while the default behavior can be changed in a major release. |
i mean fwiw, the that said, my 2c is that templating (imho) is indeed unnecessary, and probably better served with an opt-in. ideally users handle env vars directly in their process-compose configs, where templating is already available to them in shell utilities |
I am currently leaning toward what @adrian-gierakowski initially suggested.
It probably won't make everyone happy and some users will still be surprised in the future. Still, at least now there will be a well-documented explanation and a "tolerable" quick solution. I also like the v0.6 proposal by @cdmistman I am just worried that there will be another good reason to bump it to v0.7 which will also bring this change that might break a lot of |
perhaps an option within the yaml file as well? i'd imagine frustration when users sharing a config are shocked when they have 2 different behaviors... |
That's a very good point @cdmistman... I wanted to avoid the double parsing, but I guess it's a small price to pay for improved usability (sharing configuration).
Thoughts? |
Fixed in v1.6.1 |
I find this to be very confusing behavior. I think it would help if the docs highlighted this beahaviour. When I looked at the "variables" section in docs I thought oh |
I have the following
yml
file which I feed intoprocess-compose up
:This leads to a
/tmp/output
file being generated - but it's empty. Why is that? If I executeenv
and redirect it, I see the variable.The text was updated successfully, but these errors were encountered: