mirror of https://github.com/docker/compose.git
Merge pull request #4469 from dnephin/fix_secrets_config
Fixes secrets config loading
This commit is contained in:
commit
ad0e6d219b
|
@ -763,6 +763,11 @@ def finalize_service(service_config, service_names, version, environment):
|
||||||
if 'restart' in service_dict:
|
if 'restart' in service_dict:
|
||||||
service_dict['restart'] = parse_restart_spec(service_dict['restart'])
|
service_dict['restart'] = parse_restart_spec(service_dict['restart'])
|
||||||
|
|
||||||
|
if 'secrets' in service_dict:
|
||||||
|
service_dict['secrets'] = [
|
||||||
|
types.ServiceSecret.parse(s) for s in service_dict['secrets']
|
||||||
|
]
|
||||||
|
|
||||||
normalize_build(service_dict, service_config.working_dir, environment)
|
normalize_build(service_dict, service_config.working_dir, environment)
|
||||||
|
|
||||||
service_dict['name'] = service_config.name
|
service_dict['name'] = service_config.name
|
||||||
|
|
|
@ -253,3 +253,11 @@ class ServiceSecret(namedtuple('_ServiceSecret', 'source target uid gid mode')):
|
||||||
@property
|
@property
|
||||||
def merge_field(self):
|
def merge_field(self):
|
||||||
return self.source
|
return self.source
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return dict(
|
||||||
|
source=self.source,
|
||||||
|
target=self.target,
|
||||||
|
uid=self.uid,
|
||||||
|
gid=self.gid,
|
||||||
|
mode=self.mode)
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -64,11 +64,9 @@ try:
|
||||||
for key, value in extras_require.items():
|
for key, value in extras_require.items():
|
||||||
if key.startswith(':') and pkg_resources.evaluate_marker(key[1:]):
|
if key.startswith(':') and pkg_resources.evaluate_marker(key[1:]):
|
||||||
install_requires.extend(value)
|
install_requires.extend(value)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logging.getLogger(__name__).exception(
|
print("Failed to compute platform dependencies: {}. ".format(e) +
|
||||||
'Failed to compute platform dependencies. All dependencies will be '
|
"All dependencies will be installed as a result.", file=sys.stderr)
|
||||||
'installed as a result.'
|
|
||||||
)
|
|
||||||
for key, value in extras_require.items():
|
for key, value in extras_require.items():
|
||||||
if key.startswith(':'):
|
if key.startswith(':'):
|
||||||
install_requires.extend(value)
|
install_requires.extend(value)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import pytest
|
||||||
|
|
||||||
from ...helpers import build_config_details
|
from ...helpers import build_config_details
|
||||||
from compose.config import config
|
from compose.config import config
|
||||||
|
from compose.config import types
|
||||||
from compose.config.config import resolve_build_args
|
from compose.config.config import resolve_build_args
|
||||||
from compose.config.config import resolve_environment
|
from compose.config.config import resolve_environment
|
||||||
from compose.config.config import V1
|
from compose.config.config import V1
|
||||||
|
@ -1849,6 +1850,91 @@ class ConfigTest(unittest.TestCase):
|
||||||
config.load(config_details)
|
config.load(config_details)
|
||||||
assert 'has neither an image nor a build context' in exc.exconly()
|
assert 'has neither an image nor a build context' in exc.exconly()
|
||||||
|
|
||||||
|
def test_load_secrets(self):
|
||||||
|
base_file = config.ConfigFile(
|
||||||
|
'base.yaml',
|
||||||
|
{
|
||||||
|
'version': '3.1',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'example/web',
|
||||||
|
'secrets': [
|
||||||
|
'one',
|
||||||
|
{
|
||||||
|
'source': 'source',
|
||||||
|
'target': 'target',
|
||||||
|
'uid': '100',
|
||||||
|
'gid': '200',
|
||||||
|
'mode': 0o777,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'secrets': {
|
||||||
|
'one': {'file': 'secret.txt'},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
details = config.ConfigDetails('.', [base_file])
|
||||||
|
service_dicts = config.load(details).services
|
||||||
|
expected = [
|
||||||
|
{
|
||||||
|
'name': 'web',
|
||||||
|
'image': 'example/web',
|
||||||
|
'secrets': [
|
||||||
|
types.ServiceSecret('one', None, None, None, None),
|
||||||
|
types.ServiceSecret('source', 'target', '100', '200', 0o777),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
assert service_sort(service_dicts) == service_sort(expected)
|
||||||
|
|
||||||
|
def test_load_secrets_multi_file(self):
|
||||||
|
base_file = config.ConfigFile(
|
||||||
|
'base.yaml',
|
||||||
|
{
|
||||||
|
'version': '3.1',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'example/web',
|
||||||
|
'secrets': ['one'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'secrets': {
|
||||||
|
'one': {'file': 'secret.txt'},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
override_file = config.ConfigFile(
|
||||||
|
'base.yaml',
|
||||||
|
{
|
||||||
|
'version': '3.1',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'secrets': [
|
||||||
|
{
|
||||||
|
'source': 'source',
|
||||||
|
'target': 'target',
|
||||||
|
'uid': '100',
|
||||||
|
'gid': '200',
|
||||||
|
'mode': 0o777,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
details = config.ConfigDetails('.', [base_file, override_file])
|
||||||
|
service_dicts = config.load(details).services
|
||||||
|
expected = [
|
||||||
|
{
|
||||||
|
'name': 'web',
|
||||||
|
'image': 'example/web',
|
||||||
|
'secrets': [
|
||||||
|
types.ServiceSecret('one', None, None, None, None),
|
||||||
|
types.ServiceSecret('source', 'target', '100', '200', 0o777),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
assert service_sort(service_dicts) == service_sort(expected)
|
||||||
|
|
||||||
|
|
||||||
class NetworkModeTest(unittest.TestCase):
|
class NetworkModeTest(unittest.TestCase):
|
||||||
def test_network_mode_standard(self):
|
def test_network_mode_standard(self):
|
||||||
|
|
Loading…
Reference in New Issue