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

Document setting Drush config values via environment variable #3009

Closed
weitzman opened this issue Oct 4, 2017 · 8 comments
Closed

Document setting Drush config values via environment variable #3009

weitzman opened this issue Oct 4, 2017 · 8 comments

Comments

@weitzman
Copy link
Member

weitzman commented Oct 4, 2017

The logic for the default value for this config is in drush_find_tmp(). Not changing any logic here, using config system.

@greg-1-anderson
Copy link
Member

The standard is for a .env file with environment variables. Maybe we should support that in consolidation/config?

@weitzman
Copy link
Member Author

weitzman commented Oct 4, 2017

I have used .env files on a couple project and find them very convenient. Sounds great.

I think this change in Drush could happen in parallel with a consolidation/config change, right?

@greg-1-anderson
Copy link
Member

For new designs it is often preferable to implement in Drush first, and then refactor / extract to external components. In cases like this where the new behavior is already incremental to functionality that has already been extracted, I'd say that it is best & just as easy to implement directly in consolidation/config first.

@greg-1-anderson
Copy link
Member

We need a way to map from a config element to an environment variable. Maybe convert . to _ and then uppercase and prepend DRUSH_. That's a start. With that rule, drush.alias-path would become DRUSH_DRUSH_ALIAS-PATH.

The two obvious flaws with this proposal:

  • DRUSH_DRUSH is sub-optimal, but not all config items start with drush., and all environment variables should.
  • Having a - instead of a _ is inconsistent; however, if we converted it to DRUSH_DRUSH_ALIAS_PATH, I'm not sure how we would know whether to convert that back to drush.alias-path instead of drush.alias.path.

Terminus searches both $_SERVER and $_ENV for matches, and overrides set to convert the key to a constant if applicable. Config is read via DotEnvConfig. There is a yml file listing all valid key constants.

Terminus has neither hierarchy nor -s in their config symbols; they would just use alias_path instead of drush.alias-path. Not sure I'd be happy to do likewise.

Maybe rather than reading all of the env variables and applying them as a config, we could instead change the implementation of default handling to check the environment variable before returning the default value. Then the lossy transformation to DRUSH_DRUSH_ALIAS_PATH would be okay, as we would never need to go the other way.

@weitzman
Copy link
Member Author

weitzman commented Nov 3, 2017

My original idea for this issue is now a PR at #3137

However, lets discuss the Env variable mapping. It looks like consolidation/config now supports setting config from Env variables. We need to document how that works, or point to docs in consolidation/config. @greg-1-anderson any chance you could write a couple examples here. I can turn them into docs on examples/example.drush.yml

To answer the questions above

  1. I'm not overly bothered by the DRUSH_DRUSH_ naming. Seems hard to avoid.
  2. Its nearly impossible to set an environment variable with dashes in the name on the CLI. See https://stackoverflow.com/questions/35151619/source-a-file-containing-environment-variables-including-dash-character-in-bas

@greg-1-anderson
Copy link
Member

consolidation/config maps both . and - to _ in the environment variable name, so dashes in the environment name are not a problem (won't happen).

@weitzman weitzman changed the title Create env.tmp config and use it wherever drush_find_tmp() is used Document setting Drush config values via environment variable Nov 12, 2017
@legovaer
Copy link

My 5 cents: I created a PR which allows you to use environment variables in your alias (yaml) file same way as Symfony does it. Have a look at #3202

@weitzman
Copy link
Member Author

yaml-expander got the nice env feature we hoped for. docs still needed.

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

No branches or pull requests

3 participants