Merge pull request #2713 from aanand/links-v2

Support links in v2 files
This commit is contained in:
Aanand Prasad 2016-01-21 17:08:05 +00:00
commit 013c5ea3f9
7 changed files with 21 additions and 30 deletions

View File

@ -88,6 +88,7 @@
"image": {"type": "string"},
"ipc": {"type": "string"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"logging": {
"type": "object",

View File

@ -78,12 +78,11 @@ class Project(object):
if use_networking:
networks = get_networks(service_dict, all_networks)
net = Net(networks[0]) if networks else Net("none")
links = []
else:
networks = []
net = project.get_net(service_dict)
links = project.get_links(service_dict)
links = project.get_links(service_dict)
volumes_from = get_volumes_from(project, service_dict)
project.services.append(

View File

@ -426,10 +426,11 @@ class Service(object):
def connect_container_to_networks(self, container):
for network in self.networks:
log.debug('Connecting "{}" to "{}"'.format(container.name, network))
self.client.connect_container_to_network(
container.id, network,
aliases=[self.name])
aliases=[self.name],
links=self._get_links(False),
)
def remove_duplicate_containers(self, timeout=DEFAULT_TIMEOUT):
for c in self.duplicate_containers():
@ -500,9 +501,6 @@ class Service(object):
return 1 if not numbers else max(numbers) + 1
def _get_links(self, link_to_self):
if self.use_networking:
return []
links = {}
for service, link_name in self.links:
@ -645,7 +643,10 @@ class Service(object):
def _get_container_networking_config(self):
return self.client.create_networking_config({
network_name: self.client.create_endpoint_config(aliases=[self.name])
network_name: self.client.create_endpoint_config(
aliases=[self.name],
links=self._get_links(False),
)
for network_name in self.networks
if network_name not in ['host', 'bridge']
})

View File

@ -41,6 +41,9 @@ Get-ChildItem -Recurse -Include *.pyc | foreach ($_) { Remove-Item $_.FullName }
# Create virtualenv
virtualenv .\venv
# pip and pyinstaller generate lots of warnings, so we need to ignore them
$ErrorActionPreference = "Continue"
# Install dependencies
.\venv\Scripts\pip install pypiwin32==219
.\venv\Scripts\pip install -r requirements.txt
@ -50,8 +53,6 @@ virtualenv .\venv
git rev-parse --short HEAD | out-file -encoding ASCII compose\GITSHA
# Build binary
# pyinstaller has lots of warnings, so we need to run with ErrorAction = Continue
$ErrorActionPreference = "Continue"
.\venv\Scripts\pyinstaller .\docker-compose.spec
$ErrorActionPreference = "Stop"

View File

@ -461,6 +461,10 @@ class CLITestCase(DockerClientTestCase):
app_container = self.project.get_service('app').containers()[0]
db_container = self.project.get_service('db').containers()[0]
for net_name in [front_name, back_name]:
links = app_container.get('NetworkSettings.Networks.{}.Links'.format(net_name))
assert '{}:database'.format(db_container.name) in links
# db and app joined the back network
assert sorted(back_network['Containers']) == sorted([db_container.id, app_container.id])
@ -474,6 +478,9 @@ class CLITestCase(DockerClientTestCase):
# app can see db
assert self.lookup(app_container, "db")
# app has aliased db to "database"
assert self.lookup(app_container, "database")
@v2_only()
def test_up_missing_network(self):
self.base_dir = 'tests/fixtures/networks'
@ -566,18 +573,6 @@ class CLITestCase(DockerClientTestCase):
for name in ['bar', 'foo']
]
@v2_only()
def test_up_with_links_is_invalid(self):
self.base_dir = 'tests/fixtures/v2-simple'
result = self.dispatch(
['-f', 'links-invalid.yml', 'up', '-d'],
returncode=1)
# TODO: fix validation error messages for v2 files
# assert "Unsupported config option for service 'simple': 'links'" in result.stderr
assert "Unsupported config option" in result.stderr
def test_up_with_links_v1(self):
self.base_dir = 'tests/fixtures/links-composefile'
self.dispatch(['up', '-d', 'web'], None)

View File

@ -9,6 +9,8 @@ services:
image: busybox
command: top
networks: ["front", "back"]
links:
- "db:database"
db:
image: busybox
command: top

View File

@ -536,14 +536,6 @@ class ServiceTest(unittest.TestCase):
ports=["127.0.0.1:1000-2000:2000-3000"])
self.assertEqual(service.specifies_host_port(), True)
def test_get_links_with_networking(self):
service = Service(
'foo',
image='foo',
links=[(Service('one'), 'one')],
use_networking=True)
self.assertEqual(service._get_links(link_to_self=True), [])
def test_image_name_from_config(self):
image_name = 'example/web:latest'
service = Service('foo', image=image_name)