Merge pull request #4859 from shin-/eliat123-4771-fix-allow-override-yaml-extension

Fix: allow override yaml extension
This commit is contained in:
Joffrey F 2017-05-23 15:08:00 -07:00 committed by GitHub
commit 98419ba2a2
8 changed files with 69 additions and 4 deletions

View File

@ -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
@ -128,7 +129,7 @@ SUPPORTED_FILENAMES = [
'docker-compose.yaml', '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__) log = logging.getLogger(__name__)
@ -292,8 +293,12 @@ def get_default_config_files(base_dir):
def get_default_override_file(path): def get_default_override_file(path):
override_filename = os.path.join(path, DEFAULT_OVERRIDE_FILENAME) override_files_in_path = [os.path.join(path, override_filename) for override_filename
return [override_filename] if os.path.exists(override_filename) else [] 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): def find_candidates_in_parent_dirs(filenames, path):

View File

@ -44,3 +44,12 @@ 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
super(DuplicateOverrideFileFound, self).__init__(
"Multiple override files found: {}. You may only use a single "
"override file.".format(", ".join(override_filenames))
)

View File

@ -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')
@ -2149,3 +2149,25 @@ class CLITestCase(DockerClientTestCase):
assert 'busybox' in result.stdout assert 'busybox' in result.stdout
assert 'multiplecomposefiles_another_1' in result.stdout assert 'multiplecomposefiles_another_1' in result.stdout
assert 'multiplecomposefiles_simple_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')
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

View File

@ -0,0 +1,3 @@
db:
command: "top"

View File

@ -0,0 +1,3 @@
db:
command: "sleep 300"

View File

@ -0,0 +1,10 @@
web:
image: busybox:latest
command: "sleep 100"
links:
- db
db:
image: busybox:latest
command: "sleep 200"

View File

@ -0,0 +1,3 @@
db:
command: "top"

View File

@ -0,0 +1,10 @@
web:
image: busybox:latest
command: "sleep 100"
links:
- db
db:
image: busybox:latest
command: "sleep 200"