forked from github-starred/komodo
* update easy deps * update otel deps * implement template in types + update resource meta * ts types * dev-2 * dev-3 default template query is include * Toggle resource is template in resource header * dev-4 support CopyServer * gen ts * style template selector in New Resource menu * fix new menu show 0 * add template market in omni search bar * fix some dynamic import behavior * template badge on dashboard * dev-5 * standardize interpolation methods with nice api * core use new interpolation methods * refactor git usage * dev-6 refactor interpolation / git methods * fix pull stack passed replacers * new types * remove redundant interpolation for build secret args * clean up periphery docker client * dev-7 include ports in container summary, see if they actually come through * show container ports in container table * refresh processes without tasks (more efficient) * dev-8 keep container stats cache, include with ContainerListItem * gen types * display more container ports * dev-9 fix repo clone when repo doesn't exist initially * Add ports display to more spots * fix function name * add Periphery full container stats api, may be used later * server container stats list * dev-10 * 1.18.4 release * Use reset instead of invalidate to fix GetUser spam on token expiry (#618) --------- Co-authored-by: Jacky Fong <hello@huzky.dev>
68 lines
1.8 KiB
Rust
68 lines
1.8 KiB
Rust
use std::path::{Path, PathBuf};
|
|
|
|
use anyhow::Context;
|
|
use formatting::format_serror;
|
|
use komodo_client::entities::{EnvironmentVar, update::Log};
|
|
|
|
/// If the environment was written and needs to be passed to the compose command,
|
|
/// will return the env file PathBuf.
|
|
/// Should ensure all logs are successful after calling.
|
|
pub async fn write_env_file(
|
|
environment: &[EnvironmentVar],
|
|
folder: &Path,
|
|
env_file_path: &str,
|
|
logs: &mut Vec<Log>,
|
|
) -> Option<PathBuf> {
|
|
let env_file_path =
|
|
folder.join(env_file_path).components().collect::<PathBuf>();
|
|
|
|
if environment.is_empty() {
|
|
// Still want to return Some(env_file_path) if the path
|
|
// already exists on the host and is a file.
|
|
// This is for "Files on Server" mode when user writes the env file themself.
|
|
if env_file_path.is_file() {
|
|
return Some(env_file_path);
|
|
}
|
|
return None;
|
|
}
|
|
|
|
let contents = environment
|
|
.iter()
|
|
.map(|env| format!("{}={}", env.variable, env.value))
|
|
.collect::<Vec<_>>()
|
|
.join("\n");
|
|
|
|
if let Some(parent) = env_file_path.parent() {
|
|
if let Err(e) = tokio::fs::create_dir_all(parent)
|
|
.await
|
|
.with_context(|| format!("Failed to initialize environment file parent directory {parent:?}"))
|
|
{
|
|
logs.push(Log::error(
|
|
"Write Environment File",
|
|
format_serror(&e.into()),
|
|
));
|
|
return None;
|
|
}
|
|
}
|
|
|
|
if let Err(e) = tokio::fs::write(&env_file_path, contents)
|
|
.await
|
|
.with_context(|| {
|
|
format!("Failed to write environment file to {env_file_path:?}")
|
|
})
|
|
{
|
|
logs.push(Log::error(
|
|
"Write Environment File",
|
|
format_serror(&e.into()),
|
|
));
|
|
return None;
|
|
}
|
|
|
|
logs.push(Log::simple(
|
|
"Write Environment File",
|
|
format!("Environment file written to {env_file_path:?}"),
|
|
));
|
|
|
|
Some(env_file_path)
|
|
}
|