Skip to content

Add support for 'env-file' key - #481

Closed
dekked wants to merge 1 commit into
docker:masterfrom
dekked:support-env-file
Closed

dekked wants to merge 1 commit into
docker:masterfrom
dekked:support-env-file

Conversation

@dekked

@dekked dekked commented Sep 12, 2014

Copy link
Copy Markdown

I wasn't going to make PR until adding test, but it seems it would save people some work so in the meantime, here it is.

This adds support for the env-file key, with a path to a file in the same format docker run --env-file would take. It can work together with environment key, meaning the variables defined in the file will be overriden by anything environment specifies.

@dekked dekked mentioned this pull request Sep 12, 2014
Signed-off-by: Alan Descoins <[email protected]>
@zimbatm

zimbatm commented Sep 19, 2014

Copy link
Copy Markdown

It would be nice if it could read the .env format introduced by foreman. https://github.com/theskumar/python-dotenv

@bfirsh

bfirsh commented Sep 30, 2014

Copy link
Copy Markdown

Thanks @dekked! Any chance you could write docs and tests?

@aanand

aanand commented Sep 30, 2014

Copy link
Copy Markdown

Bikeshedding, but I'd prefer underscored (env_file) rather than dashed, for consistency with the other options. Otherwise, looks good!

@bfirsh

bfirsh commented Oct 1, 2014

Copy link
Copy Markdown

👍 That's not bikeshedding, that's just right. ;)

@marksteve

Copy link
Copy Markdown

👍 As a temporary solution, I've been wrapping fig with a bash script that does source config.sh.

@dekked

dekked commented Oct 1, 2014

Copy link
Copy Markdown
Author

Sure, I'll make the change and write docs/test as soon as I have time! Stay tuned :)

@tristanz

tristanz commented Oct 6, 2014

Copy link
Copy Markdown

In docker, --env-file can be used multiple times with variables merged. This would suggest env_file should be an array, or at least allow an array of strings rather than just a single string.

@jmreicha

jmreicha commented Nov 1, 2014

Copy link
Copy Markdown

👍 this would be really useful.

@jmreicha

jmreicha commented Nov 4, 2014

Copy link
Copy Markdown

I am having trouble getting this PR working on my laptop and am not sure what to look at. Here is the error I'm getting:

Traceback (most recent call last):
  File "/usr/local/bin/fig", line 8, in <module>
    load_entry_point('fig==1.0.0', 'console_scripts', 'fig')()
  File "/Users/user/github/fig/fig/cli/main.py", line 31, in main
    command.sys_dispatch()
  File "/Users/user/github/fig/fig/cli/docopt_command.py", line 21, in sys_dispatch
    self.dispatch(sys.argv[1:], None)
  File "/Users/user/github/fig/fig/cli/command.py", line 28, in dispatch
    super(Command, self).dispatch(*args, **kwargs)
  File "/Users/user/github/fig/fig/cli/docopt_command.py", line 24, in dispatch
    self.perform_command(*self.parse(argv, global_options))
  File "/Users/user/github/fig/fig/cli/command.py", line 51, in perform_command
    handler(project, command_options)
  File "/Users/user/github/fig/fig/cli/main.py", line 427, in up
    insecure_registry=insecure_registry,
  File "/Users/user/github/fig/fig/project.py", line 175, in up
    for (_, container) in service.recreate_containers():
  File "/Users/user/github/fig/fig/service.py", line 190, in recreate_containers
    container = self.create_container(**override_options)
  File "/Users/user/github/fig/fig/service.py", line 170, in create_container
    container_options = self._get_container_create_options(override_options, one_off=one_off)
  File "/Users/user/github/fig/fig/service.py", line 366, in _get_container_create_options
    container_options['environment'] = self._get_environment()
  File "/Users/user/github/fig/fig/service.py", line 322, in _get_environment
    env = env_vars_from_file(self.options['env-file'])
  File "/Users/user/github/fig/fig/service.py", line 525, in env_vars_from_file
    for line in open(filename, 'r'):
TypeError: coercing to Unicode: need string or buffer, list found

Just an update, I got this figured out. I have a bad yml configuration, very silly mistake. For others that get this error here is what it should look like:

env-file: "/full/path/to/env_vars_file"

@asmundg

asmundg commented Nov 5, 2014

Copy link
Copy Markdown

Would it make sense to reverse the precedence so that env-file overrides environment? I find myself wanting a pattern where I can specify a default environment and then override it explicitly per command line.

@benlangfeld benlangfeld mentioned this pull request Nov 21, 2014
@benlangfeld

Copy link
Copy Markdown

@asmundg This would be the opposite of Docker's behaviour, so I think it would be difficult to do that.

@bfirsh

bfirsh commented Dec 9, 2014

Copy link
Copy Markdown

This has been added in #665. Thanks anyway!

@bfirsh bfirsh closed this Dec 9, 2014
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.

9 participants