From 020268fe67cf996ac1fe20cd05849a53bf0df91b Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:38:30 -0700 Subject: [PATCH] don't attempt autoconfig if config is null (#2775) * don't attempt autoconfig if config is null * quiet * fixes --- .../Systems/SystemForEmbassy/index.ts | 1 + core/startos/src/s9pk/v2/pack.rs | 24 +-- core/startos/src/version/v0_3_6_alpha_8.rs | 143 +++++++++--------- 3 files changed, 87 insertions(+), 81 deletions(-) diff --git a/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts b/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts index b33e83c0f..b01ca2dc1 100644 --- a/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts +++ b/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts @@ -929,6 +929,7 @@ export class SystemForEmbassy implements System { this.dependenciesAutoconfig(effects, id, timeoutMs) }, })) as U.Config + if (!oldConfig) return const moduleCode = await this.moduleCode const method = moduleCode.dependencies?.[id]?.autoConfigure if (!method) return diff --git a/core/startos/src/s9pk/v2/pack.rs b/core/startos/src/s9pk/v2/pack.rs index 1911152c4..67be558f1 100644 --- a/core/startos/src/s9pk/v2/pack.rs +++ b/core/startos/src/s9pk/v2/pack.rs @@ -1,5 +1,4 @@ -use std::collections::BTreeMap; -use std::collections::BTreeSet; +use std::collections::{BTreeMap, BTreeSet}; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -295,7 +294,7 @@ impl TryFrom for ImageConfig { ImageSource::DockerBuild { dockerfile: value.dockerfile, workdir: value.workdir, - build_args: None + build_args: None, } } else if let Some(tag) = value.docker_tag { ImageSource::DockerTag(tag) @@ -345,9 +344,7 @@ impl clap::FromArgMatches for ImageConfig { #[ts(export)] pub enum BuildArg { String(String), - EnvVar { - env: String, - }, + EnvVar { env: String }, } #[derive(Debug, Clone, Deserialize, Serialize, TS)] @@ -361,7 +358,7 @@ pub enum ImageSource { dockerfile: Option, #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional)] - build_args: Option> + build_args: Option>, }, DockerTag(String), } @@ -400,7 +397,7 @@ impl ImageSource { ImageSource::DockerBuild { workdir, dockerfile, - build_args + build_args, } => { let workdir = workdir.as_deref().unwrap_or(Path::new(".")); let dockerfile = dockerfile @@ -424,7 +421,8 @@ impl ImageSource { .arg("-t") .arg(&tag) .arg(&docker_platform) - .arg("--build-arg").arg(format!("ARCH={}", arch)); + .arg("--build-arg") + .arg(format!("ARCH={}", arch)); // add build arguments if let Some(build_args) = build_args { @@ -436,10 +434,12 @@ impl ImageSource { Ok(val) => val, Err(_) => continue, // skip if env var not set or invalid } - }, + } }; - command.arg("--build-arg").arg(format!("{}={}", key, build_arg_value)); + command + .arg("--build-arg") + .arg(format!("{}={}", key, build_arg_value)); } } @@ -580,7 +580,7 @@ fn tar2sqfs(dest: impl AsRef) -> Result { #[cfg(target_os = "linux")] { let mut command = Command::new("tar2sqfs"); - command.arg(&dest); + command.arg("-q").arg(&dest); command } #[cfg(target_os = "macos")] diff --git a/core/startos/src/version/v0_3_6_alpha_8.rs b/core/startos/src/version/v0_3_6_alpha_8.rs index b23c205e8..fcef96a69 100644 --- a/core/startos/src/version/v0_3_6_alpha_8.rs +++ b/core/startos/src/version/v0_3_6_alpha_8.rs @@ -3,15 +3,15 @@ use tokio::fs::File; use super::v0_3_5::V0_3_0_COMPAT; use super::{v0_3_6_alpha_7, VersionT}; +use crate::install::PKG_ARCHIVE_DIR; +use crate::prelude::*; use crate::s9pk::manifest::{DeviceFilter, Manifest}; +use crate::s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile; use crate::s9pk::merkle_archive::MerkleArchive; use crate::s9pk::v2::SIG_CONTEXT; use crate::s9pk::S9pk; +use crate::service::LoadDisposition; use crate::util::io::create_file; -use crate::{ - install::PKG_ARCHIVE_DIR, s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile, -}; -use crate::{prelude::*, service::LoadDisposition}; lazy_static::lazy_static! { static ref V0_3_6_alpha_8: exver::Version = exver::Version::new( @@ -42,78 +42,83 @@ impl VersionT for Version { async fn post_up(self, ctx: &crate::context::RpcContext) -> Result<(), Error> { let s9pk_dir = ctx.datadir.join(PKG_ARCHIVE_DIR).join("installed"); - for s9pk_path in s9pk_dir.read_dir()? { - let s9pk_path = s9pk_path?.path(); - let matches_s9pk = s9pk_path.extension().map(|x| x == "s9pk").unwrap_or(false); - if !matches_s9pk { - continue; - } - - let get_archive = async { - let multi_cursor = MultiCursorFile::from(File::open(&s9pk_path).await?); - Ok::<_, Error>(S9pk::archive(&multi_cursor, None).await?) - }; - - let archive: MerkleArchive< - crate::s9pk::merkle_archive::source::Section, - > = match get_archive.await { - Ok(a) => a, - Err(e) => { - tracing::error!("Error opening s9pk for install: {e}"); - tracing::debug!("{e:?}"); + if tokio::fs::metadata(&s9pk_dir).await.is_ok() { + let mut read_dir = tokio::fs::read_dir(&s9pk_dir).await?; + while let Some(s9pk_ent) = read_dir.next_entry().await? { + let s9pk_path = s9pk_ent.path(); + let matches_s9pk = s9pk_path.extension().map(|x| x == "s9pk").unwrap_or(false); + if !matches_s9pk { continue; } - }; - let previous_manifest: Value = serde_json::from_slice::( - &archive - .contents() - .get_path("manifest.json") - .or_not_found("manifest.json")? - .read_file_to_vec() - .await?, - ) - .with_kind(ErrorKind::Deserialization)? - .into(); + let get_archive = async { + let multi_cursor = MultiCursorFile::from(File::open(&s9pk_path).await?); + Ok::<_, Error>(S9pk::archive(&multi_cursor, None).await?) + }; - let mut manifest = previous_manifest.clone(); + let archive: MerkleArchive< + crate::s9pk::merkle_archive::source::Section, + > = match get_archive.await { + Ok(a) => a, + Err(e) => { + tracing::error!("Error opening s9pk for install: {e}"); + tracing::debug!("{e:?}"); + continue; + } + }; - if let Some(device) = previous_manifest["hardwareRequirements"]["device"].as_object() { - manifest["hardwareRequirements"]["device"] = to_value( - &device - .into_iter() - .map(|(class, product)| { - Ok::<_, Error>(DeviceFilter { - pattern_description: format!( - "a {class} device matching the expression {}", - &product - ), - class: class.clone(), - pattern: from_value(product.clone())?, + let previous_manifest: Value = serde_json::from_slice::( + &archive + .contents() + .get_path("manifest.json") + .or_not_found("manifest.json")? + .read_file_to_vec() + .await?, + ) + .with_kind(ErrorKind::Deserialization)? + .into(); + + let mut manifest = previous_manifest.clone(); + + if let Some(device) = + previous_manifest["hardwareRequirements"]["device"].as_object() + { + manifest["hardwareRequirements"]["device"] = to_value( + &device + .into_iter() + .map(|(class, product)| { + Ok::<_, Error>(DeviceFilter { + pattern_description: format!( + "a {class} device matching the expression {}", + &product + ), + class: class.clone(), + pattern: from_value(product.clone())?, + }) }) - }) - .fold(Ok::<_, Error>(Vec::new()), |acc, value| { - let mut acc = acc?; - acc.push(value?); - Ok(acc) - })?, - )?; - } + .fold(Ok::<_, Error>(Vec::new()), |acc, value| { + let mut acc = acc?; + acc.push(value?); + Ok(acc) + })?, + )?; + } - if previous_manifest != manifest { - let tmp_path = s9pk_path.with_extension("s9pk.tmp"); - let mut tmp_file = create_file(&tmp_path).await?; - // TODO, wouldn't this break in the later versions of the manifest that would need changes, this doesn't seem to be a good way to handle this - let manifest: Manifest = from_value(manifest.clone())?; - let id = manifest.id.clone(); - let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive, None, manifest); - let s9pk_compat_key = ctx.account.read().await.compat_s9pk_key.clone(); - s9pk.as_archive_mut() - .set_signer(s9pk_compat_key, SIG_CONTEXT); - s9pk.serialize(&mut tmp_file, true).await?; - tmp_file.sync_all().await?; - tokio::fs::rename(&tmp_path, &s9pk_path).await?; - ctx.services.load(ctx, &id, LoadDisposition::Retry).await?; + if previous_manifest != manifest { + let tmp_path = s9pk_path.with_extension("s9pk.tmp"); + let mut tmp_file = create_file(&tmp_path).await?; + // TODO, wouldn't this break in the later versions of the manifest that would need changes, this doesn't seem to be a good way to handle this + let manifest: Manifest = from_value(manifest.clone())?; + let id = manifest.id.clone(); + let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive, None, manifest); + let s9pk_compat_key = ctx.account.read().await.compat_s9pk_key.clone(); + s9pk.as_archive_mut() + .set_signer(s9pk_compat_key, SIG_CONTEXT); + s9pk.serialize(&mut tmp_file, true).await?; + tmp_file.sync_all().await?; + tokio::fs::rename(&tmp_path, &s9pk_path).await?; + ctx.services.load(ctx, &id, LoadDisposition::Retry).await?; + } } }