mirror of
https://github.com/docker/compose.git
synced 2025-10-25 09:13:50 +02:00
Refactors config validation of a service to use a ServiceConfig data object. Instead of passing around a bunch of related scalars, we can use the ServiceConfig object as a parameter to most of the service validation functions. This allows for a fix to the config schema, where the name is a field in the schema, but not actually in the configuration. My passing the name around as part of the ServiceConfig object, we don't need to add it to the config options. Fixes #2299 validate_against_service_schema() is moved from a conditional branch in ServiceExtendsResolver() to happen as one of the last steps after all configuration is merged. This schema only contains constraints which only need to be true at the very end of merging. Signed-off-by: Daniel Nephin <dnephin@docker.com>
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import unicode_literals
|
|
|
|
from docker import errors
|
|
from docker.utils import version_lt
|
|
from pytest import skip
|
|
|
|
from .. import unittest
|
|
from compose.cli.docker_client import docker_client
|
|
from compose.config.config import process_service
|
|
from compose.config.config import resolve_environment
|
|
from compose.config.config import ServiceConfig
|
|
from compose.const import LABEL_PROJECT
|
|
from compose.progress_stream import stream_output
|
|
from compose.service import Service
|
|
|
|
|
|
def pull_busybox(client):
|
|
try:
|
|
client.inspect_image('busybox:latest')
|
|
except errors.APIError:
|
|
client.pull('busybox:latest', stream=False)
|
|
|
|
|
|
class DockerClientTestCase(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.client = docker_client()
|
|
|
|
def tearDown(self):
|
|
for c in self.client.containers(
|
|
all=True,
|
|
filters={'label': '%s=composetest' % LABEL_PROJECT}):
|
|
self.client.kill(c['Id'])
|
|
self.client.remove_container(c['Id'])
|
|
for i in self.client.images(
|
|
filters={'label': 'com.docker.compose.test_image'}):
|
|
self.client.remove_image(i)
|
|
|
|
def create_service(self, name, **kwargs):
|
|
if 'image' not in kwargs and 'build' not in kwargs:
|
|
kwargs['image'] = 'busybox:latest'
|
|
|
|
if 'command' not in kwargs:
|
|
kwargs['command'] = ["top"]
|
|
|
|
service_config = ServiceConfig('.', None, name, kwargs)
|
|
options = process_service(service_config)
|
|
options['environment'] = resolve_environment('.', kwargs)
|
|
labels = options.setdefault('labels', {})
|
|
labels['com.docker.compose.test-name'] = self.id()
|
|
|
|
return Service(name, client=self.client, project='composetest', **options)
|
|
|
|
def check_build(self, *args, **kwargs):
|
|
kwargs.setdefault('rm', True)
|
|
build_output = self.client.build(*args, **kwargs)
|
|
stream_output(build_output, open('/dev/null', 'w'))
|
|
|
|
def require_api_version(self, minimum):
|
|
api_version = self.client.version()['ApiVersion']
|
|
if version_lt(api_version, minimum):
|
|
skip("API version is too low ({} < {})".format(api_version, minimum))
|