fix(deploy): 保留已有覆盖配置并支持重复迁移
This commit is contained in:
@@ -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'}
|
||||
|
||||
Reference in New Issue
Block a user