Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make the merged checksum file available to the installer #3597

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3597.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The installer changes from downloading the checksum files for each package separately to receiving a consolidated checksum file and using them separately.
34 changes: 28 additions & 6 deletions src/ai/backend/install/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,24 +991,45 @@ async def _validate_checksum(self, pkg_path: Path, csum_path: Path) -> None:
async def _fetch_package(self, name: str, vpane: Vertical) -> None:
pkg_name = self.mangle_pkgname(name)
dst_path = self.dist_info.target_path / pkg_name
csum_path = dst_path.with_name(pkg_name + ".sha256")
pkg_url = f"https://github.com/lablup/backend.ai/releases/download/{self.dist_info.version}/{pkg_name}"
csum_url = pkg_url + ".sha256"
self.log.write(f"Downloading {pkg_url}...")
item = ProgressItem(f"[blue](download)[/] {pkg_name}")
await vpane.mount(item)
progress = item.get_child_by_type(ProgressBar)
async with self.wget_sema:
await wget(pkg_url, dst_path, progress)
await wget(csum_url, csum_path)

async def _fetch_checksums(self, vpane: Vertical) -> None:
csum_url = f"https://github.com/lablup/backend.ai/releases/download/{self.dist_info.version}/checksum.txt"
dst_path = self.dist_info.target_path / "checksum.txt"
self.log.write(f"Downloading {csum_url}...")
item = ProgressItem("[blue](download)[/] checksum.txt")
await vpane.mount(item)
progress = item.get_child_by_type(ProgressBar)
async with self.wget_sema:
await wget(csum_url, dst_path, progress)

Comment on lines +1009 to 1011
Copy link
Preview

Copilot AI Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download of the checksum file should handle potential errors to avoid issues if the download fails.

Suggested change
async with self.wget_sema:
await wget(csum_url, dst_path, progress)
try:
async with self.wget_sema:
await wget(csum_url, dst_path, progress)
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
self.log.write(f"Failed to download {csum_url}: {e}")
raise RuntimeError(f"Failed to download checksum file from {csum_url}. Please check your network connection and try again.")

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
async def _verify_package(self, name: str, *, fat: bool) -> None:
pkg_name = self.mangle_pkgname(name, fat=fat)
dst_path = self.dist_info.target_path / pkg_name
self.log.write(f"Verifying {dst_path} ...")
csum_path = dst_path.with_name(pkg_name + ".sha256")
await self._validate_checksum(dst_path, csum_path)
csum_path.unlink()
csum_path = self.dist_info.target_path / "checksum.txt"

with open(csum_path, "r") as f:
lines = f.readlines()
for line in lines:
if pkg_name in line:
csum_line = line
break
else:
raise ValueError(f"Checksum for {pkg_name} not found in {csum_path}")

individual_csum_path = dst_path.with_name(pkg_name + ".sha256")
with open(individual_csum_path, "w") as f:
f.write(csum_line)

await self._validate_checksum(dst_path, individual_csum_path)
individual_csum_path.unlink()
dst_path.chmod(0o755)
dst_path.rename(dst_path.with_name(f"backendai-{name}"))

Expand Down Expand Up @@ -1060,6 +1081,7 @@ async def install(self) -> None:
tg.create_task(self._fetch_package("wsproxy", vpane))
tg.create_task(self._fetch_package("storage-proxy", vpane))
tg.create_task(self._fetch_package("client", vpane))
tg.create_task(self._fetch_checksums(vpane))
# Verify the checksums of the downloaded packages.
await self._verify_package("manager", fat=False)
await self._verify_package("agent", fat=False)
Expand Down
Loading