mirror of https://github.com/docker/compose.git
Support multiple files in COMPOSE_FILE env var.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
f75408923e
commit
53a3d14046
|
@ -58,8 +58,10 @@ def get_config_path_from_options(options):
|
||||||
if file_option:
|
if file_option:
|
||||||
return file_option
|
return file_option
|
||||||
|
|
||||||
config_file = os.environ.get('COMPOSE_FILE')
|
config_files = os.environ.get('COMPOSE_FILE')
|
||||||
return [config_file] if config_file else None
|
if config_files:
|
||||||
|
return config_files.split(os.pathsep)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_client(verbose=False, version=None):
|
def get_client(verbose=False, version=None):
|
||||||
|
|
|
@ -27,10 +27,15 @@ defaults to the `basename` of the project directory. See also the `-p`
|
||||||
|
|
||||||
## COMPOSE\_FILE
|
## COMPOSE\_FILE
|
||||||
|
|
||||||
Specify the file containing the compose configuration. If not provided,
|
Specify the path to a Compose file. If not provided, Compose looks for a file named
|
||||||
Compose looks for a file named `docker-compose.yml` in the current directory
|
`docker-compose.yml` in the current directory and then each parent directory in
|
||||||
and then each parent directory in succession until a file by that name is
|
succession until a file by that name is found.
|
||||||
found. See also the `-f` [command-line option](overview.md).
|
|
||||||
|
This variable supports multiple compose files separate by a path separator (on
|
||||||
|
Linux and OSX the path separator is `:`, on Windows it is `;`). For example:
|
||||||
|
`COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml`
|
||||||
|
|
||||||
|
See also the `-f` [command-line option](overview.md).
|
||||||
|
|
||||||
## COMPOSE\_API\_VERSION
|
## COMPOSE\_API\_VERSION
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
from compose.cli import errors
|
from compose.cli import errors
|
||||||
from compose.cli.command import friendly_error_message
|
from compose.cli.command import friendly_error_message
|
||||||
|
from compose.cli.command import get_config_path_from_options
|
||||||
|
from compose.const import IS_WINDOWS_PLATFORM
|
||||||
from tests import mock
|
from tests import mock
|
||||||
from tests import unittest
|
|
||||||
|
|
||||||
|
|
||||||
class FriendlyErrorMessageTestCase(unittest.TestCase):
|
class TestFriendlyErrorMessage(object):
|
||||||
|
|
||||||
def test_dispatch_generic_connection_error(self):
|
def test_dispatch_generic_connection_error(self):
|
||||||
with pytest.raises(errors.ConnectionErrorGeneric):
|
with pytest.raises(errors.ConnectionErrorGeneric):
|
||||||
|
@ -21,3 +24,31 @@ class FriendlyErrorMessageTestCase(unittest.TestCase):
|
||||||
):
|
):
|
||||||
with friendly_error_message():
|
with friendly_error_message():
|
||||||
raise ConnectionError()
|
raise ConnectionError()
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetConfigPathFromOptions(object):
|
||||||
|
|
||||||
|
def test_path_from_options(self):
|
||||||
|
paths = ['one.yml', 'two.yml']
|
||||||
|
opts = {'--file': paths}
|
||||||
|
assert get_config_path_from_options(opts) == paths
|
||||||
|
|
||||||
|
def test_single_path_from_env(self):
|
||||||
|
with mock.patch.dict(os.environ):
|
||||||
|
os.environ['COMPOSE_FILE'] = 'one.yml'
|
||||||
|
assert get_config_path_from_options({}) == ['one.yml']
|
||||||
|
|
||||||
|
@pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='posix separator')
|
||||||
|
def test_multiple_path_from_env(self):
|
||||||
|
with mock.patch.dict(os.environ):
|
||||||
|
os.environ['COMPOSE_FILE'] = 'one.yml:two.yml'
|
||||||
|
assert get_config_path_from_options({}) == ['one.yml', 'two.yml']
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not IS_WINDOWS_PLATFORM, reason='windows separator')
|
||||||
|
def test_multiple_path_from_env_windows(self):
|
||||||
|
with mock.patch.dict(os.environ):
|
||||||
|
os.environ['COMPOSE_FILE'] = 'one.yml;two.yml'
|
||||||
|
assert get_config_path_from_options({}) == ['one.yml', 'two.yml']
|
||||||
|
|
||||||
|
def test_no_path(self):
|
||||||
|
assert not get_config_path_from_options({})
|
||||||
|
|
Loading…
Reference in New Issue