"""Validate both deployment models without a running Docker daemon or real credentials.""" import json import os from pathlib import Path import subprocess 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', HOMEGATE_ALLOWED_NETWORKS='[192.168.0.0/24]', HOMEGATE_ZONES='[home, home.arpa]', HOMEGATE_DNS_MODE='manual', UI_ORIGIN='http://192.168.0.10:8098', NPM_URL='http://192.168.0.10:81', NPM_IDENTITY='test@example.invalid', UI_PASSWORD='test-only-panel-password', NPM_PASSWORD='test-only-npm', PIHOLE_PASSWORD='not-used', PIHOLE_URL='', UI_PORT='8098', SSH_PORT='8099') 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 assert service['image'] == env['HOMEGATE_IMAGE'] assert all(v['type'] == 'volume' for v in service.get('volumes', [])), name if name != 'initialize': assert service['user'] == '1000:1000' assert service['depends_on']['initialize']['condition'] == 'service_completed_successfully' for port in service.get('ports', []): assert port['host_ip'] == env['HOMEGATE_LAN_IP'] 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']) assert set(model['secrets']) == {'ui_password', 'npm_password', 'pihole_password'} 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'] == [] 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, '-f', 'compose.registry.yaml', 'config', '--quiet'], env=env, capture_output=True) assert missing.returncode != 0 print('Build and registry Compose models validated; isolation and first-run defaults verified.') if __name__ == '__main__': main()