Skip to content

Commit 770eef0

Browse files
authored
[TOW-1316] Validate 50MB Limit for deployment package size (#148)
* [TOW-1316] Validate 50MB Limit for deploymentpackage size * Review
1 parent debee84 commit 770eef0

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

crates/tower-cmd/src/util/deploy.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ pub async fn upload_file_with_progress(
3333
let metadata = file.metadata().await?;
3434
let file_size = metadata.len();
3535

36-
// Create a stream with progress tracking
36+
// Check if bundle size exceeds the maximum allowed size
37+
if file_size > tower_package::MAX_BUNDLE_SIZE {
38+
let size_mb = file_size as f64 / (1024.0 * 1024.0);
39+
let max_mb = tower_package::MAX_BUNDLE_SIZE as f64 / (1024.0 * 1024.0);
40+
output::die(&format!(
41+
"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.",
42+
size_mb, max_mb
43+
));
44+
}
45+
3746
let reader_stream = ReaderStream::new(file);
3847
let progress_stream =
3948
util::progress::ProgressStream::new(reader_stream, file_size, progress_cb).await?;

crates/tower-package/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub use error::Error;
2929
// 3 - Change checksum algorithm to be cross-platform
3030
const CURRENT_PACKAGE_VERSION: i32 = 3;
3131

32+
// Maximum allowed size for a bundle package in bytes (50MB)
33+
// This limit ensures bundles remain manageable for deployment and storage.
34+
pub const MAX_BUNDLE_SIZE: u64 = 50 * 1024 * 1024;
35+
3236
#[derive(Clone, Serialize, Deserialize, Debug)]
3337
pub struct Parameter {
3438
pub name: String,

crates/tower-runtime/tests/local_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async fn test_running_hello_world_json_logs() {
5656
secrets: HashMap::new(),
5757
parameters: HashMap::new(),
5858
env_vars: HashMap::new(),
59-
cache_dir: Some(config::default_cache_dir())
59+
cache_dir: Some(config::default_cache_dir()),
6060
};
6161

6262
// Start the app using the LocalApp runtime

crates/tower-telemetry/src/logging.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,26 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL
183183

184184
match destination {
185185
LogDestination::Stdout => match format {
186-
LogFormat::Plain => Box::new(fmt::layer().event_format(
187-
fmt::format()
188-
.pretty()
189-
.with_target(false)
190-
.with_file(false)
191-
.with_line_number(false)
192-
.with_ansi(use_color)
193-
)),
194-
LogFormat::Json => Box::new(fmt::layer().event_format(
195-
fmt::format()
196-
.json()
197-
.with_target(false)
198-
.with_file(false)
199-
.with_line_number(false)
200-
.with_ansi(use_color)
201-
)),
186+
LogFormat::Plain => Box::new(
187+
fmt::layer().event_format(
188+
fmt::format()
189+
.pretty()
190+
.with_target(false)
191+
.with_file(false)
192+
.with_line_number(false)
193+
.with_ansi(use_color),
194+
),
195+
),
196+
LogFormat::Json => Box::new(
197+
fmt::layer().event_format(
198+
fmt::format()
199+
.json()
200+
.with_target(false)
201+
.with_file(false)
202+
.with_line_number(false)
203+
.with_ansi(use_color),
204+
),
205+
),
202206
},
203207
LogDestination::File(path) => {
204208
let file_appender = tracing_appender::rolling::daily(".", path);
@@ -211,7 +215,7 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL
211215
.with_target(false)
212216
.with_file(false)
213217
.with_line_number(false)
214-
.with_ansi(use_color)
218+
.with_ansi(use_color),
215219
)
216220
.with_writer(file_appender),
217221
),
@@ -223,7 +227,7 @@ fn create_fmt_layer(format: LogFormat, destination: LogDestination) -> BoxedFmtL
223227
.with_target(false)
224228
.with_file(false)
225229
.with_line_number(false)
226-
.with_ansi(use_color)
230+
.with_ansi(use_color),
227231
)
228232
.with_writer(file_appender),
229233
),

0 commit comments

Comments
 (0)