mirror of https://github.com/docker/compose.git
Allow setting compatibility options from environment
Signed-off-by: Kevin Roy <kiniou@gmail.com>
This commit is contained in:
parent
f1cfd93c8f
commit
093cc2c089
|
@ -59,7 +59,7 @@ def project_from_options(project_dir, options, additional_options={}):
|
|||
tls_config=tls_config_from_options(options, environment),
|
||||
environment=environment,
|
||||
override_dir=override_dir,
|
||||
compatibility=options.get('--compatibility'),
|
||||
compatibility=compatibility_from_options(project_dir, options, environment),
|
||||
interpolate=(not additional_options.get('--no-interpolate')),
|
||||
environment_file=environment_file
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ def get_config_from_options(base_dir, options, additional_options={}):
|
|||
)
|
||||
return config.load(
|
||||
config.find(base_dir, config_path, environment, override_dir),
|
||||
options.get('--compatibility'),
|
||||
compatibility_from_options(config_path, options, environment),
|
||||
not additional_options.get('--no-interpolate')
|
||||
)
|
||||
|
||||
|
@ -198,3 +198,13 @@ def get_project_name(working_dir, project_name=None, environment=None):
|
|||
return normalize_name(project)
|
||||
|
||||
return 'default'
|
||||
|
||||
|
||||
def compatibility_from_options(working_dir, options=None, environment=None):
|
||||
"""Get compose v3 compatibility from --compatibility option
|
||||
or from COMPOSE_COMPATIBILITY environment variable."""
|
||||
|
||||
compatibility_option = options.get('--compatibility')
|
||||
compatibility_environment = environment.get_boolean('COMPOSE_COMPATIBILITY')
|
||||
|
||||
return compatibility_option or compatibility_environment
|
||||
|
|
|
@ -43,6 +43,24 @@ ProcessResult = namedtuple('ProcessResult', 'stdout stderr')
|
|||
|
||||
BUILD_CACHE_TEXT = 'Using cache'
|
||||
BUILD_PULL_TEXT = 'Status: Image is up to date for busybox:1.27.2'
|
||||
COMPOSE_COMPATIBILITY_DICT = {
|
||||
'version': '2.3',
|
||||
'volumes': {'foo': {'driver': 'default'}},
|
||||
'networks': {'bar': {}},
|
||||
'services': {
|
||||
'foo': {
|
||||
'command': '/bin/true',
|
||||
'image': 'alpine:3.10.1',
|
||||
'scale': 3,
|
||||
'restart': 'always:7',
|
||||
'mem_limit': '300M',
|
||||
'mem_reservation': '100M',
|
||||
'cpus': 0.7,
|
||||
'volumes': ['foo:/bar:rw'],
|
||||
'networks': {'bar': None},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def start_process(base_dir, options):
|
||||
|
@ -564,24 +582,23 @@ services:
|
|||
self.base_dir = 'tests/fixtures/compatibility-mode'
|
||||
result = self.dispatch(['--compatibility', 'config'])
|
||||
|
||||
assert yaml.safe_load(result.stdout) == {
|
||||
'version': '2.3',
|
||||
'volumes': {'foo': {'driver': 'default'}},
|
||||
'networks': {'bar': {}},
|
||||
'services': {
|
||||
'foo': {
|
||||
'command': '/bin/true',
|
||||
'image': 'alpine:3.10.1',
|
||||
'scale': 3,
|
||||
'restart': 'always:7',
|
||||
'mem_limit': '300M',
|
||||
'mem_reservation': '100M',
|
||||
'cpus': 0.7,
|
||||
'volumes': ['foo:/bar:rw'],
|
||||
'networks': {'bar': None},
|
||||
}
|
||||
},
|
||||
}
|
||||
assert yaml.load(result.stdout) == COMPOSE_COMPATIBILITY_DICT
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_config_compatibility_mode_from_env(self):
|
||||
self.base_dir = 'tests/fixtures/compatibility-mode'
|
||||
os.environ['COMPOSE_COMPATIBILITY'] = 'true'
|
||||
result = self.dispatch(['config'])
|
||||
|
||||
assert yaml.load(result.stdout) == COMPOSE_COMPATIBILITY_DICT
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_config_compatibility_mode_from_env_and_option_precedence(self):
|
||||
self.base_dir = 'tests/fixtures/compatibility-mode'
|
||||
os.environ['COMPOSE_COMPATIBILITY'] = 'false'
|
||||
result = self.dispatch(['--compatibility', 'config'])
|
||||
|
||||
assert yaml.load(result.stdout) == COMPOSE_COMPATIBILITY_DICT
|
||||
|
||||
def test_ps(self):
|
||||
self.project.get_service('simple').create_container()
|
||||
|
|
Loading…
Reference in New Issue