Skip to content

Commit

Permalink
don't attempt autoconfig if config is null (#2775)
Browse files Browse the repository at this point in the history
* don't attempt autoconfig if config is null

* quiet

* fixes
  • Loading branch information
dr-bonez authored Nov 6, 2024
1 parent 176b1c9 commit 020268f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions core/startos/src/s9pk/v2/pack.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -295,7 +294,7 @@ impl TryFrom<CliImageConfig> 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)
Expand Down Expand Up @@ -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)]
Expand All @@ -361,7 +358,7 @@ pub enum ImageSource {
dockerfile: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")]
#[ts(optional)]
build_args: Option<BTreeMap<String, BuildArg>>
build_args: Option<BTreeMap<String, BuildArg>>,
},
DockerTag(String),
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -580,7 +580,7 @@ fn tar2sqfs(dest: impl AsRef<Path>) -> Result<Command, Error> {
#[cfg(target_os = "linux")]
{
let mut command = Command::new("tar2sqfs");
command.arg(&dest);
command.arg("-q").arg(&dest);
command
}
#[cfg(target_os = "macos")]
Expand Down
143 changes: 74 additions & 69 deletions core/startos/src/version/v0_3_6_alpha_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<MultiCursorFile>,
> = 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::<serde_json::Value>(
&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 archive: MerkleArchive<
crate::s9pk::merkle_archive::source::Section<MultiCursorFile>,
> = match get_archive.await {
Ok(a) => a,
Err(e) => {
tracing::error!("Error opening s9pk for install: {e}");
tracing::debug!("{e:?}");
continue;
}
};

let mut manifest = previous_manifest.clone();
let previous_manifest: Value = serde_json::from_slice::<serde_json::Value>(
&archive
.contents()
.get_path("manifest.json")
.or_not_found("manifest.json")?
.read_file_to_vec()
.await?,
)
.with_kind(ErrorKind::Deserialization)?
.into();

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 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?;
}
}
}

Expand Down

0 comments on commit 020268f

Please sign in to comment.