diff --git a/Cargo.lock b/Cargo.lock index 2e0d7a9ce..ed193980b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2910,6 +2910,8 @@ dependencies = [ [[package]] name = "oci-wasm" version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91502e5352f927156f2b6a28d2558cc59558b1f441b681df3f706ced6937e07" dependencies = [ "anyhow", "chrono", diff --git a/crates/oci-tar-builder/Cargo.toml b/crates/oci-tar-builder/Cargo.toml index e9b0442c6..cbedd1f4d 100644 --- a/crates/oci-tar-builder/Cargo.toml +++ b/crates/oci-tar-builder/Cargo.toml @@ -18,7 +18,7 @@ serde = { workspace = true } serde_json = { workspace = true } clap = { version = "4.5.7", features = ["derive"] } indexmap = "2.2.6" -oci-wasm = { path = "../../../rust-oci-wasm/" } +oci-wasm = "0.0.4" tokio = { version = "1.38.0", features = [ "full" ] } [lib] diff --git a/crates/oci-tar-builder/src/lib.rs b/crates/oci-tar-builder/src/lib.rs index 6e07f1338..16d61065c 100644 --- a/crates/oci-tar-builder/src/lib.rs +++ b/crates/oci-tar-builder/src/lib.rs @@ -13,16 +13,17 @@ use oci_spec::image::{ use oci_wasm::{WasmConfig, WASM_ARCHITECTURE}; use serde::Serialize; use sha256::{digest, try_digest}; -#[derive(Debug, Default)] +#[derive(Debug)] pub struct Builder { configs: Vec<(C, String, MediaType)>, layers: Vec<(PathBuf, String)>, } -pub trait OciConfig: ToString { +pub trait OciConfig { fn os(&self) -> String; fn architecture(&self) -> String; fn layers(&self) -> Vec; + fn to_string(&self) -> String; } impl OciConfig for ImageConfiguration { @@ -37,6 +38,10 @@ impl OciConfig for ImageConfiguration { fn layers(&self) -> Vec { self.rootfs().diff_ids().to_vec() } + + fn to_string(&self) -> String { + self.to_string_pretty().unwrap() + } } impl OciConfig for WasmConfig { @@ -51,6 +56,28 @@ impl OciConfig for WasmConfig { fn layers(&self) -> Vec { self.layer_digests.clone() } + + fn to_string(&self) -> String { + serde_json::to_string_pretty(self).unwrap() + } +} + +impl Default for Builder { + fn default() -> Self { + Self { + configs: Vec::new(), + layers: Vec::new(), + } + } +} + +impl Default for Builder { + fn default() -> Self { + Self { + configs: Vec::new(), + layers: Vec::new(), + } + } } #[derive(Serialize, Debug)] @@ -79,8 +106,6 @@ struct DockerManifest { pub const WASM_LAYER_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.wasm.component.layer.v0+wasm"; -pub const WASM_ARTIFACT_LAYER: &str = "application/wasm"; -pub const WASM_ARTIFACT_TYPE: &str = "application/vnd.wasm.config.v0+json"; impl Builder { pub fn add_config(&mut self, config: C, name: String, media_type: MediaType) -> &mut Self { diff --git a/crates/wasi-demo-app/build.rs b/crates/wasi-demo-app/build.rs index 70a336691..5b85b159a 100644 --- a/crates/wasi-demo-app/build.rs +++ b/crates/wasi-demo-app/build.rs @@ -59,6 +59,7 @@ fn main() { builder.add_config( img, "ghcr.io/containerd/runwasi/wasi-demo-app:latest".to_string(), + spec::MediaType::ImageConfig, ); let f = File::create(&p).unwrap();