From 9334f29898fba51f7d44c6368b4d8df54b6cfc2e Mon Sep 17 00:00:00 2001 From: Eli Atzaba Date: Sat, 29 Apr 2017 02:00:52 +0300 Subject: [PATCH 1/3] Fix for yaml extention does not work with override file Signed-off-by: Eli Atzaba --- compose/config/config.py | 9 ++++++--- tests/acceptance/cli_test.py | 16 ++++++++++++++++ .../docker-compose.override.yaml | 3 +++ .../override-yaml-files/docker-compose.yml | 10 ++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/override-yaml-files/docker-compose.override.yaml create mode 100644 tests/fixtures/override-yaml-files/docker-compose.yml diff --git a/compose/config/config.py b/compose/config/config.py index 4fddac822..861a3e9bf 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -128,7 +128,7 @@ SUPPORTED_FILENAMES = [ 'docker-compose.yaml', ] -DEFAULT_OVERRIDE_FILENAME = 'docker-compose.override.yml' +DEFAULT_OVERRIDE_FILENAMES = ('docker-compose.override.yml', 'docker-compose.override.yaml') log = logging.getLogger(__name__) @@ -292,8 +292,11 @@ def get_default_config_files(base_dir): def get_default_override_file(path): - override_filename = os.path.join(path, DEFAULT_OVERRIDE_FILENAME) - return [override_filename] if os.path.exists(override_filename) else [] + for default_override_filename in DEFAULT_OVERRIDE_FILENAMES: + override_filename = os.path.join(path, default_override_filename) + if os.path.exists(override_filename): + return [override_filename] + return [] def find_candidates_in_parent_dirs(filenames, path): diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 30eff1b6a..f6c074364 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -2149,3 +2149,19 @@ class CLITestCase(DockerClientTestCase): assert 'busybox' in result.stdout assert 'multiplecomposefiles_another_1' in result.stdout assert 'multiplecomposefiles_simple_1' in result.stdout + + def test_up_with_override_yaml(self): + self.base_dir = 'tests/fixtures/override-yaml-files' + self._project = get_project(self.base_dir, []) + self.dispatch( + [ + 'up', '-d', + ], + None) + + containers = self.project.containers() + self.assertEqual(len(containers), 2) + + web, db = containers + self.assertEqual(web.human_readable_command, 'sleep 100') + self.assertEqual(db.human_readable_command, 'top') diff --git a/tests/fixtures/override-yaml-files/docker-compose.override.yaml b/tests/fixtures/override-yaml-files/docker-compose.override.yaml new file mode 100644 index 000000000..58c673482 --- /dev/null +++ b/tests/fixtures/override-yaml-files/docker-compose.override.yaml @@ -0,0 +1,3 @@ + +db: + command: "top" diff --git a/tests/fixtures/override-yaml-files/docker-compose.yml b/tests/fixtures/override-yaml-files/docker-compose.yml new file mode 100644 index 000000000..5f2909d69 --- /dev/null +++ b/tests/fixtures/override-yaml-files/docker-compose.yml @@ -0,0 +1,10 @@ + +web: + image: busybox:latest + command: "sleep 100" + links: + - db + +db: + image: busybox:latest + command: "sleep 200" From 0d0c0454e90ab40a72600844b8eba10314304869 Mon Sep 17 00:00:00 2001 From: Eli Atzaba Date: Sun, 7 May 2017 18:03:14 +0300 Subject: [PATCH 2/3] Raise exception when override.yaml & override.yml coexist Signed-off-by: Eli Atzaba --- compose/config/config.py | 12 +++++++----- compose/config/errors.py | 12 ++++++++++++ tests/acceptance/cli_test.py | 8 +++++++- .../docker-compose.override.yaml | 3 +++ .../docker-compose.override.yml | 3 +++ .../duplicate-override-yaml-files/docker-compose.yml | 10 ++++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml create mode 100644 tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml create mode 100644 tests/fixtures/duplicate-override-yaml-files/docker-compose.yml diff --git a/compose/config/config.py b/compose/config/config.py index 861a3e9bf..2a81b93da 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -24,6 +24,7 @@ from .environment import split_env from .errors import CircularReference from .errors import ComposeFileNotFound from .errors import ConfigurationError +from .errors import DuplicateOverrideFileFound from .errors import VERSION_EXPLANATION from .interpolation import interpolate_environment_variables 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): - for default_override_filename in DEFAULT_OVERRIDE_FILENAMES: - override_filename = os.path.join(path, default_override_filename) - if os.path.exists(override_filename): - return [override_filename] - return [] + override_files_in_path = [os.path.join(path, override_filename) for override_filename + in DEFAULT_OVERRIDE_FILENAMES + if os.path.exists(os.path.join(path, override_filename))] + if len(override_files_in_path) > 1: + raise DuplicateOverrideFileFound(override_files_in_path) + return override_files_in_path def find_candidates_in_parent_dirs(filenames, path): diff --git a/compose/config/errors.py b/compose/config/errors.py index 9b82df0ab..060564fc4 100644 --- a/compose/config/errors.py +++ b/compose/config/errors.py @@ -44,3 +44,15 @@ class ComposeFileNotFound(ConfigurationError): Supported filenames: %s """ % ", ".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) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index f6c074364..1ba64201f 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -21,6 +21,7 @@ from docker import errors from .. import mock from ..helpers import create_host_file from compose.cli.command import get_project +from compose.config.errors import DuplicateOverrideFileFound from compose.container import Container from compose.project import OneOffFilter 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 v3_only - ProcessResult = namedtuple('ProcessResult', 'stdout stderr') @@ -2165,3 +2165,9 @@ class CLITestCase(DockerClientTestCase): web, db = containers self.assertEqual(web.human_readable_command, 'sleep 100') 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 diff --git a/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml b/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml new file mode 100644 index 000000000..58c673482 --- /dev/null +++ b/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yaml @@ -0,0 +1,3 @@ + +db: + command: "top" diff --git a/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml b/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml new file mode 100644 index 000000000..f1b8ef181 --- /dev/null +++ b/tests/fixtures/duplicate-override-yaml-files/docker-compose.override.yml @@ -0,0 +1,3 @@ + +db: + command: "sleep 300" diff --git a/tests/fixtures/duplicate-override-yaml-files/docker-compose.yml b/tests/fixtures/duplicate-override-yaml-files/docker-compose.yml new file mode 100644 index 000000000..5f2909d69 --- /dev/null +++ b/tests/fixtures/duplicate-override-yaml-files/docker-compose.yml @@ -0,0 +1,10 @@ + +web: + image: busybox:latest + command: "sleep 100" + links: + - db + +db: + image: busybox:latest + command: "sleep 200" From 7f1f450080c1029cb2b3c008ca527c00338147f4 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Tue, 23 May 2017 12:14:32 -0700 Subject: [PATCH 3/3] Rewrite duplicate override error message Signed-off-by: Joffrey F --- compose/config/errors.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/compose/config/errors.py b/compose/config/errors.py index 060564fc4..ac1d3ac19 100644 --- a/compose/config/errors.py +++ b/compose/config/errors.py @@ -49,10 +49,7 @@ class ComposeFileNotFound(ConfigurationError): 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) + super(DuplicateOverrideFileFound, self).__init__( + "Multiple override files found: {}. You may only use a single " + "override file.".format(", ".join(override_filenames)) + )