Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/plugin-sy…
Browse files Browse the repository at this point in the history
…stem
  • Loading branch information
GM-Alex committed Sep 8, 2016
2 parents 688e275 + 3dec600 commit a0c9988
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 4 deletions.
4 changes: 3 additions & 1 deletion compose/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import six

from . import errors
from . import verbose_proxy
from .. import config
from ..config.environment import Environment
Expand Down Expand Up @@ -110,7 +111,8 @@ def get_project(project_dir, config_path=None, project_name=None, verbose=False,
host=host, environment=environment
)

return Project.from_config(project_name, config_data, client)
with errors.handle_connection_errors(client):
return Project.from_config(project_name, config_data, client)


def get_project_name(working_dir, project_name=None, environment=None):
Expand Down
7 changes: 4 additions & 3 deletions compose/cli/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
from ..const import HTTP_TIMEOUT
from .errors import UserError
from .utils import generate_user_agent
from .utils import unquote_path

log = logging.getLogger(__name__)


def tls_config_from_options(options):
tls = options.get('--tls', False)
ca_cert = options.get('--tlscacert')
cert = options.get('--tlscert')
key = options.get('--tlskey')
ca_cert = unquote_path(options.get('--tlscacert'))
cert = unquote_path(options.get('--tlscert'))
key = unquote_path(options.get('--tlskey'))
verify = options.get('--tlsverify')
skip_hostname_check = options.get('--skip-hostname-check', False)

Expand Down
8 changes: 8 additions & 0 deletions compose/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ def get_user_home():

def get_plugin_dir():
return os.path.join(get_user_home(), HOME_DIR, PLUGIN_DIR)


def unquote_path(s):
if not s:
return s
if s[0] == '"' and s[-1] == '"':
return s[1:-1]
return s
4 changes: 4 additions & 0 deletions docs/swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ parent="workw_compose"

# Using Compose with Swarm

> **Note:** “Swarm” here refers to [Docker Swarm](/swarm/overview.md), a product separate from Docker Engine. It does _not_ refer to [swarm mode](/engine/swarm), which is a built-in feature of Docker Engine introduced in version 1.12.
>
> Integration between Compose and swarm mode is at the experimental stage. See [Docker Stacks and Bundles](bundles.md) for details.
Docker Compose and [Docker Swarm](/swarm/overview.md) aim to have full integration, meaning
you can point a Compose app at a Swarm cluster and have it all just work as if
you were using a single Docker host.
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def test_shorthand_host_opt(self):
returncode=0
)

def test_host_not_reachable(self):
result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
assert "Couldn't connect to Docker daemon" in result.stderr

def test_host_not_reachable_volumes_from_container(self):
self.base_dir = 'tests/fixtures/volumes-from-container'

container = self.client.create_container('busybox', 'true', name='composetest_data_container')
self.addCleanup(self.client.remove_container, container)

result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
assert "Couldn't connect to Docker daemon" in result.stderr

def test_config_list_services(self):
self.base_dir = 'tests/fixtures/v2-full'
result = self.dispatch(['config', '--services'])
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/volumes-from-container/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "2"
services:
test:
image: busybox
volumes_from: ["container:composetest_data_container"]
13 changes: 13 additions & 0 deletions tests/unit/cli/docker_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,16 @@ def test_assert_hostname_explicit_skip(self):
result = tls_config_from_options(options)
assert isinstance(result, docker.tls.TLSConfig)
assert result.assert_hostname is False

def test_tls_client_and_ca_quoted_paths(self):
options = {
'--tlscacert': '"{0}"'.format(self.ca_cert),
'--tlscert': '"{0}"'.format(self.client_cert),
'--tlskey': '"{0}"'.format(self.key),
'--tlsverify': True
}
result = tls_config_from_options(options)
assert isinstance(result, docker.tls.TLSConfig)
assert result.cert == (self.client_cert, self.key)
assert result.ca_cert == self.ca_cert
assert result.verify is True
23 changes: 23 additions & 0 deletions tests/unit/cli/utils_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import unittest

from compose.cli.utils import unquote_path


class UnquotePathTest(unittest.TestCase):
def test_no_quotes(self):
assert unquote_path('hello') == 'hello'

def test_simple_quotes(self):
assert unquote_path('"hello"') == 'hello'

def test_uneven_quotes(self):
assert unquote_path('"hello') == '"hello'
assert unquote_path('hello"') == 'hello"'

def test_nested_quotes(self):
assert unquote_path('""hello""') == '"hello"'
assert unquote_path('"hel"lo"') == 'hel"lo'
assert unquote_path('"hello""') == 'hello"'

0 comments on commit a0c9988

Please sign in to comment.