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

Add support for environment variables with default values in fig.yml #845

Closed
wants to merge 1 commit into from

Conversation

relwell
Copy link

@relwell relwell commented Jan 15, 2015

This change resolves #495 by introducing a Config class inside the cli
library. The Config class is responsible for loading a .yml file and
evaluating its contents for environment variables. The Config immediately
reloads the data as a dictionary, which reduces compatibility issues within
previously written code. This behavior also prevents race conditions
caused by changes to the environment during long-running fig builds.

This change is valuable because it allows for a greater degree of
automation and variability when working with multiple environments
or deployment types that use identically built containers. We
currently have to define separate services for each degree of
variability we want to account for.

Future steps for this change may include introducing template files,
or adding access and manipulation APIs directly so that we can
perpetuate the config class everywhere we are currently using
bare dictionaries.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: Robert Elwell robert.elwell@gmail.com
Sponsored by: Lookout, Inc.

@@ -10,6 +10,14 @@ Each service defined in `fig.yml` must specify exactly one of `image` or `build`

As with `docker run`, options specified in the Dockerfile (e.g. `CMD`, `EXPOSE`, `VOLUME`, `ENV`) are respected by default - you don't need to specify them again in `fig.yml`.

Fig supports using environment variables with optional backoffs as values. The accepted patterns are as follows:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor terminology issue: I would expect "default" here instead of "backoff"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, will fix

@dnephin
Copy link

dnephin commented Jan 15, 2015

Thanks for the PR!

I like the direction this is taking, I've left a few comments. I suspect others will be interested in this as well.

@relwell
Copy link
Author

relwell commented Jan 15, 2015

Glad to hear it! Do you prefer an additional commit or an amended commit for revisions?

@relwell relwell force-pushed the master branch 2 times, most recently from 9cb07d1 to 30c589c Compare January 15, 2015 17:56
Fig supports using environment variables with optional defaults as values. The accepted patterns are as follows:

```
${ENVIRONMENT_VARIABLE:backoff}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/backoff/default/

@aanand
Copy link

aanand commented Jan 15, 2015

Thanks!

  1. I'm similarly wary of regular expressions, but if there's no practical alternative then fine. In either case we're going to need an extensive set of unit tests to cover edge cases and such.
  2. How do I escape the dollar-curly-brace syntax, if I actually want the string ${FOO} to appear?
  3. A single, squashed commit is preferred.

@thaJeztah
Copy link
Member

Good points by Aanand.

I added a couple of nits while glancing over the PR.

Thanks very much, this looks like a very useful feature that I'll definitely use!

@relwell
Copy link
Author

relwell commented Jan 15, 2015

@aanand I've added in support to escape the text as "${FOO}". Please refer to (the following test)[https://github.com//pull/845/files#diff-a1643645d7f79dbd5684ed0631ab1066R50] and let me know if you think anything is missing here.


def from_yaml_with_environment_vars(yaml_filename):
"""
Resolves enviornment variables in values defined by a YAML file and transformed into a dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo; enviornment

@relwell
Copy link
Author

relwell commented Jan 16, 2015

I've added some basic regex tokenization support that will allow us to provide multiple environment variables per line, and accompanying tests.

@relwell
Copy link
Author

relwell commented Feb 6, 2015

@aanand , it's been 22 days since #846 was opened, and not much has been decided. The community seems to be heavily in favor of delivering a solution to #495 sooner rather than later.

If you take #426 into account, there has been an open community request for a feature like this for over 120 days.

Since this seems to be close to the direction we want to take, and there have been no additional revision requests, I'd appreciate a merge on this so that we can show some progress on this issue. If you can't merge now, I think we'd all appreciate some kind of timeline or feedback, since we haven't seen much activity from the admins on this issue for the last couple of weeks.

This change resolves docker#495 by introducing a Config class inside the cli
library. The Config class is responsible for loading a .yml file and
evaluating its contents for environment variables. The Config immediately
reloads the data as a dictionary, which reduces compatibility issues within
previously written code. This behavior also prevents race conditions
caused by changes to the environment during long-running fig builds.

This change is valuable because it allows for a greater degree of
automation and variability when working with multiple environments
or deployment types that use identically built containers. We
currently have to define separate services for each degree of
variability we want to account for.

Future steps for this change may include introducing template files,
or adding access and manipulation APIs directly so that we can
perpetuate the config class everywhere we are currently using
bare dictionaries.

Added in revision requests from  @dnephin:

* Terminology fix in docs/yml.md
* Refactored config class into a series of functions
* Updated tests to reflect functional interpolation
* Improved forward compatibility

Added in revision requests from @thaJeztah

* Terminology fixes

Added in revision requests from @aanand

* Support for escaping

Added in revision requests from @thaJeztah

* Support for multiple variables per line

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Robert Elwell <robert.elwell@gmail.com>
Sponsored by: Lookout, Inc.
@relwell
Copy link
Author

relwell commented Feb 6, 2015

FYI: I've updated the PR to support the new docker compose format.

@relwell relwell mentioned this pull request Feb 10, 2015
@relwell
Copy link
Author

relwell commented Feb 10, 2015

@aanand @thaJeztah @dnephin would it be possible to get some status on this PR, and any outstanding issues that may need to be addressed to get it merged in?

@thaJeztah
Copy link
Member

Unfortunately, I'm not a maintainer, so I cannot give you an update. I like this feature and certainly hope this gets approved/merged. It may need a final review to check if everything is okay to merge.

@aanand aanand changed the title Add support for environment variables with backoff values in fig.yml Add support for environment variables with fallback values in fig.yml Feb 11, 2015
@aanand aanand changed the title Add support for environment variables with fallback values in fig.yml Add support for environment variables with default values in fig.yml Feb 11, 2015
@aanand
Copy link

aanand commented Feb 11, 2015

I'm going to review this soon - we've a lot on our plate with the impending Compose release. I'd like to get this merged soon after that release, but it needs thorough inspection and fuzz-testing.

@hawknewton
Copy link

For what it's worth I find environment-specific configuration values shouldn't have defaults.

This usually goes one of two ways: either the developer enters development-time defaults and forgets to update them for production (?!) or the defaults are for production and you have to override them in your development/QA environments. Having your dev/QA deploy jobs diverge from your production deploy jobs is a clear anti-pattern not to mention the terrifying possibility that somebody forgets to override the production database information for a QA deploy.

I'm super-interested in coming up with a mechanism by which a given profile could be activated as defined in the the yaml that would tailor the application for a given environment or class of environment. When in QA mode I might use a lower TTL to facilitate testing. When in development mode maybe I force the developer to provide database connection information via environment variables, etc.

Anyway, just my two cents.

@torbjornvatn
Copy link

Any news on when we can expect this PR to appear in a release. It's a feature I really need to make make docker-compose scheme to work

@hadim
Copy link

hadim commented Apr 7, 2015

Any news here ?

@relwell
Copy link
Author

relwell commented Apr 23, 2015

Is there a plan for integrating this pull request, ever?

I'm happy to rebase and re-push, but I'm not going to bother if you guys don't have a plan to integrate these changes.

My ask is that if there is not a plan to integrate these changes, that you reject the CR, and close #495 as a "won't fix" feature request.

@aanand
Copy link

aanand commented Apr 30, 2015

I've put the current state of my thinking at #1377. Summary: this is the best design so far, but the implementation isn't there yet.

@relwell
Copy link
Author

relwell commented Apr 30, 2015

I'll leave you guys to worry about handling this then. I'm tired of wasting my time with this.

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.

Pass variables inside fig.yml on runtime
7 participants