mirror of https://github.com/docker/compose.git
Support a default docker-compose.override.yml for overrides
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
fe5daf860d
commit
39ae85db8a
|
@ -77,6 +77,7 @@ SUPPORTED_FILENAMES = [
|
||||||
'fig.yaml',
|
'fig.yaml',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
DEFAULT_OVERRIDE_FILENAME = 'docker-compose.override.yml'
|
||||||
|
|
||||||
PATH_START_CHARS = [
|
PATH_START_CHARS = [
|
||||||
'/',
|
'/',
|
||||||
|
@ -102,16 +103,16 @@ def find(base_dir, filenames):
|
||||||
if filenames:
|
if filenames:
|
||||||
filenames = [os.path.join(base_dir, f) for f in filenames]
|
filenames = [os.path.join(base_dir, f) for f in filenames]
|
||||||
else:
|
else:
|
||||||
filenames = get_default_config_path(base_dir)
|
filenames = get_default_config_files(base_dir)
|
||||||
return ConfigDetails(
|
return ConfigDetails(
|
||||||
os.path.dirname(filenames[0]),
|
os.path.dirname(filenames[0]),
|
||||||
[ConfigFile(f, load_yaml(f)) for f in filenames])
|
[ConfigFile(f, load_yaml(f)) for f in filenames])
|
||||||
|
|
||||||
|
|
||||||
def get_default_config_path(base_dir):
|
def get_default_config_files(base_dir):
|
||||||
(candidates, path) = find_candidates_in_parent_dirs(SUPPORTED_FILENAMES, base_dir)
|
(candidates, path) = find_candidates_in_parent_dirs(SUPPORTED_FILENAMES, base_dir)
|
||||||
|
|
||||||
if len(candidates) == 0:
|
if not candidates:
|
||||||
raise ComposeFileNotFound(SUPPORTED_FILENAMES)
|
raise ComposeFileNotFound(SUPPORTED_FILENAMES)
|
||||||
|
|
||||||
winner = candidates[0]
|
winner = candidates[0]
|
||||||
|
@ -129,7 +130,12 @@ def get_default_config_path(base_dir):
|
||||||
log.warn("%s is deprecated and will not be supported in future. "
|
log.warn("%s is deprecated and will not be supported in future. "
|
||||||
"Please rename your config file to docker-compose.yml\n" % winner)
|
"Please rename your config file to docker-compose.yml\n" % winner)
|
||||||
|
|
||||||
return os.path.join(path, winner)
|
return [os.path.join(path, winner)] + get_default_override_file(path)
|
||||||
|
|
||||||
|
|
||||||
|
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 []
|
||||||
|
|
||||||
|
|
||||||
def find_candidates_in_parent_dirs(filenames, path):
|
def find_candidates_in_parent_dirs(filenames, path):
|
||||||
|
@ -143,7 +149,7 @@ def find_candidates_in_parent_dirs(filenames, path):
|
||||||
candidates = [filename for filename in filenames
|
candidates = [filename for filename in filenames
|
||||||
if os.path.exists(os.path.join(path, filename))]
|
if os.path.exists(os.path.join(path, filename))]
|
||||||
|
|
||||||
if len(candidates) == 0:
|
if not candidates:
|
||||||
parent_dir = os.path.join(path, '..')
|
parent_dir = os.path.join(path, '..')
|
||||||
if os.path.abspath(parent_dir) != os.path.abspath(path):
|
if os.path.abspath(parent_dir) != os.path.abspath(path):
|
||||||
return find_candidates_in_parent_dirs(filenames, parent_dir)
|
return find_candidates_in_parent_dirs(filenames, parent_dir)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
web:
|
||||||
|
command: "top"
|
||||||
|
|
||||||
|
db:
|
||||||
|
command: "top"
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
web:
|
||||||
|
image: busybox:latest
|
||||||
|
command: "sleep 200"
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: busybox:latest
|
||||||
|
command: "sleep 200"
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
web:
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
- other
|
||||||
|
|
||||||
|
other:
|
||||||
|
image: busybox:latest
|
||||||
|
command: "top"
|
|
@ -549,7 +549,6 @@ class CLITestCase(DockerClientTestCase):
|
||||||
self.assertEqual(get_port(3002), "0.0.0.0:49153")
|
self.assertEqual(get_port(3002), "0.0.0.0:49153")
|
||||||
|
|
||||||
def test_port_with_scale(self):
|
def test_port_with_scale(self):
|
||||||
|
|
||||||
self.command.base_dir = 'tests/fixtures/ports-composefile-scale'
|
self.command.base_dir = 'tests/fixtures/ports-composefile-scale'
|
||||||
self.command.dispatch(['scale', 'simple=2'], None)
|
self.command.dispatch(['scale', 'simple=2'], None)
|
||||||
containers = sorted(
|
containers = sorted(
|
||||||
|
@ -593,6 +592,44 @@ class CLITestCase(DockerClientTestCase):
|
||||||
self.assertTrue(components[-2:] == ['home-dir', 'my-volume'],
|
self.assertTrue(components[-2:] == ['home-dir', 'my-volume'],
|
||||||
msg="Last two components differ: %s, %s" % (actual_host_path, expected_host_path))
|
msg="Last two components differ: %s, %s" % (actual_host_path, expected_host_path))
|
||||||
|
|
||||||
|
def test_up_with_default_override_file(self):
|
||||||
|
self.command.base_dir = 'tests/fixtures/override-files'
|
||||||
|
self.command.dispatch(['up', '-d'], None)
|
||||||
|
|
||||||
|
containers = self.project.containers()
|
||||||
|
self.assertEqual(len(containers), 2)
|
||||||
|
|
||||||
|
web, db = containers
|
||||||
|
self.assertEqual(web.human_readable_command, 'top')
|
||||||
|
self.assertEqual(db.human_readable_command, 'top')
|
||||||
|
|
||||||
|
def test_up_with_multiple_files(self):
|
||||||
|
self.command.base_dir = 'tests/fixtures/override-files'
|
||||||
|
config_paths = [
|
||||||
|
'docker-compose.yml',
|
||||||
|
'docker-compose.override.yml',
|
||||||
|
'extra.yml',
|
||||||
|
|
||||||
|
]
|
||||||
|
self._project = get_project(self.command.base_dir, config_paths)
|
||||||
|
self.command.dispatch(
|
||||||
|
[
|
||||||
|
'-f', config_paths[0],
|
||||||
|
'-f', config_paths[1],
|
||||||
|
'-f', config_paths[2],
|
||||||
|
'up', '-d',
|
||||||
|
],
|
||||||
|
None)
|
||||||
|
|
||||||
|
containers = self.project.containers()
|
||||||
|
self.assertEqual(len(containers), 3)
|
||||||
|
|
||||||
|
web, other, db = containers
|
||||||
|
self.assertEqual(web.human_readable_command, 'top')
|
||||||
|
self.assertTrue({'db', 'other'} <= set(web.links()))
|
||||||
|
self.assertEqual(db.human_readable_command, 'top')
|
||||||
|
self.assertEqual(other.human_readable_command, 'top')
|
||||||
|
|
||||||
def test_up_with_extends(self):
|
def test_up_with_extends(self):
|
||||||
self.command.base_dir = 'tests/fixtures/extends'
|
self.command.base_dir = 'tests/fixtures/extends'
|
||||||
self.command.dispatch(['up', '-d'], None)
|
self.command.dispatch(['up', '-d'], None)
|
||||||
|
|
|
@ -1213,6 +1213,7 @@ def get_config_filename_for_files(filenames, subdir=None):
|
||||||
base_dir = tempfile.mkdtemp(dir=project_dir)
|
base_dir = tempfile.mkdtemp(dir=project_dir)
|
||||||
else:
|
else:
|
||||||
base_dir = project_dir
|
base_dir = project_dir
|
||||||
return os.path.basename(config.get_config_path(base_dir))
|
filename, = config.get_default_config_files(base_dir)
|
||||||
|
return os.path.basename(filename)
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(project_dir)
|
shutil.rmtree(project_dir)
|
||||||
|
|
Loading…
Reference in New Issue