From 90541412a53f553888a4e312db70b7025ce34945 Mon Sep 17 00:00:00 2001 From: Vim Wickramasinghe Date: Tue, 30 Dec 2025 18:00:53 +0100 Subject: [PATCH 1/2] [TOW-1316] Validate 50MB Limit for deploymentpackage size --- crates/tower-cmd/src/util/deploy.rs | 11 ++++++- crates/tower-package/src/lib.rs | 4 +++ crates/tower-runtime/tests/local_test.rs | 2 +- crates/tower-telemetry/src/logging.rs | 40 +++++++++++++----------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/crates/tower-cmd/src/util/deploy.rs b/crates/tower-cmd/src/util/deploy.rs index 4488c39d..d30a77e6 100644 --- a/crates/tower-cmd/src/util/deploy.rs +++ b/crates/tower-cmd/src/util/deploy.rs @@ -33,7 +33,16 @@ pub async fn upload_file_with_progress( let metadata = file.metadata().await?; let file_size = metadata.len(); - // Create a stream with progress tracking + // Check if bundle size exceeds the maximum allowed size + if file_size > tower_package::MAX_BUNDLE_SIZE { + let size_mb = file_size as f64 / (1024.0 * 1024.0); + let max_mb = tower_package::MAX_BUNDLE_SIZE as f64 / (1024.0 * 1024.0); + output::die(&format!( + "Bundle size ({:.2} MB) exceeds maximum allowed size ({:.0} MB). Please reduce your bundle size by removing unnecessary files or import_paths in the Towerfile.", + size_mb, max_mb + )); + } + let reader_stream = ReaderStream::new(file); let progress_stream = util::progress::ProgressStream::new(reader_stream, file_size, progress_cb).await?; diff --git a/crates/tower-package/src/lib.rs b/crates/tower-package/src/lib.rs index b2a8f6a1..c32ae959 100644 --- a/crates/tower-package/src/lib.rs +++ b/crates/tower-package/src/lib.rs @@ -29,6 +29,10 @@ pub use error::Error; // 3 - Change checksum algorithm to be cross-platform const CURRENT_PACKAGE_VERSION: i32 = 3; +// Maximum allowed size for a bundle package in bytes (50MB) +// This limit ensures bundles remain manageable for deployment and storage. +pub const MAX_BUNDLE_SIZE: u64 = 50 * 1024 * 1024; + #[derive(Clone, Serialize, Deserialize, Debug)] pub struct Parameter { pub name: String, diff --git a/crates/tower-runtime/tests/local_test.rs b/crates/tower-runtime/tests/local_test.rs index e803ff2f..d8ee4a6d 100644 --- a/crates/tower-runtime/tests/local_test.rs +++ b/crates/tower-runtime/tests/local_test.rs @@ -56,7 +56,7 @@ async fn test_running_hello_world_json_logs() { secrets: HashMap::new(), parameters: HashMap::new(), env_vars: HashMap::new(), - cache_dir: Some(config::default_cache_dir()) + cache_dir: Some(config::default_cache_dir()), }; // Start the app using the LocalApp runtime diff --git a/crates/tower-telemetry/src/logging.rs b/crates/tower-telemetry/src/logging.rs index c80b4464..7c16fd48 100644 --- a/crates/tower-telemetry/src/logging.rs +++ b/crates/tower-telemetry/src/logging.rs @@ -183,22 +183,26 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL match destination { LogDestination::Stdout => match format { - LogFormat::Plain => Box::new(fmt::layer().event_format( - fmt::format() - .pretty() - .with_target(false) - .with_file(false) - .with_line_number(false) - .with_ansi(use_color) - )), - LogFormat::Json => Box::new(fmt::layer().event_format( - fmt::format() - .json() - .with_target(false) - .with_file(false) - .with_line_number(false) - .with_ansi(use_color) - )), + LogFormat::Plain => Box::new( + fmt::layer().event_format( + fmt::format() + .pretty() + .with_target(false) + .with_file(false) + .with_line_number(false) + .with_ansi(use_color), + ), + ), + LogFormat::Json => Box::new( + fmt::layer().event_format( + fmt::format() + .json() + .with_target(false) + .with_file(false) + .with_line_number(false) + .with_ansi(use_color), + ), + ), }, LogDestination::File(path) => { let file_appender = tracing_appender::rolling::daily(".", path); @@ -211,7 +215,7 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL .with_target(false) .with_file(false) .with_line_number(false) - .with_ansi(use_color) + .with_ansi(use_color), ) .with_writer(file_appender), ), @@ -223,7 +227,7 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL .with_target(false) .with_file(false) .with_line_number(false) - .with_ansi(use_color) + .with_ansi(use_color), ) .with_writer(file_appender), ), From bc54840fbf4ddba72aca0807d5c26f11c264a390 Mon Sep 17 00:00:00 2001 From: Vim Wickramasinghe Date: Wed, 31 Dec 2025 13:20:08 +0100 Subject: [PATCH 2/2] Review --- crates/tower-cmd/src/util/deploy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tower-cmd/src/util/deploy.rs b/crates/tower-cmd/src/util/deploy.rs index d30a77e6..ad995887 100644 --- a/crates/tower-cmd/src/util/deploy.rs +++ b/crates/tower-cmd/src/util/deploy.rs @@ -38,7 +38,7 @@ pub async fn upload_file_with_progress( let size_mb = file_size as f64 / (1024.0 * 1024.0); let max_mb = tower_package::MAX_BUNDLE_SIZE as f64 / (1024.0 * 1024.0); output::die(&format!( - "Bundle size ({:.2} MB) exceeds maximum allowed size ({:.0} MB). Please reduce your bundle size by removing unnecessary files or import_paths in the Towerfile.", + "Your App is too big! ({:.2} MB) exceeds maximum allowed size ({:.0} MB). Please consider reducing app size by removing unnecessary files or import_paths in the Towerfile.", size_mb, max_mb )); }