mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
Use custom container name in logs. Fixes #1851
Signed-off-by: Karol Duleba <mr.fuxi@gmail.com>
This commit is contained in:
parent
9da2bf3973
commit
d83d6306c9
@ -6,6 +6,7 @@ from functools import reduce
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from .const import LABEL_CONTAINER_NUMBER
|
from .const import LABEL_CONTAINER_NUMBER
|
||||||
|
from .const import LABEL_PROJECT
|
||||||
from .const import LABEL_SERVICE
|
from .const import LABEL_SERVICE
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +71,12 @@ class Container(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name_without_project(self):
|
def name_without_project(self):
|
||||||
|
project = self.labels.get(LABEL_PROJECT)
|
||||||
|
|
||||||
|
if self.name.startswith('{0}_{1}'.format(project, self.service)):
|
||||||
return '{0}_{1}'.format(self.service, self.number)
|
return '{0}_{1}'.format(self.service, self.number)
|
||||||
|
else:
|
||||||
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def number(self):
|
def number(self):
|
||||||
|
@ -83,9 +83,15 @@ class ContainerTest(unittest.TestCase):
|
|||||||
self.assertEqual(container.name, "composetest_db_1")
|
self.assertEqual(container.name, "composetest_db_1")
|
||||||
|
|
||||||
def test_name_without_project(self):
|
def test_name_without_project(self):
|
||||||
|
self.container_dict['Name'] = "/composetest_web_7"
|
||||||
container = Container(None, self.container_dict, has_been_inspected=True)
|
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||||
self.assertEqual(container.name_without_project, "web_7")
|
self.assertEqual(container.name_without_project, "web_7")
|
||||||
|
|
||||||
|
def test_name_without_project_custom_container_name(self):
|
||||||
|
self.container_dict['Name'] = "/custom_name_of_container"
|
||||||
|
container = Container(None, self.container_dict, has_been_inspected=True)
|
||||||
|
self.assertEqual(container.name_without_project, "custom_name_of_container")
|
||||||
|
|
||||||
def test_inspect_if_not_inspected(self):
|
def test_inspect_if_not_inspected(self):
|
||||||
mock_client = mock.create_autospec(docker.Client)
|
mock_client = mock.create_autospec(docker.Client)
|
||||||
container = Container(mock_client, dict(Id="the_id"))
|
container = Container(mock_client, dict(Id="the_id"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user