mirror of
https://github.com/docker/compose.git
synced 2025-07-21 04:34:38 +02:00
Raise exception when override.yaml & override.yml coexist
Signed-off-by: Eli Atzaba <eliat123@gmail.com>
This commit is contained in:
parent
d0b80f537b
commit
88fa8db79a
@ -24,6 +24,7 @@ from .environment import split_env
|
|||||||
from .errors import CircularReference
|
from .errors import CircularReference
|
||||||
from .errors import ComposeFileNotFound
|
from .errors import ComposeFileNotFound
|
||||||
from .errors import ConfigurationError
|
from .errors import ConfigurationError
|
||||||
|
from .errors import DuplicateOverrideFileFound
|
||||||
from .errors import VERSION_EXPLANATION
|
from .errors import VERSION_EXPLANATION
|
||||||
from .interpolation import interpolate_environment_variables
|
from .interpolation import interpolate_environment_variables
|
||||||
from .sort_services import get_container_name_from_network_mode
|
from .sort_services import get_container_name_from_network_mode
|
||||||
@ -292,11 +293,12 @@ def get_default_config_files(base_dir):
|
|||||||
|
|
||||||
|
|
||||||
def get_default_override_file(path):
|
def get_default_override_file(path):
|
||||||
for default_override_filename in DEFAULT_OVERRIDE_FILENAMES:
|
override_files_in_path = [os.path.join(path, override_filename) for override_filename
|
||||||
override_filename = os.path.join(path, default_override_filename)
|
in DEFAULT_OVERRIDE_FILENAMES
|
||||||
if os.path.exists(override_filename):
|
if os.path.exists(os.path.join(path, override_filename))]
|
||||||
return [override_filename]
|
if len(override_files_in_path) > 1:
|
||||||
return []
|
raise DuplicateOverrideFileFound(override_files_in_path)
|
||||||
|
return override_files_in_path
|
||||||
|
|
||||||
|
|
||||||
def find_candidates_in_parent_dirs(filenames, path):
|
def find_candidates_in_parent_dirs(filenames, path):
|
||||||
|
@ -44,3 +44,15 @@ class ComposeFileNotFound(ConfigurationError):
|
|||||||
|
|
||||||
Supported filenames: %s
|
Supported filenames: %s
|
||||||
""" % ", ".join(supported_filenames))
|
""" % ", ".join(supported_filenames))
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateOverrideFileFound(ConfigurationError):
|
||||||
|
def __init__(self, override_filenames):
|
||||||
|
self.override_filenames = override_filenames
|
||||||
|
|
||||||
|
@property
|
||||||
|
def msg(self):
|
||||||
|
return """
|
||||||
|
Unable to determine with duplicate override files, only a single override file can be used.
|
||||||
|
Found: %s
|
||||||
|
""" % ", ".join(self.override_filenames)
|
||||||
|
@ -21,6 +21,7 @@ from docker import errors
|
|||||||
from .. import mock
|
from .. import mock
|
||||||
from ..helpers import create_host_file
|
from ..helpers import create_host_file
|
||||||
from compose.cli.command import get_project
|
from compose.cli.command import get_project
|
||||||
|
from compose.config.errors import DuplicateOverrideFileFound
|
||||||
from compose.container import Container
|
from compose.container import Container
|
||||||
from compose.project import OneOffFilter
|
from compose.project import OneOffFilter
|
||||||
from compose.utils import nanoseconds_from_time_seconds
|
from compose.utils import nanoseconds_from_time_seconds
|
||||||
@ -31,7 +32,6 @@ from tests.integration.testcases import v2_1_only
|
|||||||
from tests.integration.testcases import v2_only
|
from tests.integration.testcases import v2_only
|
||||||
from tests.integration.testcases import v3_only
|
from tests.integration.testcases import v3_only
|
||||||
|
|
||||||
|
|
||||||
ProcessResult = namedtuple('ProcessResult', 'stdout stderr')
|
ProcessResult = namedtuple('ProcessResult', 'stdout stderr')
|
||||||
|
|
||||||
|
|
||||||
@ -2165,3 +2165,9 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
web, db = containers
|
web, db = containers
|
||||||
self.assertEqual(web.human_readable_command, 'sleep 100')
|
self.assertEqual(web.human_readable_command, 'sleep 100')
|
||||||
self.assertEqual(db.human_readable_command, 'top')
|
self.assertEqual(db.human_readable_command, 'top')
|
||||||
|
|
||||||
|
def test_up_with_duplicate_override_yaml_files(self):
|
||||||
|
self.base_dir = 'tests/fixtures/duplicate-override-yaml-files'
|
||||||
|
with self.assertRaises(DuplicateOverrideFileFound):
|
||||||
|
get_project(self.base_dir, [])
|
||||||
|
self.base_dir = None
|
||||||
|
3
tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml
vendored
Normal file
3
tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
db:
|
||||||
|
command: "top"
|
3
tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml
vendored
Normal file
3
tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
db:
|
||||||
|
command: "sleep 300"
|
10
tests/fixtures/duplicate-override-yaml-files/docker-compose.yml
vendored
Normal file
10
tests/fixtures/duplicate-override-yaml-files/docker-compose.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
web:
|
||||||
|
image: busybox:latest
|
||||||
|
command: "sleep 100"
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: busybox:latest
|
||||||
|
command: "sleep 200"
|
Loading…
x
Reference in New Issue
Block a user