-
Notifications
You must be signed in to change notification settings - Fork 9
🚸 Show Top-3 files larger than threshold on deploy command
#190
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
base: main
Are you sure you want to change the base?
Changes from all commits
7a39272
dccea9b
539f028
5005f99
36b5751
1d2ed14
5a13cc8
d166877
1e611ca
cd445ff
81799ee
8cc01a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,15 +108,19 @@ def _should_exclude_entry(path: Path) -> bool: | |
| return False | ||
|
|
||
|
|
||
| def archive(path: Path, tar_path: Path) -> Path: | ||
| logger.debug("Starting archive creation for path: %s", path) | ||
| files = rignore.walk( | ||
| def _rignore_walk(path: Path) -> rignore.Walker: | ||
| return rignore.walk( | ||
| path, | ||
| should_exclude_entry=_should_exclude_entry, | ||
| additional_ignore_paths=[".fastapicloudignore"], | ||
| ignore_hidden=False, | ||
| ) | ||
|
|
||
|
|
||
| def archive(path: Path, tar_path: Path) -> Path: | ||
| logger.debug("Starting archive creation for path: %s", path) | ||
| files = _rignore_walk(path) | ||
|
|
||
| logger.debug("Archive will be created at: %s", tar_path) | ||
|
|
||
| file_count = 0 | ||
|
|
@@ -134,6 +138,20 @@ def archive(path: Path, tar_path: Path) -> Path: | |
| return tar_path | ||
|
|
||
|
|
||
| def _get_large_files(path: Path, threshold_mb: int) -> list[tuple[Path, int]]: | ||
| threshold_bytes = threshold_mb * 1024 * 1024 | ||
| large_files = [] | ||
| files = _rignore_walk(path) | ||
| for filename in files: | ||
| if filename.is_dir(): | ||
| continue | ||
| file_size = filename.stat().st_size | ||
| if file_size > threshold_bytes: | ||
| large_files.append((filename.relative_to(path), file_size)) | ||
|
|
||
| return sorted(large_files, key=lambda x: x[1], reverse=True) | ||
|
|
||
|
|
||
| class Team(BaseModel): | ||
| id: str | ||
| slug: str | ||
|
|
@@ -679,6 +697,14 @@ def deploy( | |
| envvar="FASTAPI_CLOUD_APP_ID", | ||
| ), | ||
| ] = None, | ||
| large_file_threshold: Annotated[ | ||
| int, | ||
| typer.Option( | ||
| help="File size threshold in MB for warning about large files", | ||
| min=1, | ||
| envvar="FASTAPI_CLOUD_LARGE_FILE_THRESHOLD", | ||
| ), | ||
| ] = 10, # 10 MB | ||
| ) -> Any: | ||
| """ | ||
| Deploy a [bold]FastAPI[/bold] app to FastAPI Cloud. 🚀 | ||
|
|
@@ -804,10 +830,32 @@ def deploy( | |
| ) | ||
| raise typer.Exit(1) | ||
|
|
||
| large_files = _get_large_files( | ||
| path_to_deploy, threshold_mb=large_file_threshold | ||
| ) | ||
| if large_files: | ||
| toolkit.print( | ||
| f"⚠️ Some uploaded files are larger than {large_file_threshold} MB ⚖️ :", | ||
| tag="warning", | ||
| ) | ||
| for fname, fsize in large_files[:3]: | ||
| fsize_mb = fsize // (1024 * 1024) | ||
| toolkit.print(f" • {fname} [yellow]({fsize_mb} MB)[/yellow]") | ||
|
Comment on lines
+842
to
+843
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| is_more = len(large_files) > 3 | ||
| if is_more: | ||
| toolkit.print(f" [dim]...and {len(large_files) - 3} more[/dim]") | ||
|
|
||
| large_files_docs_url = "https://fastapicloud.com/docs/fastapi-cloud-cli/deploy/#large-files-warning" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This page doesn't exist yet. We will need to create it first (see corresponding PR in that repo) |
||
| toolkit.print( | ||
| f"Read more: [link={large_files_docs_url}]{large_files_docs_url}[/link]", | ||
| tag="tip", | ||
| ) | ||
| toolkit.print_line() | ||
|
|
||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| logger.debug("Creating archive for deployment") | ||
| archive_path = Path(temp_dir) / "archive.tar" | ||
| archive(path or Path.cwd(), archive_path) | ||
| archive(path_to_deploy, archive_path) | ||
|
|
||
| with ( | ||
| toolkit.progress( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.