Fix inline configs and secrets in registry Compose deployment
This commit is contained in:
@@ -7,6 +7,21 @@ import yaml
|
||||
import homegate as h
|
||||
|
||||
|
||||
def check_read_only_resources(model):
|
||||
# compose config accepts this combination, but container creation rejects it.
|
||||
for name, service in model['services'].items():
|
||||
if not service.get('read_only'):
|
||||
continue
|
||||
for kind in ('configs', 'secrets'):
|
||||
for resource in service.get(kind, []):
|
||||
source = resource['source']
|
||||
definition = model[kind][source]
|
||||
assert 'file' in definition, (
|
||||
f'{name}: read_only requires a file source for {kind}.{source}; '
|
||||
'Compose cannot inject content/environment into a read-only container'
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
env = dict(os.environ, HOMEGATE_IMAGE='registry.example/homegate/homegate:0.4.0',
|
||||
HOMEGATE_LAN_IP='192.168.0.10', HOMEGATE_PROXY_IP='192.168.0.10',
|
||||
@@ -18,6 +33,7 @@ def main():
|
||||
model = json.loads(subprocess.check_output(
|
||||
['docker', 'compose', '--env-file', os.devnull, '-f', 'compose.registry.yaml',
|
||||
'config', '--format', 'json'], env=env))
|
||||
check_read_only_resources(model)
|
||||
assert set(model['services']) == {'initialize', 'homegate', 'ssh-export', 'ui'}
|
||||
for name, service in model['services'].items():
|
||||
assert 'build' not in service, name
|
||||
@@ -31,6 +47,7 @@ def main():
|
||||
assert model['services']['initialize']['network_mode'] == 'none'
|
||||
assert not model['services']['initialize'].get('secrets')
|
||||
assert not model['services']['ssh-export'].get('secrets')
|
||||
assert model['services']['ssh-export']['read_only']
|
||||
assert [v['source'] for v in model['services']['ui']['secrets']] == ['ui_password']
|
||||
for name in ('ui', 'ssh-export'):
|
||||
assert all(v['target'] != '/data' for v in model['services'][name]['volumes'])
|
||||
@@ -38,8 +55,10 @@ def main():
|
||||
assert all('environment' in s and 'file' not in s for s in model['secrets'].values())
|
||||
seed = h.validate_config(yaml.safe_load(model['configs']['initial-config']['content']))
|
||||
assert seed['services'] == [] and seed['ssh_hosts'] == []
|
||||
subprocess.run(['docker', 'compose', '--env-file', '.env.example', '-f', 'compose.yaml',
|
||||
'config', '--quiet'], check=True, env=env)
|
||||
source_model = json.loads(subprocess.check_output(
|
||||
['docker', 'compose', '--env-file', '.env.example', '-f', 'compose.yaml',
|
||||
'config', '--format', 'json'], env=env))
|
||||
check_read_only_resources(source_model)
|
||||
# The one-file deployment cannot accidentally fall back to all host interfaces.
|
||||
del env['HOMEGATE_LAN_IP']
|
||||
missing = subprocess.run(['docker', 'compose', '--env-file', os.devnull,
|
||||
|
||||
Reference in New Issue
Block a user