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

Variable substitution not working in env files #656

Closed
gyszalai opened this issue May 12, 2022 · 15 comments · Fixed by #657 or #665
Closed

Variable substitution not working in env files #656

gyszalai opened this issue May 12, 2022 · 15 comments · Fixed by #657 or #665

Comments

@gyszalai
Copy link

It seems that environment variables are not substituted in env files.
I use helmsman 3.9.0. I checked the godotenv library that this project uses for loading env files and from version 1.3.0 it should work. Helmsman 3.9.0 uses 1.4.0 of this lib.

Example:

helmsman.yaml

context: mycontext
metadata:
  test: "${TEST_VAR}"

.env file

TEST_VAR=${SOMETHING}

Calling helmsman:

export SOMETHING=some_value
helmsman --debug -e .env -f helmsman.yaml

result (from helmsman output)

Metadata: 
--------- 
test :  

Context: 
--------- 
mycontext

Am I doing somethong wrong or is it a bug?

@luisdavim
Copy link
Collaborator

Hi, you need to enable it with the config flags --subst-env-values

@gyszalai
Copy link
Author

Hi, thanks for your suggestion, but the situation is the same with --subst-env-values

Actually, according to the documentation, this CLI option is for value files not env files:
--subst-env-values turn on environment substitution in values files.

I need the substitution in an env file that is passed to helmsman with the -e option.

@gyszalai
Copy link
Author

Our use case is that the operations team provides a helm repo base URL in an env var on the CI server and we would like to use it in our .env file like this:

HELM_REPO_URL=${HELM_REPO_BASE_URL}/our-repo/

@luisdavim
Copy link
Collaborator

Oh, I think the problem might be that we're not expanding the environment variables inside the env file. I'll look into that.

@luisdavim
Copy link
Collaborator

Hi, I've opened a PR to address this (#657) would you be able to test your use case using a build from that branch?

@luisdavim
Copy link
Collaborator

I was checking godotenv's code and my PR might not be enough, godotenv only expands variables that are set in the loaded env files.

There are issues regarding this:

@luisdavim
Copy link
Collaborator

as a workaround, untill this gets fixed upstream, you can try adding something like this in your CI:

export SOMETHING=some_value
printenv > cur.env
helmsman --debug  -e cur.env -e .env -f helmsman.yaml

@luisdavim
Copy link
Collaborator

Keeping this open as godotenv's implementation might still affect the issue

@gyszalai
Copy link
Author

Sorry, I was offline for a few days. I'll check if it solves our problem.

@gyszalai
Copy link
Author

just built helmsman from the master branch, but it doesn't seem to be working :(

@luisdavim
Copy link
Collaborator

Yeah, I think the problem is that with the current implementation godotenv will expand HELM_REPO_URL=${HELM_REPO_BASE_URL}/our-repo/ as HELM_REPO_URL=/our-repo/ unless HELM_REPO_BASE_URL is also defined in the env file, there are a bunch o issues and PRs open about this in https://github.com/joho/godotenv, but the maintainer isn't responding....

There's also https://github.com/subosito/gotenv I can have a look at that and see it would be a suitable replacement if the issue doesn't get fixed in godotenv...

@gyszalai
Copy link
Author

Yes, I just checked the godotenv project and saw that there are multiple issues regarding this problem. Anyway, thank you for your efforts! That would be great if you could look at the other lib (gotenv), though.

@luisdavim
Copy link
Collaborator

luisdavim commented May 20, 2022

Once subosito/gotenv#15 is merged, I think we can switch from godotenv to gotenv.
subosito/gotenv#12 was making it incompatible with our use case

@luisdavim
Copy link
Collaborator

Hi @gyszalai would you be able to test a build from #665 and let me know if it solves your use case?

@gyszalai
Copy link
Author

Hi @luisdavim I just checked it and it looks good! 👍 The variable is resolved either if its in another env file or just simply exported before calling helmsman. Thank you for your efforts!

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