mirror of
https://github.com/docker/compose.git
synced 2025-07-20 12:14:41 +02:00
Merge pull request #897 from aanand/nicer-env-file-error
Nicer env file error
This commit is contained in:
commit
fd30920aac
@ -95,6 +95,10 @@ class Service(object):
|
|||||||
if 'image' in options and 'build' in options:
|
if 'image' in options and 'build' in options:
|
||||||
raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)
|
raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)
|
||||||
|
|
||||||
|
for filename in get_env_files(options):
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
raise ConfigError("Couldn't find env file for service %s: %s" % (name, filename))
|
||||||
|
|
||||||
supported_options = DOCKER_CONFIG_KEYS + ['build', 'expose',
|
supported_options = DOCKER_CONFIG_KEYS + ['build', 'expose',
|
||||||
'external_links']
|
'external_links']
|
||||||
|
|
||||||
@ -617,15 +621,18 @@ def split_port(port):
|
|||||||
return internal_port, (external_ip, external_port or None)
|
return internal_port, (external_ip, external_port or None)
|
||||||
|
|
||||||
|
|
||||||
|
def get_env_files(options):
|
||||||
|
env_files = options.get('env_file', [])
|
||||||
|
if not isinstance(env_files, list):
|
||||||
|
env_files = [env_files]
|
||||||
|
return env_files
|
||||||
|
|
||||||
|
|
||||||
def merge_environment(options):
|
def merge_environment(options):
|
||||||
env = {}
|
env = {}
|
||||||
|
|
||||||
if 'env_file' in options:
|
for f in get_env_files(options):
|
||||||
if isinstance(options['env_file'], list):
|
env.update(env_vars_from_file(f))
|
||||||
for f in options['env_file']:
|
|
||||||
env.update(env_vars_from_file(f))
|
|
||||||
else:
|
|
||||||
env.update(env_vars_from_file(options['env_file']))
|
|
||||||
|
|
||||||
if 'environment' in options:
|
if 'environment' in options:
|
||||||
if isinstance(options['environment'], list):
|
if isinstance(options['environment'], list):
|
||||||
|
7
tests/fixtures/env/one.env
vendored
7
tests/fixtures/env/one.env
vendored
@ -1,4 +1,11 @@
|
|||||||
|
# Keep the blank lines and comments in this file, please
|
||||||
|
|
||||||
ONE=2
|
ONE=2
|
||||||
TWO=1
|
TWO=1
|
||||||
|
|
||||||
|
# (thanks)
|
||||||
|
|
||||||
THREE=3
|
THREE=3
|
||||||
|
|
||||||
FOO=bar
|
FOO=bar
|
||||||
|
# FOO=somethingelse
|
||||||
|
@ -378,6 +378,10 @@ class ServiceEnvironmentTest(unittest.TestCase):
|
|||||||
{'ONE': '2', 'TWO': '1', 'THREE': '3', 'FOO': 'baz', 'DOO': 'dah'}
|
{'ONE': '2', 'TWO': '1', 'THREE': '3', 'FOO': 'baz', 'DOO': 'dah'}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_env_nonexistent_file(self):
|
||||||
|
self.assertRaises(ConfigError, lambda: Service('foo', env_file='tests/fixtures/env/nonexistent.env'))
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.dict(os.environ)
|
@mock.patch.dict(os.environ)
|
||||||
def test_resolve_environment_from_file(self):
|
def test_resolve_environment_from_file(self):
|
||||||
os.environ['FILE_DEF'] = 'E1'
|
os.environ['FILE_DEF'] = 'E1'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user