mirror of https://github.com/docker/compose.git
Refactor API version switching logic
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
a027a0079c
commit
9e17cff0ef
|
@ -13,6 +13,7 @@ from requests.exceptions import SSLError
|
||||||
from . import errors
|
from . import errors
|
||||||
from . import verbose_proxy
|
from . import verbose_proxy
|
||||||
from .. import config
|
from .. import config
|
||||||
|
from ..const import API_VERSIONS
|
||||||
from ..project import Project
|
from ..project import Project
|
||||||
from .docker_client import docker_client
|
from .docker_client import docker_client
|
||||||
from .utils import call_silently
|
from .utils import call_silently
|
||||||
|
@ -77,7 +78,10 @@ def get_project(base_dir, config_path=None, project_name=None, verbose=False):
|
||||||
config_details = config.find(base_dir, config_path)
|
config_details = config.find(base_dir, config_path)
|
||||||
project_name = get_project_name(config_details.working_dir, project_name)
|
project_name = get_project_name(config_details.working_dir, project_name)
|
||||||
config_data = config.load(config_details)
|
config_data = config.load(config_details)
|
||||||
api_version = '1.21' if config_data.version < 2 else None
|
|
||||||
|
api_version = os.environ.get(
|
||||||
|
'COMPOSE_API_VERSION',
|
||||||
|
API_VERSIONS[config_data.version])
|
||||||
client = get_client(verbose=verbose, version=api_version)
|
client = get_client(verbose=verbose, version=api_version)
|
||||||
|
|
||||||
return Project.from_config(project_name, config_data, client)
|
return Project.from_config(project_name, config_data, client)
|
||||||
|
|
|
@ -11,8 +11,6 @@ from ..const import HTTP_TIMEOUT
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_API_VERSION = '1.21'
|
|
||||||
|
|
||||||
|
|
||||||
def docker_client(version=None):
|
def docker_client(version=None):
|
||||||
"""
|
"""
|
||||||
|
@ -23,8 +21,7 @@ def docker_client(version=None):
|
||||||
log.warn('The DOCKER_CLIENT_TIMEOUT environment variable is deprecated. Please use COMPOSE_HTTP_TIMEOUT instead.')
|
log.warn('The DOCKER_CLIENT_TIMEOUT environment variable is deprecated. Please use COMPOSE_HTTP_TIMEOUT instead.')
|
||||||
|
|
||||||
kwargs = kwargs_from_env(assert_hostname=False)
|
kwargs = kwargs_from_env(assert_hostname=False)
|
||||||
kwargs['version'] = version or os.environ.get(
|
if version:
|
||||||
'COMPOSE_API_VERSION',
|
kwargs['version'] = version
|
||||||
DEFAULT_API_VERSION)
|
|
||||||
kwargs['timeout'] = HTTP_TIMEOUT
|
kwargs['timeout'] = HTTP_TIMEOUT
|
||||||
return Client(**kwargs)
|
return Client(**kwargs)
|
||||||
|
|
|
@ -15,3 +15,10 @@ LABEL_SERVICE = 'com.docker.compose.service'
|
||||||
LABEL_VERSION = 'com.docker.compose.version'
|
LABEL_VERSION = 'com.docker.compose.version'
|
||||||
LABEL_CONFIG_HASH = 'com.docker.compose.config-hash'
|
LABEL_CONFIG_HASH = 'com.docker.compose.config-hash'
|
||||||
COMPOSEFILE_VERSIONS = (1, 2)
|
COMPOSEFILE_VERSIONS = (1, 2)
|
||||||
|
|
||||||
|
API_VERSIONS = {
|
||||||
|
1: '1.21',
|
||||||
|
|
||||||
|
# TODO: update to 1.22 when there's a Docker 1.10 build to test against
|
||||||
|
2: '1.21',
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue