Skip to content

Commit

Permalink
Remove direct interactions with env vars for fields in config, use up…
Browse files Browse the repository at this point in the history
…date_env() instead
  • Loading branch information
gememma committed Jan 14, 2025
1 parent 16d7df1 commit 2aa9588
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mirrord/cli/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ pub(crate) async fn container_command(
(CONTAINER_EXECUTION_KIND as u32).to_string(),
);

// LayerConfig must be created after setting relevant env vars
let (mut config, mut analytics) = create_config_and_analytics(&mut progress, watch)?;

let (_internal_proxy_tls_guards, _external_proxy_tls_guards) =
Expand Down Expand Up @@ -427,6 +428,7 @@ pub(crate) async fn container_ext_command(
env.insert("MIRRORD_IMPERSONATED_TARGET".into(), target.to_string());
}

// LayerConfig must be created after setting relevant env vars
let (mut config, mut analytics) = create_config_and_analytics(&mut progress, watch)?;

let (_internal_proxy_tls_guards, _external_proxy_tls_guards) =
Expand Down
7 changes: 3 additions & 4 deletions mirrord/cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,9 @@ impl MirrordExecution {
})?;

// Provide details for layer to connect to agent via internal proxy
env_vars.insert(
MIRRORD_CONNECT_TCP_ENV.to_string(),
format!("127.0.0.1:{}", address.port()),
);
let mut config = config.clone();
config.connect_tcp = Some(format!("127.0.0.1:{}", address.port()));
config.update_env()?;

// Fixes <https://github.com/metalbear-co/mirrord/issues/1745>
// by disabling the fork safety check in the Objective-C runtime.
Expand Down
2 changes: 2 additions & 0 deletions mirrord/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ async fn exec(args: &ExecArgs, watch: drain::Watch) -> CliResult<()> {
std::env::set_var(name, value);
}

// LayerConfig must be created after setting relevant env vars
let (config, mut context) = LayerConfig::from_env_with_warnings()?;

let mut analytics = AnalyticsReporter::only_error(config.telemetry, Default::default(), watch);
Expand Down Expand Up @@ -472,6 +473,7 @@ async fn port_forward(args: &PortForwardArgs, watch: drain::Watch) -> CliResult<
std::env::set_var("MIRRORD_CONFIG_FILE", config_file);
}

// LayerConfig must be created after setting relevant env vars
let (config, mut context) = LayerConfig::from_env_with_warnings()?;

let mut analytics = AnalyticsReporter::new(config.telemetry, ExecutionKind::PortForward, watch);
Expand Down
5 changes: 5 additions & 0 deletions mirrord/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ impl LayerConfig {
Ok(BASE64_STANDARD.encode(serialized))
}

pub fn update_env(&self) -> Result<(), ConfigError> {
std::env::set_var(MIRRORD_RESOLVED_CONFIG_ENV, self.to_env_var()?);
Ok(())
}

/// Generate a config from the environment variables and/or a config file.
/// On success, returns the config and a vec of warnings.
/// To be used from CLI to verify config and print warnings
Expand Down

0 comments on commit 2aa9588

Please sign in to comment.