Reuse verified installer files when updating lightweight Edge snapshots
This commit is contained in:
parent
afe749fc1b
commit
8990f4efb5
|
|
@ -4,7 +4,6 @@
|
||||||
из нашего Git. Актуальные команды и состав — [в инструкции установки](offline/README.md).
|
из нашего Git. Актуальные команды и состав — [в инструкции установки](offline/README.md).
|
||||||
Зависимости хранятся в Git внутри `third_party/` и скачиваются по необходимости;
|
Зависимости хранятся в Git внутри `third_party/` и скачиваются по необходимости;
|
||||||
на Edge полный набор пакетов и `.git` больше не сохраняются.
|
на Edge полный набор пакетов и `.git` больше не сохраняются.
|
||||||
Старые команды ниже сохраняются как справочная история, если расходятся с этой инструкцией.
|
|
||||||
|
|
||||||
Это простая инструкция по установке Edge после прошивки vendor image.
|
Это простая инструкция по установке Edge после прошивки vendor image.
|
||||||
|
|
||||||
|
|
@ -27,8 +26,8 @@ install_iomatex_edge.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Этот скрипт сам:
|
Этот скрипт сам:
|
||||||
- установит `git`, если его нет;
|
- получит скрипты и каталог пакетов без полного Git clone;
|
||||||
- скачает или обновит репозиторий;
|
- скачает только необходимые пакеты из нашего Git и удалит временные загрузки;
|
||||||
- запустит основной порядок стадий;
|
- запустит основной порядок стадий;
|
||||||
- после `stage_env` переживет reboot и продолжит установку сам.
|
- после `stage_env` переживет reboot и продолжит установку сам.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,19 @@ def check_existing(dest):
|
||||||
elif dest.exists() and any(dest.iterdir()):
|
elif dest.exists() and any(dest.iterdir()):
|
||||||
raise ValueError('Refusing to replace an unidentified nonempty directory')
|
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):
|
def bootstrap(url, branch, checkout):
|
||||||
platform_check()
|
platform_check()
|
||||||
repo = repo_name(url)
|
repo = repo_name(url)
|
||||||
|
|
@ -130,14 +143,7 @@ def bootstrap(url, branch, checkout):
|
||||||
staged = Path(tmp) / 'snapshot'
|
staged = Path(tmp) / 'snapshot'
|
||||||
staged.mkdir()
|
staged.mkdir()
|
||||||
def download(entry):
|
def download(entry):
|
||||||
with open_git(repo, raw_endpoint(entry['path'], commit), auth) as r:
|
materialize_file(repo, commit, auth, entry, dest, staged)
|
||||||
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))
|
|
||||||
print('Fetching', len(files), 'installer/metadata files; package payloads excluded', flush=True)
|
print('Fetching', len(files), 'installer/metadata files; package payloads excluded', flush=True)
|
||||||
with ThreadPoolExecutor(max_workers=6) as pool:
|
with ThreadPoolExecutor(max_workers=6) as pool:
|
||||||
list(pool.map(download, files))
|
list(pool.map(download, files))
|
||||||
|
|
@ -157,7 +163,9 @@ def bootstrap(url, branch, checkout):
|
||||||
relative = p.relative_to(dest).as_posix()
|
relative = p.relative_to(dest).as_posix()
|
||||||
if '.git' in p.relative_to(dest).parts or relative in tracked or relative == '.iomatex-source.json':
|
if '.git' in p.relative_to(dest).parts or relative in tracked or relative == '.iomatex-source.json':
|
||||||
continue
|
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)
|
(staged / relative).parent.mkdir(parents=True, exist_ok=True)
|
||||||
shutil.copy2(p, staged / relative)
|
shutil.copy2(p, staged / relative)
|
||||||
dest.rename(previous)
|
dest.rename(previous)
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,16 @@ class DeliveryTest(unittest.TestCase):
|
||||||
for path in [key, 'debian/xserver-common_2%253a1.0%2bdeb11_all.deb']:
|
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))
|
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):
|
def test_no_redirect_even_on_same_host(self):
|
||||||
with self.assertRaisesRegex(ValueError,'redirect refused'):
|
with self.assertRaisesRegex(ValueError,'redirect refused'):
|
||||||
d.NoRedirect().redirect_request(None,None,302,'',{},'https://git.it-screen.com/other')
|
d.NoRedirect().redirect_request(None,None,302,'',{},'https://git.it-screen.com/other')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue