diff --git a/ENGINEER_INSTRUCTIONS.md b/ENGINEER_INSTRUCTIONS.md index 2774d9a..1ccbf9e 100644 --- a/ENGINEER_INSTRUCTIONS.md +++ b/ENGINEER_INSTRUCTIONS.md @@ -4,7 +4,6 @@ из нашего Git. Актуальные команды и состав — [в инструкции установки](offline/README.md). Зависимости хранятся в Git внутри `third_party/` и скачиваются по необходимости; на Edge полный набор пакетов и `.git` больше не сохраняются. -Старые команды ниже сохраняются как справочная история, если расходятся с этой инструкцией. Это простая инструкция по установке Edge после прошивки vendor image. @@ -27,8 +26,8 @@ install_iomatex_edge.sh ``` Этот скрипт сам: -- установит `git`, если его нет; -- скачает или обновит репозиторий; +- получит скрипты и каталог пакетов без полного Git clone; +- скачает только необходимые пакеты из нашего Git и удалит временные загрузки; - запустит основной порядок стадий; - после `stage_env` переживет reboot и продолжит установку сам. diff --git a/offline/git_delivery.py b/offline/git_delivery.py index 6bd4883..67b863c 100644 --- a/offline/git_delivery.py +++ b/offline/git_delivery.py @@ -98,6 +98,19 @@ def check_existing(dest): elif dest.exists() and any(dest.iterdir()): raise ValueError('Refusing to replace an unidentified nonempty directory') +def materialize_file(repo, commit, auth, entry, existing, staged): + old = existing / entry['path'] + data = old.read_bytes() if old.is_file() and not old.is_symlink() else None + if data is None or blob_hash(data) != entry['sha']: + with open_git(repo, raw_endpoint(entry['path'], commit), auth) as response: + data = response.read() + if blob_hash(data) != entry['sha']: + raise ValueError('Git blob checksum mismatch: ' + entry['path']) + p = staged / entry['path'] + p.parent.mkdir(parents=True, exist_ok=True) + p.write_bytes(data) + p.chmod(int(entry['mode'][-3:], 8)) + def bootstrap(url, branch, checkout): platform_check() repo = repo_name(url) @@ -130,14 +143,7 @@ def bootstrap(url, branch, checkout): staged = Path(tmp) / 'snapshot' staged.mkdir() def download(entry): - with open_git(repo, raw_endpoint(entry['path'], commit), auth) as r: - data = r.read() - if blob_hash(data) != entry['sha']: - raise ValueError('Git blob checksum mismatch: ' + entry['path']) - p = staged / entry['path'] - p.parent.mkdir(parents=True, exist_ok=True) - p.write_bytes(data) - p.chmod(int(entry['mode'][-3:], 8)) + materialize_file(repo, commit, auth, entry, dest, staged) print('Fetching', len(files), 'installer/metadata files; package payloads excluded', flush=True) with ThreadPoolExecutor(max_workers=6) as pool: list(pool.map(download, files)) @@ -157,7 +163,9 @@ def bootstrap(url, branch, checkout): relative = p.relative_to(dest).as_posix() if '.git' in p.relative_to(dest).parts or relative in tracked or relative == '.iomatex-source.json': continue - if p.is_file() and not p.is_symlink() and not (staged / relative).exists(): + if p.is_symlink(): + raise ValueError('Preserve untracked symlink before updating: ' + relative) + if p.is_file() and not (staged / relative).exists(): (staged / relative).parent.mkdir(parents=True, exist_ok=True) shutil.copy2(p, staged / relative) dest.rename(previous) diff --git a/offline/test_git_delivery.py b/offline/test_git_delivery.py index dfb4d3a..dfe9487 100644 --- a/offline/test_git_delivery.py +++ b/offline/test_git_delivery.py @@ -55,6 +55,16 @@ class DeliveryTest(unittest.TestCase): for path in [key, 'debian/xserver-common_2%253a1.0%2bdeb11_all.deb']: self.assertEqual(key,d.apt_key('iomatex://git.it-screen.com/'+path,objects)) + def test_unchanged_snapshot_file_is_reused_without_network(self): + with tempfile.TemporaryDirectory() as folder: + existing=Path(folder)/'old'; staged=Path(folder)/'new' + existing.mkdir(); staged.mkdir() + (existing/'installer.sh').write_bytes(b'unchanged') + entry={'path':'installer.sh','mode':'100755','sha':d.blob_hash(b'unchanged')} + with patch.object(d,'open_git',side_effect=AssertionError('Unnecessary download')): + d.materialize_file('An-J/Iomatex_OS','a'*40,{},entry,existing,staged) + self.assertEqual(b'unchanged',(staged/'installer.sh').read_bytes()) + def test_no_redirect_even_on_same_host(self): with self.assertRaisesRegex(ValueError,'redirect refused'): d.NoRedirect().redirect_request(None,None,302,'',{},'https://git.it-screen.com/other')