Skip to content

Support for --env-file #479

Closed
Closed

Description

@benlangfeld

Some of the containers in my project require sensitive data (such as 3rd party API tokens) to be passed as environment variables. I understand that I can enumerate these without values in my fig.yml to be picked up from the host environment, but then I still need some way to get them there, meaning one of:

  • Passing these on every fig invocation (unacceptable due to the repetition), or
  • Yet another script to wrap fig and load these environment variables from disk.

Docker already provides support for loading a container environment from disk in the --env-file option to docker run. It would be nice if fig exposed this as environment_file as a parallel to the current environment option.

I'd be happy to submit a PR for this, but in order to do so I would need pointing in the right direction by someone who actually knows Python. I figure the implementation would likely be as easy as extending this constant and that I'd probably need a test similar to this one. Am I on the right track so far?

Activity

  1. dnephin commented on Sep 10, 2014

    @dnephin

    Sounds like you're on the right track, but I think there is more work involved. https://github.com/docker/fig/blob/ce8ef23c097995b7a9f295c9621b5f25e683c2c4/fig/service.py#L318 similar to how environment is handled here.

    Looking at https://github.com/docker/docker-py create_container() doesn't accept a environment_file. I suspect this is because it's being handled by the docker client (not on the server), so you'll probably have to handle the param by actually reading the file and updating the environment in this method.

  2. benlangfeld commented on Sep 10, 2014

    @benlangfeld
    Author

    It does seem you're right in that this is only supported client-side and so we'd have to implement it along the same lines.

    I'll give it a shot tomorrow.

  3. benlangfeld commented on Sep 10, 2014

    @benlangfeld
    Author

    Attempting to setup my development environment, following the instructions here, I get this, suggesting the test dependencies aren't being installed:

    ➭ sudo python setup.py develop
    running develop
    running egg_info
    writing requirements to fig.egg-info/requires.txt
    writing fig.egg-info/PKG-INFO
    writing top-level names to fig.egg-info/top_level.txt
    writing dependency_links to fig.egg-info/dependency_links.txt
    writing entry points to fig.egg-info/entry_points.txt
    reading manifest file 'fig.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files matching '*' found under directory 'tests'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.un~' found anywhere in distribution
    writing manifest file 'fig.egg-info/SOURCES.txt'
    running build_ext
    Creating /Library/Python/2.7/site-packages/fig.egg-link (link to .)
    fig 0.5.2 is already the active version in easy-install.pth
    Installing fig script to /usr/local/bin
    
    Installed /Users/ben/code/fig
    Processing dependencies for fig==0.5.2
    Searching for six==1.7.3
    Best match: six 1.7.3
    Processing six-1.7.3-py2.7.egg
    six 1.7.3 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/six-1.7.3-py2.7.egg
    Searching for docker-py==0.5.0
    Best match: docker-py 0.5.0
    Processing docker_py-0.5.0-py2.7.egg
    docker-py 0.5.0 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/docker_py-0.5.0-py2.7.egg
    Searching for dockerpty==0.2.3
    Best match: dockerpty 0.2.3
    Processing dockerpty-0.2.3-py2.7.egg
    dockerpty 0.2.3 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/dockerpty-0.2.3-py2.7.egg
    Searching for websocket-client==0.11.0
    Best match: websocket-client 0.11.0
    Processing websocket_client-0.11.0-py2.7.egg
    websocket-client 0.11.0 is already the active version in easy-install.pth
    Installing wsdump.py script to /usr/local/bin
    
    Using /Library/Python/2.7/site-packages/websocket_client-0.11.0-py2.7.egg
    Searching for texttable==0.8.1
    Best match: texttable 0.8.1
    Processing texttable-0.8.1-py2.7.egg
    texttable 0.8.1 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/texttable-0.8.1-py2.7.egg
    Searching for requests==2.4.1
    Best match: requests 2.4.1
    Processing requests-2.4.1-py2.7.egg
    requests 2.4.1 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/requests-2.4.1-py2.7.egg
    Searching for PyYAML==3.11
    Best match: PyYAML 3.11
    Processing PyYAML-3.11-py2.7-macosx-10.9-intel.egg
    PyYAML 3.11 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/PyYAML-3.11-py2.7-macosx-10.9-intel.egg
    Searching for docopt==0.6.2
    Best match: docopt 0.6.2
    Processing docopt-0.6.2-py2.7.egg
    docopt 0.6.2 is already the active version in easy-install.pth
    
    Using /Library/Python/2.7/site-packages/docopt-0.6.2-py2.7.egg
    Finished processing dependencies for fig==0.5.2
    {15:35}~/code/fig:master ✓ [2.1.2]
    ➭ sudo ./script/test
    ./script/test: line 3: flake8: command not found
    

    Is there a step missing from the docs?

  4. dnephin commented on Sep 10, 2014

    @dnephin

    Personally I think those notes need to be updated, they didn't work for me, and they aren't really "standard" for python development.

    I would do this:

    1. install python-tox (https://pypi.python.org/pypi/tox) using apt, yum, pip, whatever
    2. tox -e py27 to run tests and build a virtualenv
    3. If you want to do something interactively , just source the virtualenv source .tox/py27/bin/active

    See also: http://virtualenv.readthedocs.org/en/latest/virtualenv.html#usage

  5. dekked commented on Sep 12, 2014

    @dekked

    I made PR #481 for you :) comments are welcome, or if you would like to contribute with test.

  6. benlangfeld commented on Sep 12, 2014

    @benlangfeld
    Author

    Awesome, thanks @dekked. I'll see if I can figure out some tests over the weekend.

  7. tomfotherby commented on Oct 21, 2014

    @tomfotherby

    --env-file would be a fantastic edition to fig - shame it didn't make the v1.0.0 release. Keep up the good work. 👍

  8. geovanisouza92 commented on Oct 21, 2014

    @geovanisouza92

    +1

  9. albers commented on Oct 23, 2014

    @albers

    +1

  10. djdefi commented on Oct 24, 2014

    @djdefi

    +1

  11. JustinTulloss commented on Oct 27, 2014

    @JustinTulloss

    +1

  12. kunday commented on Nov 8, 2014

    @kunday

    +1

  13. benlangfeld commented on Dec 5, 2014

    @benlangfeld
    Author

    Closing in favour of #665 where this is implemented.

  14. bobcolner commented on Jan 7, 2015

    @bobcolner

    +1

  15. benlangfeld commented on Jan 7, 2015

    @benlangfeld
    Author

    That won't help, @bobcolner. See my last comment.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions