mirror of https://github.com/docker/compose.git
Show a warning when engine is in swarm mode
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
619bf4c4df
commit
2c9e46f60f
|
@ -369,6 +369,8 @@ class Project(object):
|
|||
detached=False,
|
||||
remove_orphans=False):
|
||||
|
||||
warn_for_swarm_mode(self.client)
|
||||
|
||||
self.initialize()
|
||||
self.find_orphan_containers(remove_orphans)
|
||||
|
||||
|
@ -533,6 +535,20 @@ def get_volumes_from(project, service_dict):
|
|||
return [build_volume_from(vf) for vf in volumes_from]
|
||||
|
||||
|
||||
def warn_for_swarm_mode(client):
|
||||
info = client.info()
|
||||
if info.get('Swarm', {}).get('LocalNodeState') == 'active':
|
||||
log.warn(
|
||||
"The Docker Engine you're using is running in swarm mode.\n\n"
|
||||
"Compose does not use swarm mode to deploy services to multiple nodes in a swarm. "
|
||||
"All containers will be scheduled on the current node.\n\n"
|
||||
"To deploy your application across the swarm, "
|
||||
"use the bundle feature of the Docker experimental build.\n\n"
|
||||
"More info:\n"
|
||||
"https://github.com/docker/docker/tree/master/experimental\n"
|
||||
)
|
||||
|
||||
|
||||
class NoSuchService(Exception):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
|
|
@ -510,3 +510,35 @@ class ProjectTest(unittest.TestCase):
|
|||
|
||||
project.down(ImageType.all, True)
|
||||
self.mock_client.remove_image.assert_called_once_with("busybox:latest")
|
||||
|
||||
def test_warning_in_swarm_mode(self):
|
||||
self.mock_client.info.return_value = {'Swarm': {'LocalNodeState': 'active'}}
|
||||
project = Project('composetest', [], self.mock_client)
|
||||
|
||||
with mock.patch('compose.project.log') as fake_log:
|
||||
project.up()
|
||||
assert fake_log.warn.call_count == 1
|
||||
|
||||
def test_no_warning_on_stop(self):
|
||||
self.mock_client.info.return_value = {'Swarm': {'LocalNodeState': 'active'}}
|
||||
project = Project('composetest', [], self.mock_client)
|
||||
|
||||
with mock.patch('compose.project.log') as fake_log:
|
||||
project.stop()
|
||||
assert fake_log.warn.call_count == 0
|
||||
|
||||
def test_no_warning_in_normal_mode(self):
|
||||
self.mock_client.info.return_value = {'Swarm': {'LocalNodeState': 'inactive'}}
|
||||
project = Project('composetest', [], self.mock_client)
|
||||
|
||||
with mock.patch('compose.project.log') as fake_log:
|
||||
project.up()
|
||||
assert fake_log.warn.call_count == 0
|
||||
|
||||
def test_no_warning_with_no_swarm_info(self):
|
||||
self.mock_client.info.return_value = {}
|
||||
project = Project('composetest', [], self.mock_client)
|
||||
|
||||
with mock.patch('compose.project.log') as fake_log:
|
||||
project.up()
|
||||
assert fake_log.warn.call_count == 0
|
||||
|
|
Loading…
Reference in New Issue