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

Global variables do not get populated to .env if start from scratch #5

Closed
ygerasimov opened this issue Aug 4, 2024 · 11 comments
Closed

Comments

@ygerasimov
Copy link
Contributor

Steps to reproduce:

  • remove ddev-diffy addon from your project
  • remove DIFFY_PROJECT_ID from .ddev/config.yaml file
  • remove DIFFY_API_KEY from ~/.ddev/global_config.yaml file
  • install the addon ddev get diffywebsite/ddev-diffy, provide API key and project ID during the installation
  • check diffy-worker/.env file and see that both DIFFY_API_KEY and DIFFY_PROJECT_ID are empty

But instead they both should be populated with values you provided during installation of the add-on.

Not that if you keep variables in your .ddev/config.yaml and ~/.ddev/global_config.yaml files and reinstall the add-on (ddev get --remove diffywebsite/ddev-diffy && ddev get diffywebsite/ddev-diffy) you will get variables values populated in diffy-worker/.env file.

Video demo https://www.loom.com/share/bff2d15d3278431393415d763e656d6a

@rfay
Copy link

rfay commented Aug 4, 2024

You seem to be putting them into the DDEV global configuration in https://github.com/DiffyWebsite/ddev-diffy/blob/main/install.yaml#L15-L43

Those populate the web container.

I guess you're then trying to set them for the diffy container in

ddev-diffy/install.yaml

Lines 87 to 88 in e49bb8c

DIFFY_PROJECT_ID=${DIFFY_PROJECT_ID}
DIFFY_API_KEY=${DIFFY_API_KEY}

You seem to be using {{ $foundDiffAPIKey }} in https://github.com/DiffyWebsite/ddev-diffy/blob/main/install.yaml#L61 (probably a typo anyway, should be $foundDiffyAPIKey ?) but I don't see where that has ever been set.

I also don't really understand why you ever put those into the global config instead of just putting them into the diffy .env to begin with.

@rfay
Copy link

rfay commented Aug 4, 2024

Oh, I see super-complicated

    DIFFY_API_KEY='{{- $foundDiffApiKey := false -}}
    {{- range .DdevGlobalConfig.web_environment }}
      {{- if not $foundDiffApiKey }}
        {{- $keyVal := splitList "=" . }}
        {{- if eq (index $keyVal 0) "DIFFY_API_KEY" }}
          {{- index $keyVal 1 -}}
          {{- $foundDiffApiKey = true -}}
        {{- end }}
      {{- end }}
    {{- end }}'

That's probably a bad idea (and apparently isn't working)

@ygerasimov
Copy link
Contributor Author

Worker code we would love to keep outside of ddev-diffy repo as it is used elsewhere in the system (like on our actual production workers).

API Key is a variable to store in global configuration as you might have multiple ddev projects using it. So user doesn't need to re-enter it over and over again.

@rfay Does it make sense to simplify all this by asking users simply to add values to .env file directly? That will be the most straight forward solution.

@rfay
Copy link

rfay commented Aug 4, 2024

I think the problem you're having with this approach is that you're counting on .DdevGlobalConfig.web_environment`, but DDEV read the ~/.ddev/global_config.yaml, etc, before starting the installation, and you then changed it to add the info. You'll need to use a different technique to get the information.

@rfay
Copy link

rfay commented Aug 4, 2024

Think about why you're populating the global config and web config anyway. Will it be used in the web container?

@ygerasimov
Copy link
Contributor Author

It won't be used in web container at all.

@rfay
Copy link

rfay commented Aug 4, 2024

Seems like a mistake to be adding it as environment variables at all then... Instead of doing that, add it to the .env to begin with? You could check the .env instead of checking the global and project config, then add it there?

@ygerasimov
Copy link
Contributor Author

ok. Let me do that instead. Thank you. I'll make it much simpler.

@rfay
Copy link

rfay commented Aug 4, 2024

BTW, thanks for all your exploration here. I'm quite sure ddev-platformsh can be improved since DDEV has evolved and has more capabilities than it did when it was originally done. Maybe we can improve things there, especially using a .env, which is better than editing global config, etc.

@rfay
Copy link

rfay commented Aug 4, 2024

Interestingly enough, DDEV already loads godotenv and could use it in the future to read or (write?) arbitrary .env files.

@ygerasimov
Copy link
Contributor Author

@rfay I have simplified the addon. I am not asking for the credentials during installation and have instructions to add .env file manually. This will keep things straightforward.

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