From b2bf8cc2d5da68daec3b2ef768e665606e8913f7 Mon Sep 17 00:00:00 2001 From: Ben Lovell Date: Mon, 8 Jun 2026 19:29:34 +0200 Subject: [PATCH] feat: make TOWER_ENVIRONMENT ordinary passthrough in local runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit make_env_vars injected TOWER_ENVIRONMENT as the last step of building a run's env, unconditionally, so it overwrote any value a caller had already set in the env map. Drop the special case and let the value pass through like any other env var. The local run path now supplies it explicitly from the resolved --environment arg, which defaults to "default" — so a local run with no flag still gets TOWER_ENVIRONMENT=default, as before. The now-unused env parameter and its threading through execute_bash_program go with it. --- crates/tower-cmd/src/run.rs | 1 + crates/tower-runtime/src/local.rs | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/crates/tower-cmd/src/run.rs b/crates/tower-cmd/src/run.rs index 3a3cfa27..19ffdbf7 100644 --- a/crates/tower-cmd/src/run.rs +++ b/crates/tower-cmd/src/run.rs @@ -182,6 +182,7 @@ where env_vars.insert("TOWER_JWT".to_string(), session.token.jwt.to_string()); env_vars.insert("TOWER__RUNTIME__IS_LOCAL".to_string(), "true".to_string()); + env_vars.insert("TOWER_ENVIRONMENT".to_string(), env.to_string()); // Load the Towerfile let towerfile_path = path.join("Towerfile"); diff --git a/crates/tower-runtime/src/local.rs b/crates/tower-runtime/src/local.rs index cafc2bc7..51b0cafa 100644 --- a/crates/tower-runtime/src/local.rs +++ b/crates/tower-runtime/src/local.rs @@ -146,7 +146,6 @@ async fn inner_execute_local_app( ) -> Result { let ctx = opts.ctx.clone(); let package = opts.package; - let environment = opts.environment; let package_path = package.unpacked_path.clone().unwrap().to_path_buf(); // set for later on. @@ -186,7 +185,6 @@ async fn inner_execute_local_app( if is_bash_package(&package) { let child = execute_bash_program( &ctx, - &environment, working_dir, package_path, &manifest, @@ -212,7 +210,6 @@ async fn inner_execute_local_app( let uv = Uv::new(opts.cache_dir, protected_mode).await?; let env_vars = make_env_vars( &ctx, - &environment, &package_path, &secrets, ¶ms, @@ -475,7 +472,6 @@ impl App for LocalApp { async fn execute_bash_program( ctx: &tower_telemetry::Context, - env: &str, cwd: PathBuf, package_path: PathBuf, manifest: &Manifest, @@ -497,7 +493,6 @@ async fn execute_bash_program( .stderr(Stdio::piped()) .envs(make_env_vars( &ctx, - env, &cwd, &secrets, ¶ms, @@ -524,7 +519,6 @@ fn make_env_var_key(src: &str) -> String { fn make_env_vars( ctx: &tower_telemetry::Context, - env: &str, cwd: &PathBuf, secs: &HashMap, params: &HashMap, @@ -566,14 +560,6 @@ fn make_env_vars( .to_string(); res.insert("PYTHONPATH".to_string(), pythonpath); - // Inject a TOWER_ENVIRONMENT parameter so you know what environment you're running in. Empty - // environment is "default" by default. - if env.is_empty() { - res.insert("TOWER_ENVIRONMENT".to_string(), "default".to_string()); - } else { - res.insert("TOWER_ENVIRONMENT".to_string(), env.to_string()); - } - res.insert("PYTHONUNBUFFERED".to_string(), "x".to_string()); res