mirror of https://github.com/docker/compose.git
Add support for DOCKER_* variables in .env file
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
c7afe16419
commit
b99037b4a6
|
@ -43,8 +43,11 @@ def get_config_path_from_options(base_dir, options, environment):
|
|||
return None
|
||||
|
||||
|
||||
def get_client(verbose=False, version=None, tls_config=None, host=None):
|
||||
client = docker_client(version=version, tls_config=tls_config, host=host)
|
||||
def get_client(environment, verbose=False, version=None, tls_config=None, host=None):
|
||||
client = docker_client(
|
||||
version=version, tls_config=tls_config, host=host,
|
||||
environment=environment
|
||||
)
|
||||
if verbose:
|
||||
version_info = six.iteritems(client.version())
|
||||
log.info(get_version_info('full'))
|
||||
|
@ -70,7 +73,7 @@ def get_project(project_dir, config_path=None, project_name=None, verbose=False,
|
|||
API_VERSIONS[config_data.version])
|
||||
client = get_client(
|
||||
verbose=verbose, version=api_version, tls_config=tls_config,
|
||||
host=host
|
||||
host=host, environment=environment
|
||||
)
|
||||
|
||||
return Project.from_config(project_name, config_data, client)
|
||||
|
|
|
@ -2,7 +2,6 @@ from __future__ import absolute_import
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from docker import Client
|
||||
from docker.errors import TLSParameterError
|
||||
|
@ -42,17 +41,17 @@ def tls_config_from_options(options):
|
|||
return None
|
||||
|
||||
|
||||
def docker_client(version=None, tls_config=None, host=None):
|
||||
def docker_client(environment, version=None, tls_config=None, host=None):
|
||||
"""
|
||||
Returns a docker-py client configured using environment variables
|
||||
according to the same logic as the official Docker client.
|
||||
"""
|
||||
if 'DOCKER_CLIENT_TIMEOUT' in os.environ:
|
||||
if 'DOCKER_CLIENT_TIMEOUT' in environment:
|
||||
log.warn("The DOCKER_CLIENT_TIMEOUT environment variable is deprecated. "
|
||||
"Please use COMPOSE_HTTP_TIMEOUT instead.")
|
||||
|
||||
try:
|
||||
kwargs = kwargs_from_env(assert_hostname=False)
|
||||
kwargs = kwargs_from_env(assert_hostname=False, environment=environment)
|
||||
except TLSParameterError:
|
||||
raise UserError(
|
||||
"TLS configuration is invalid - make sure your DOCKER_TLS_VERIFY "
|
||||
|
@ -67,6 +66,10 @@ def docker_client(version=None, tls_config=None, host=None):
|
|||
if version:
|
||||
kwargs['version'] = version
|
||||
|
||||
kwargs['timeout'] = HTTP_TIMEOUT
|
||||
timeout = environment.get('COMPOSE_HTTP_TIMEOUT')
|
||||
if timeout:
|
||||
kwargs['timeout'] = int(timeout)
|
||||
else:
|
||||
kwargs['timeout'] = HTTP_TIMEOUT
|
||||
|
||||
return Client(**kwargs)
|
||||
|
|
|
@ -5,7 +5,7 @@ import os
|
|||
import sys
|
||||
|
||||
DEFAULT_TIMEOUT = 10
|
||||
HTTP_TIMEOUT = int(os.environ.get('COMPOSE_HTTP_TIMEOUT', os.environ.get('DOCKER_CLIENT_TIMEOUT', 60)))
|
||||
HTTP_TIMEOUT = int(os.environ.get('DOCKER_CLIENT_TIMEOUT', 60))
|
||||
IMAGE_EVENTS = ['delete', 'import', 'pull', 'push', 'tag', 'untag']
|
||||
IS_WINDOWS_PLATFORM = (sys.platform == "win32")
|
||||
LABEL_CONTAINER_NUMBER = 'com.docker.compose.container-number'
|
||||
|
|
|
@ -28,9 +28,13 @@ Those environment variables will be used for
|
|||
file, but can also be used to define the following
|
||||
[CLI variables](reference/envvars.md):
|
||||
|
||||
- `COMPOSE_PROJECT_NAME`
|
||||
- `COMPOSE_FILE`
|
||||
- `COMPOSE_API_VERSION`
|
||||
- `COMPOSE_FILE`
|
||||
- `COMPOSE_HTTP_TIMEOUT`
|
||||
- `COMPOSE_PROJECT_NAME`
|
||||
- `DOCKER_CERT_PATH`
|
||||
- `DOCKER_HOST`
|
||||
- `DOCKER_TLS_VERIFY`
|
||||
|
||||
## More Compose documentation
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class DockerClientTestCase(unittest.TestCase):
|
|||
else:
|
||||
version = API_VERSIONS[V2_0]
|
||||
|
||||
cls.client = docker_client(version)
|
||||
cls.client = docker_client(Environment(), version)
|
||||
|
||||
def tearDown(self):
|
||||
for c in self.client.containers(
|
||||
|
|
|
@ -17,12 +17,12 @@ class DockerClientTestCase(unittest.TestCase):
|
|||
def test_docker_client_no_home(self):
|
||||
with mock.patch.dict(os.environ):
|
||||
del os.environ['HOME']
|
||||
docker_client()
|
||||
docker_client(os.environ)
|
||||
|
||||
def test_docker_client_with_custom_timeout(self):
|
||||
timeout = 300
|
||||
with mock.patch('compose.cli.docker_client.HTTP_TIMEOUT', 300):
|
||||
client = docker_client()
|
||||
client = docker_client(os.environ)
|
||||
self.assertEqual(client.timeout, int(timeout))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue