fix(deploy): 保留已有覆盖配置并支持重复迁移

This commit is contained in:
easyai02
2026-10-09 03:16:51 +08:00
parent 94f9313e24
commit f01d36d2b8
2 changed files with 43 additions and 4 deletions
+16
View File
@@ -86,6 +86,22 @@ for restore in ('', 'easyai-web', 'redis', 'ws-gateway'):
# A second adoption preserves the result and creates no extra backup.
checked(['python3', str(prepare), str(root)], root, env)
assert len(list((root / 'data/deployment-backups').glob('legacy-update-*'))) == 1
# A later main-file customization is adopted without dropping the
# existing override or changing an unrelated dependency setting.
main_path = root / 'docker-compose.yml'
main_path.write_text(main_path.read_text().replace('LOCAL_SETTING=original', 'LOCAL_SETTING=second-custom'))
override_file = root / 'data/deployment-config/legacy-compose.json'
previous_override = override_file.read_bytes()
checked(['python3', str(prepare), str(root)], root, env)
config = json.loads(checked(['docker', 'compose', '--env-file', '.env', 'config', '--format', 'json'], root))
assert config['services']['easyai-server']['environment']['LOCAL_SETTING'] == 'second-custom'
assert config['services']['redis']['image'] == 'redis:6.2'
assert config['services']['easyai-web']['image'] == ('repository-web:latest' if restore else pin)
backups = list((root / 'data/deployment-backups').glob('legacy-update-*'))
assert len(backups) == 2
newest = max(backups, key=lambda p: p.stat().st_mtime)
assert (newest / 'data/deployment-config/legacy-compose.json').read_bytes() == previous_override
assert (newest / 'data/deployment-config/legacy-compose.json').stat().st_mode & 0o077 == 0
for mode, adopt in (('image', '1'), ('full', '0')):
env = {**os.environ, 'UPDATE_MODE': mode, 'UPDATE_ADOPT_LEGACY_CONFIG': adopt, 'UPDATE_RESTORE_REPOSITORY_IMAGES': 'easyai-web'}