Files
homegate/ci/check_compose.py
DizelBadCoder a83d897b70
All checks were successful
Test and publish Homegate / checks (push) Successful in 29s
Test and publish Homegate / publish (push) Successful in 12m46s
Add first-run web setup and Compose without environment or secrets
2026-10-14 03:26:50 +03:00

83 lines
4.4 KiB
Python

"""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():
simple = json.loads(subprocess.check_output(
['docker', 'compose', '--env-file', os.devnull, '-f', 'compose.simple.yaml',
'config', '--format', 'json']))
assert set(simple['services']) == {'homegate'}
service = simple['services']['homegate']
assert not service.get('environment') and not service.get('env_file')
assert not simple.get('secrets') and not simple.get('configs')
assert service['image'] == 'gitea.hyperdog.dev/dizyaka/homegate:' + Path('VERSION').read_text().strip()
assert {p['published'] for p in service['ports']} == {'8098', '8099'}
assert {v['source'] for v in service['volumes']} == {'config', 'state', 'control'}
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()