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

Initial support for environment variables read from .env #1462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tonsV2
Copy link

@tonsV2 tonsV2 commented Sep 7, 2020

This #1461 led to this pull request.

Not only is this my first contribution in Go this is also the very first Go code that I've written so please tell me what I've done wrong.

@woodcockjosh
Copy link

What is the status of this? I would like to have this feature

@woodcockjosh
Copy link

Is there anyway we can load environment variable from .env files specified for example in environments list? I think that environment variables could be different based on the environment. For example SOPS_PGP_FP would have a different set of public keys to control the access to the secrets based on the environment. Same as docker-compose.

@vpoyraz
Copy link

vpoyraz commented Dec 30, 2021

They way this could be worked around for the time being is to source the .env file and then in your helmfile.yaml:

...
templates:
  default: &default
    values:
      - vars/{{ requiredEnv "ENV" }}/values.yaml
      - extraArgs:
          dryRun: {{ env "DRY_RUN" }}
          logLevel: {{ env "VERBOSE" }}
releases:
- name: my-release-name
  chart: my-chart
  <<: *default

Here I have shortened the example but, basically we can override values.yaml entries extraArgs.dryRun and extraArgs.verbose during runtime:

source .env && helmfile apply

For deploy environments, you could just use a directory structure and override the default chart values.yaml and use it in the template block and pass a YAML anchor (&default).

The vars/ENV/values.yaml file would look like this:

extraArgs: {}
  # dryRun: true
  # verbose: true

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 10, 2022

Sorry for the radio silence. I was revisiting all the pending PRs today and finally had a chance to revisit this.

This is mostly good, but what makes me hesitant to merge this is that this seems to automatically import envvars if there's .env, and you have no way to opt-out of that behavior.

Shouldn't this be an opt-in feature instead? For example, docker run accepts --env-file for basically the same thing.

@tonsV2
Copy link
Author

tonsV2 commented Jan 12, 2022

@mumoshu - That's a good point. Do you have any suggestions on how to implement opt in?

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 12, 2022

@tonsV2 My idea is to add a string-file for --env-file like

helmfile/main.go

Lines 46 to 50 in 87e5903

cli.StringFlag{
Name: "helm-binary, b",
Usage: "path to helm binary",
Value: app.DefaultHelmBinary,
},
, enhance the config struct to have a new function for getting the --env-file value like

helmfile/main.go

Lines 869 to 871 in 87e5903

func (c configImpl) HelmBinary() string {
return c.c.GlobalString("helm-binary")
}
, load environment values or propagate it down to the template functions factory func (c *Context) newTemplate() *template.Template { and godot.load there, so that your template has access to RequiredEng and GetEnv functions that made aware of envvars from the env file.

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

Successfully merging this pull request may close these issues.

None yet

4 participants