From 8e0db2705fd9cea06e1cf03405dfd00b99ac2674 Mon Sep 17 00:00:00 2001 From: Jade <2364004+Blu-J@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:38:24 -0600 Subject: [PATCH] Fix/mac start cli packing (#2767) * wip * wip: Adding more of the docker for the mac build * fix: Running a build * chore: Make the code a little cleaner * optimize: reduce docker image size for mac-tar2sqfs * feat: Update sdk-utils container usage and Dockerfile * feat: Publish SDK Utils Container image * clean up ... * feat: Add manual input to control tagging Docker image as 'latest' * fix: Update workflow input handling * switch to different repo and clean --------- Co-authored-by: Mariusz Kogen Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> --- core/startos/src/s9pk/v2/pack.rs | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/core/startos/src/s9pk/v2/pack.rs b/core/startos/src/s9pk/v2/pack.rs index 27cad6e92..1911152c4 100644 --- a/core/startos/src/s9pk/v2/pack.rs +++ b/core/startos/src/s9pk/v2/pack.rs @@ -62,9 +62,7 @@ impl SqfsDir { let guid = Guid::new(); let path = self.tmpdir.join(guid.as_ref()).with_extension("squashfs"); if self.path.extension().and_then(|s| s.to_str()) == Some("tar") { - Command::new("tar2sqfs") - .arg("-q") - .arg(&path) + tar2sqfs(&self.path)? .input(Some(&mut open_file(&self.path).await?)) .invoke(ErrorKind::Filesystem) .await?; @@ -553,7 +551,7 @@ impl ImageSource { Command::new(CONTAINER_TOOL) .arg("export") .arg(container.trim()) - .pipe(Command::new("tar2sqfs").arg("-q").arg(&dest)) + .pipe(&mut tar2sqfs(&dest)?) .capture(false) .invoke(ErrorKind::Docker) .await?; @@ -575,6 +573,38 @@ impl ImageSource { } } +fn tar2sqfs(dest: impl AsRef) -> Result { + let dest = dest.as_ref(); + + Ok({ + #[cfg(target_os = "linux")] + { + let mut command = Command::new("tar2sqfs"); + command.arg(&dest); + command + } + #[cfg(target_os = "macos")] + { + let directory = dest + .parent() + .unwrap_or_else(|| Path::new("/")) + .to_path_buf(); + let mut command = Command::new(CONTAINER_TOOL); + command + .arg("run") + .arg("-i") + .arg("--rm") + .arg("-v") + .arg(format!("{}:/data:rw", directory.display())) + .arg("ghcr.io/start9labs/sdk/utils:latest") + .arg("tar2sqfs") + .arg("-q") + .arg(Path::new("/data").join(&dest.file_name().unwrap_or_default())); + command + } + }) +} + #[derive(Debug, Clone, Deserialize, Serialize, TS)] #[serde(rename_all = "camelCase")] #[ts(export)]