From 187f48e33888941367776e82e934aa9ee2db56f1 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 31 Oct 2018 13:55:20 -0700 Subject: [PATCH 1/3] Don't attempt to truncate a None value in Container.slug Signed-off-by: Joffrey F --- compose/container.py | 2 ++ tests/unit/container_test.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compose/container.py b/compose/container.py index 3ee45c8f3..026306866 100644 --- a/compose/container.py +++ b/compose/container.py @@ -96,6 +96,8 @@ class Container(object): @property def slug(self): + if not self.full_slug: + return None return truncate_id(self.full_slug) @property diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py index 64c9cc344..66c6c1578 100644 --- a/tests/unit/container_test.py +++ b/tests/unit/container_test.py @@ -5,6 +5,7 @@ import docker from .. import mock from .. import unittest +from compose.const import LABEL_SLUG from compose.container import Container from compose.container import get_container_name @@ -87,7 +88,7 @@ class ContainerTest(unittest.TestCase): assert container.name == "composetest_db_1" def test_name_without_project(self): - self.container_dict['Name'] = "/composetest_web_7" + self.container_dict['Name'] = "/composetest_web_7_092cd63296fd" container = Container(None, self.container_dict, has_been_inspected=True) assert container.name_without_project == "web_7_092cd63296fd" @@ -96,6 +97,12 @@ class ContainerTest(unittest.TestCase): container = Container(None, self.container_dict, has_been_inspected=True) assert container.name_without_project == "custom_name_of_container" + def test_name_without_project_noslug(self): + self.container_dict['Name'] = "/composetest_web_7" + del self.container_dict['Config']['Labels'][LABEL_SLUG] + container = Container(None, self.container_dict, has_been_inspected=True) + assert container.name_without_project == 'web_7' + def test_inspect_if_not_inspected(self): mock_client = mock.create_autospec(docker.APIClient) container = Container(mock_client, dict(Id="the_id")) From 176a4efaf2dc718e43afeaf01c69679b07654d42 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 31 Oct 2018 14:24:35 -0700 Subject: [PATCH 2/3] Impose consistent behavior across command for --project-directory flag Signed-off-by: Joffrey F --- compose/cli/command.py | 10 ++++++---- compose/cli/main.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compose/cli/command.py b/compose/cli/command.py index 8a32a93a2..339a65c53 100644 --- a/compose/cli/command.py +++ b/compose/cli/command.py @@ -23,7 +23,8 @@ log = logging.getLogger(__name__) def project_from_options(project_dir, options): - environment = Environment.from_env_file(project_dir) + override_dir = options.get('--project-directory') + environment = Environment.from_env_file(override_dir or project_dir) set_parallel_limit(environment) host = options.get('--host') @@ -37,7 +38,7 @@ def project_from_options(project_dir, options): host=host, tls_config=tls_config_from_options(options, environment), environment=environment, - override_dir=options.get('--project-directory'), + override_dir=override_dir, compatibility=options.get('--compatibility'), ) @@ -59,12 +60,13 @@ def set_parallel_limit(environment): def get_config_from_options(base_dir, options): - environment = Environment.from_env_file(base_dir) + override_dir = options.get('--project-directory') + environment = Environment.from_env_file(override_dir or base_dir) config_path = get_config_path_from_options( base_dir, options, environment ) return config.load( - config.find(base_dir, config_path, environment), + config.find(base_dir, config_path, environment, override_dir), options.get('--compatibility') ) diff --git a/compose/cli/main.py b/compose/cli/main.py index f2e76c1ad..610308f20 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -306,7 +306,7 @@ class TopLevelCommand(object): -o, --output PATH Path to write the bundle file to. Defaults to ".dab". """ - compose_config = get_config_from_options(self.project_dir, self.toplevel_options) + compose_config = get_config_from_options('.', self.toplevel_options) output = options["--output"] if not output: @@ -336,7 +336,7 @@ class TopLevelCommand(object): or use the wildcard symbol to display all services """ - compose_config = get_config_from_options(self.project_dir, self.toplevel_options) + compose_config = get_config_from_options('.', self.toplevel_options) image_digests = None if options['--resolve-image-digests']: From b02f1306842d603774a19bf925c5719425f82b5b Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 31 Oct 2018 14:49:00 -0700 Subject: [PATCH 3/3] "Bump 1.23.1" Signed-off-by: Joffrey F --- CHANGELOG.md | 11 +++++++++++ compose/__init__.py | 2 +- script/run/run.sh | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26fd3f883..66af5ecd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ Change log ========== +1.23.1 (2018-11-01) +------------------- + +### Bugfixes + +- Fixed a bug where working with containers created with a previous (< 1.23.0) + version of Compose would cause unexpected crashes + +- Fixed an issue where the behavior of the `--project-directory` flag would + vary depending on which subcommand was being used. + 1.23.0 (2018-10-30) ------------------- diff --git a/compose/__init__.py b/compose/__init__.py index b9088474f..7431dd0c0 100644 --- a/compose/__init__.py +++ b/compose/__init__.py @@ -1,4 +1,4 @@ from __future__ import absolute_import from __future__ import unicode_literals -__version__ = '1.23.0' +__version__ = '1.23.1' diff --git a/script/run/run.sh b/script/run/run.sh index d82b54f0f..4ce09e992 100755 --- a/script/run/run.sh +++ b/script/run/run.sh @@ -15,7 +15,7 @@ set -e -VERSION="1.23.0" +VERSION="1.23.1" IMAGE="docker/compose:$VERSION"