Detach legacy model mounts and migrate verified GGUF references
This commit is contained in:
1 parent
08e70c9113
commit
8cefa0b043
7 files changed
+260
-7
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""Recreate Deck with its existing image to detach verified legacy model mounts.
|
||||
|
||||
Requires an explicitly authorized maintenance window. Uses the same installer
|
||||
launch recipe and restores the original container if startup fails.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import install
|
||||
|
||||
|
||||
def rebind(base):
|
||||
config = install.load_manifest(base)
|
||||
previous = install.owned(config['name'], base)
|
||||
if not previous:
|
||||
raise RuntimeError('Deck-Container fehlt.')
|
||||
if not any(m['Source'].startswith('/data/models') for m in previous['Mounts']):
|
||||
print('Keine alten Modell-Mounts vorhanden.')
|
||||
return
|
||||
report = json.loads((base / 'state/reference-model-migration.json').read_text())
|
||||
if len(report) != 4:
|
||||
raise RuntimeError('Modellübernahme ist nicht vollständig.')
|
||||
for row in report:
|
||||
entry = base / 'state/models' / row['model_id']
|
||||
metadata = json.loads((entry / 'entry.json').read_text())
|
||||
if metadata['sha256'] != row['sha256'] or (entry / 'model.gguf').stat().st_size != metadata['size']:
|
||||
raise RuntimeError('Modellübernahme stimmt nicht mit Metadaten überein.')
|
||||
fallback = config['name'] + '-before-model-rebind'
|
||||
if install.inspect(fallback):
|
||||
raise RuntimeError('Rückfall-Containername belegt.')
|
||||
shutil.copyfile(base / 'installation.json', base / ('installation-before-model-rebind-' + str(time.time_ns()) + '.json'))
|
||||
was_running = previous['State']['Running']
|
||||
if was_running:
|
||||
install.run('docker', 'stop', '--time', '30', config['name'])
|
||||
install.run('docker', 'rename', config['name'], fallback)
|
||||
try:
|
||||
install.launch(config)
|
||||
install.ready(config)
|
||||
current = install.owned(config['name'], base)
|
||||
if any(m['Source'].startswith('/data/models') for m in current['Mounts']):
|
||||
raise RuntimeError('Alte Modelle weiterhin eingebunden.')
|
||||
except Exception:
|
||||
if install.owned(config['name'], base):
|
||||
install.run('docker', 'rm', '-f', config['name'])
|
||||
install.run('docker', 'rename', fallback, config['name'])
|
||||
if was_running:
|
||||
install.run('docker', 'start', config['name'])
|
||||
raise
|
||||
install.run('docker', 'rm', fallback)
|
||||
print('Deck mit unverändertem App-Image neu gestartet; alte Modell-Mounts entfernt.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--directory', type=Path, required=True)
|
||||
parser.add_argument('--maintenance-window-approved', action='store_true', required=True)
|
||||
args = parser.parse_args()
|
||||
rebind(args.directory)
|
||||
Reference in new issue
Block a user