From 5126649de4b0f3fc62036027fcb835d69767598d Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Tue, 4 Feb 2014 14:42:55 -0800 Subject: [PATCH 1/3] Friendlier connection error for docker-osx users --- fig/cli/command.py | 7 +++++-- fig/cli/utils.py | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fig/cli/command.py b/fig/cli/command.py index c60020d75..370423985 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -11,7 +11,7 @@ import yaml from ..project import Project from .docopt_command import DocoptCommand from .formatter import Formatter -from .utils import cached_property, docker_url +from .utils import cached_property, docker_url, call_silently from .errors import UserError log = logging.getLogger(__name__) @@ -23,7 +23,10 @@ class Command(DocoptCommand): try: super(Command, self).dispatch(*args, **kwargs) except ConnectionError: - raise UserError(""" + if call_silently(['which', 'docker-osx']) == 0: + raise UserError("Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.") + else: + raise UserError(""" Couldn't connect to Docker daemon at %s - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. diff --git a/fig/cli/utils.py b/fig/cli/utils.py index 3116df98b..994923754 100644 --- a/fig/cli/utils.py +++ b/fig/cli/utils.py @@ -4,6 +4,7 @@ from __future__ import division import datetime import os import socket +import subprocess from .errors import UserError @@ -108,3 +109,11 @@ def split_buffer(reader, separator): if len(buffered) > 0: yield buffered + + +def call_silently(*args, **kwargs): + """ + Like subprocess.call(), but redirects stdout and stderr to /dev/null. + """ + with open(os.devnull, 'w') as shutup: + return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs) From 2bac1c10b0569bdcff76e92af162c0760ff36622 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Tue, 4 Feb 2014 15:19:50 -0800 Subject: [PATCH 2/3] Show installation instructions if it looks like Docker isn't installed --- fig/cli/command.py | 23 +++++++++++++++++++++-- fig/cli/utils.py | 9 +++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/fig/cli/command.py b/fig/cli/command.py index 370423985..abf087628 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -11,7 +11,7 @@ import yaml from ..project import Project from .docopt_command import DocoptCommand from .formatter import Formatter -from .utils import cached_property, docker_url, call_silently +from .utils import cached_property, docker_url, call_silently, is_mac, is_ubuntu from .errors import UserError log = logging.getLogger(__name__) @@ -23,7 +23,26 @@ class Command(DocoptCommand): try: super(Command, self).dispatch(*args, **kwargs) except ConnectionError: - if call_silently(['which', 'docker-osx']) == 0: + if call_silently(['which', 'docker']) != 0: + if is_mac(): + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install docker-osx: + +https://github.com/noplay/docker-osx +""") + elif is_ubuntu(): + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install Docker: + +http://docs.docker.io/en/latest/installation/ubuntulinux/ +""") + else: + raise UserError(""" +Couldn't connect to Docker daemon. You might need to install Docker: + +http://docs.docker.io/en/latest/installation/ +""") + elif call_silently(['which', 'docker-osx']) == 0: raise UserError("Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.") else: raise UserError(""" diff --git a/fig/cli/utils.py b/fig/cli/utils.py index 994923754..8a26e7b8b 100644 --- a/fig/cli/utils.py +++ b/fig/cli/utils.py @@ -5,6 +5,7 @@ import datetime import os import socket import subprocess +import platform from .errors import UserError @@ -117,3 +118,11 @@ def call_silently(*args, **kwargs): """ with open(os.devnull, 'w') as shutup: return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs) + + +def is_mac(): + return platform.system() == 'Darwin' + + +def is_ubuntu(): + return platform.system() == 'Linux' From 2b8949440561583431613339f9390413e80519f0 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Tue, 4 Feb 2014 15:31:05 -0800 Subject: [PATCH 3/3] Fix Ubuntu check - forgot to actually inspect the distro --- fig/cli/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fig/cli/utils.py b/fig/cli/utils.py index 8a26e7b8b..64b2ea383 100644 --- a/fig/cli/utils.py +++ b/fig/cli/utils.py @@ -125,4 +125,4 @@ def is_mac(): def is_ubuntu(): - return platform.system() == 'Linux' + return platform.system() == 'Linux' and platform.linux_distribution()[0] == 'Ubuntu'