67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
"""Prepare an isolated alternate Hermes container; never contact Docker here.
|
|
|
|
Run in a temporary, network-disabled helper using the old Hermes image:
|
|
docker run --rm --network none -v TEST_ROOT:/test \
|
|
--entrypoint /opt/hermes/.venv/bin/python OLD_IMAGE /test/build/prepare-container.py
|
|
The operator passes the resulting private create request to Docker locally.
|
|
No credentials are printed. Production appdata is never mounted in the helper.
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, '/opt/hermes')
|
|
import hermes_yaml as yaml
|
|
|
|
root = Path('/test')
|
|
original = json.loads((root / 'build/production-container.private.json').read_text())[0]
|
|
assert original['Name'] == '/Hermes-Agent-Desktop'
|
|
host_root = '/mnt/nvme-storage/appdata/Hermes-Webapp-Test'
|
|
prod_root = '/mnt/nvme-storage/appdata/Hermes-Agent-Desktop'
|
|
config = original['Config'].copy()
|
|
config['Image'] = 'local/hermes-webapp-test:e5f2b153'
|
|
# Docker owns hostname selection when joining an existing network namespace.
|
|
config.pop('Hostname', None)
|
|
config.pop('Domainname', None)
|
|
env = dict(v.split('=', 1) for v in config.get('Env', []) if '=' in v)
|
|
# Docker's snapshot can predate persistent env-file changes. Apply that same
|
|
# env-file internally, without executing it or displaying any of its values.
|
|
for raw in (root / 'data/container.env').read_text().splitlines():
|
|
line = raw.lstrip()
|
|
if not line or line.startswith('#'):
|
|
continue
|
|
assert '=' in line, 'Bare inherited env keys are not supported by this clone'
|
|
key, value = line.split('=', 1)
|
|
env[key] = value
|
|
assert env.get('HERMES_MANAGED_DIR') == '/opt/data/managed'
|
|
env['HERMES_DASHBOARD'] = '0'
|
|
config['Env'] = [f'{k}={v}' for k, v in env.items()]
|
|
config.setdefault('Labels', {})['de.casaderoll.test'] = 'hermes-webapp'
|
|
hc = original['HostConfig'].copy()
|
|
assert hc['NetworkMode'].startswith('container:')
|
|
binds = hc.get('Binds') or []
|
|
assert len(binds) == 1 and binds[0].split(':')[:2] == [prod_root, '/opt/data']
|
|
parts = binds[0].split(':')
|
|
parts[0] = host_root + '/data'
|
|
hc['Binds'] = [':'.join(parts)]
|
|
# An alternate, manually stopped container stays stopped with this policy.
|
|
assert hc['RestartPolicy']['Name'] == 'unless-stopped'
|
|
body = {**config, 'HostConfig': hc}
|
|
p = root / 'build/test-create.private.json'
|
|
p.write_text(json.dumps(body))
|
|
p.chmod(0o600)
|
|
|
|
cfg_path = root / 'data/config.yaml'
|
|
cfg = yaml.safe_load(cfg_path.read_text()) or {}
|
|
cfg['webapp'] = {
|
|
'enabled': True,
|
|
'host': '0.0.0.0',
|
|
'port': 9119,
|
|
'public_url': cfg.get('dashboard', {}).get('public_url', 'http://192.168.1.2:9120'),
|
|
}
|
|
cfg_path.write_text(yaml.safe_dump(cfg, allow_unicode=True, sort_keys=False))
|
|
cfg_path.chmod(0o600)
|
|
os.chown(cfg_path, 99, 100)
|
|
print('Prepared private create request; only copied root config changed: webapp on port 9119.')
|