don't attempt autoconfig if config is null (#2775)

* don't attempt autoconfig if config is null

* quiet

* fixes
This commit is contained in:
Aiden McClelland
2024-11-05 20:38:30 -07:00
committed by GitHub
parent 176b1c9d20
commit 020268fe67
3 changed files with 87 additions and 81 deletions

View File

@@ -929,6 +929,7 @@ export class SystemForEmbassy implements System {
this.dependenciesAutoconfig(effects, id, timeoutMs) this.dependenciesAutoconfig(effects, id, timeoutMs)
}, },
})) as U.Config })) as U.Config
if (!oldConfig) return
const moduleCode = await this.moduleCode const moduleCode = await this.moduleCode
const method = moduleCode.dependencies?.[id]?.autoConfigure const method = moduleCode.dependencies?.[id]?.autoConfigure
if (!method) return if (!method) return

View File

@@ -1,5 +1,4 @@
use std::collections::BTreeMap; use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeSet;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
@@ -295,7 +294,7 @@ impl TryFrom<CliImageConfig> for ImageConfig {
ImageSource::DockerBuild { ImageSource::DockerBuild {
dockerfile: value.dockerfile, dockerfile: value.dockerfile,
workdir: value.workdir, workdir: value.workdir,
build_args: None build_args: None,
} }
} else if let Some(tag) = value.docker_tag { } else if let Some(tag) = value.docker_tag {
ImageSource::DockerTag(tag) ImageSource::DockerTag(tag)
@@ -345,9 +344,7 @@ impl clap::FromArgMatches for ImageConfig {
#[ts(export)] #[ts(export)]
pub enum BuildArg { pub enum BuildArg {
String(String), String(String),
EnvVar { EnvVar { env: String },
env: String,
},
} }
#[derive(Debug, Clone, Deserialize, Serialize, TS)] #[derive(Debug, Clone, Deserialize, Serialize, TS)]
@@ -361,7 +358,7 @@ pub enum ImageSource {
dockerfile: Option<PathBuf>, dockerfile: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[ts(optional)] #[ts(optional)]
build_args: Option<BTreeMap<String, BuildArg>> build_args: Option<BTreeMap<String, BuildArg>>,
}, },
DockerTag(String), DockerTag(String),
} }
@@ -400,7 +397,7 @@ impl ImageSource {
ImageSource::DockerBuild { ImageSource::DockerBuild {
workdir, workdir,
dockerfile, dockerfile,
build_args build_args,
} => { } => {
let workdir = workdir.as_deref().unwrap_or(Path::new(".")); let workdir = workdir.as_deref().unwrap_or(Path::new("."));
let dockerfile = dockerfile let dockerfile = dockerfile
@@ -424,7 +421,8 @@ impl ImageSource {
.arg("-t") .arg("-t")
.arg(&tag) .arg(&tag)
.arg(&docker_platform) .arg(&docker_platform)
.arg("--build-arg").arg(format!("ARCH={}", arch)); .arg("--build-arg")
.arg(format!("ARCH={}", arch));
// add build arguments // add build arguments
if let Some(build_args) = build_args { if let Some(build_args) = build_args {
@@ -436,10 +434,12 @@ impl ImageSource {
Ok(val) => val, Ok(val) => val,
Err(_) => continue, // skip if env var not set or invalid 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<Path>) -> Result<Command, Error> {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
let mut command = Command::new("tar2sqfs"); let mut command = Command::new("tar2sqfs");
command.arg(&dest); command.arg("-q").arg(&dest);
command command
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@@ -3,15 +3,15 @@ use tokio::fs::File;
use super::v0_3_5::V0_3_0_COMPAT; use super::v0_3_5::V0_3_0_COMPAT;
use super::{v0_3_6_alpha_7, VersionT}; 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::manifest::{DeviceFilter, Manifest};
use crate::s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile;
use crate::s9pk::merkle_archive::MerkleArchive; use crate::s9pk::merkle_archive::MerkleArchive;
use crate::s9pk::v2::SIG_CONTEXT; use crate::s9pk::v2::SIG_CONTEXT;
use crate::s9pk::S9pk; use crate::s9pk::S9pk;
use crate::service::LoadDisposition;
use crate::util::io::create_file; 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! { lazy_static::lazy_static! {
static ref V0_3_6_alpha_8: exver::Version = exver::Version::new( 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> { async fn post_up(self, ctx: &crate::context::RpcContext) -> Result<(), Error> {
let s9pk_dir = ctx.datadir.join(PKG_ARCHIVE_DIR).join("installed"); let s9pk_dir = ctx.datadir.join(PKG_ARCHIVE_DIR).join("installed");
for s9pk_path in s9pk_dir.read_dir()? { if tokio::fs::metadata(&s9pk_dir).await.is_ok() {
let s9pk_path = s9pk_path?.path(); let mut read_dir = tokio::fs::read_dir(&s9pk_dir).await?;
let matches_s9pk = s9pk_path.extension().map(|x| x == "s9pk").unwrap_or(false); while let Some(s9pk_ent) = read_dir.next_entry().await? {
if !matches_s9pk { let s9pk_path = s9pk_ent.path();
continue; let matches_s9pk = s9pk_path.extension().map(|x| x == "s9pk").unwrap_or(false);
} if !matches_s9pk {
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; continue;
} }
};
let previous_manifest: Value = serde_json::from_slice::<serde_json::Value>( let get_archive = async {
&archive let multi_cursor = MultiCursorFile::from(File::open(&s9pk_path).await?);
.contents() Ok::<_, Error>(S9pk::archive(&multi_cursor, None).await?)
.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(); 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;
}
};
if let Some(device) = previous_manifest["hardwareRequirements"]["device"].as_object() { let previous_manifest: Value = serde_json::from_slice::<serde_json::Value>(
manifest["hardwareRequirements"]["device"] = to_value( &archive
&device .contents()
.into_iter() .get_path("manifest.json")
.map(|(class, product)| { .or_not_found("manifest.json")?
Ok::<_, Error>(DeviceFilter { .read_file_to_vec()
pattern_description: format!( .await?,
"a {class} device matching the expression {}", )
&product .with_kind(ErrorKind::Deserialization)?
), .into();
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| {
.fold(Ok::<_, Error>(Vec::new()), |acc, value| { let mut acc = acc?;
let mut acc = acc?; acc.push(value?);
acc.push(value?); Ok(acc)
Ok(acc) })?,
})?, )?;
)?; }
}
if previous_manifest != manifest { if previous_manifest != manifest {
let tmp_path = s9pk_path.with_extension("s9pk.tmp"); let tmp_path = s9pk_path.with_extension("s9pk.tmp");
let mut tmp_file = create_file(&tmp_path).await?; 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 // 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 manifest: Manifest = from_value(manifest.clone())?;
let id = manifest.id.clone(); let id = manifest.id.clone();
let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive, None, manifest); let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive, None, manifest);
let s9pk_compat_key = ctx.account.read().await.compat_s9pk_key.clone(); let s9pk_compat_key = ctx.account.read().await.compat_s9pk_key.clone();
s9pk.as_archive_mut() s9pk.as_archive_mut()
.set_signer(s9pk_compat_key, SIG_CONTEXT); .set_signer(s9pk_compat_key, SIG_CONTEXT);
s9pk.serialize(&mut tmp_file, true).await?; s9pk.serialize(&mut tmp_file, true).await?;
tmp_file.sync_all().await?; tmp_file.sync_all().await?;
tokio::fs::rename(&tmp_path, &s9pk_path).await?; tokio::fs::rename(&tmp_path, &s9pk_path).await?;
ctx.services.load(ctx, &id, LoadDisposition::Retry).await?; ctx.services.load(ctx, &id, LoadDisposition::Retry).await?;
}
} }
} }