Skip to content

Commit 4a90c80

Browse files
committed
feat(push): allow pushing composed components to registry
Signed-off-by: Brian H <brian.hardock@fermyon.com>
1 parent 6571862 commit 4a90c80

File tree

13 files changed

+303
-84
lines changed

13 files changed

+303
-84
lines changed

Diff for: Cargo.lock

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ wasmtime = "25.0.3"
155155
wasmtime-wasi = "25.0.0"
156156
wasmtime-wasi-http = "25.0.0"
157157

158+
wasm-encoder = "0.217"
159+
wasm-metadata = "0.217"
160+
wasmparser = "0.217"
161+
wit-component = "0.217"
162+
wit-parser = "0.217"
163+
158164
spin-componentize = { path = "crates/componentize" }
159165

160166
[workspace.lints.clippy]

Diff for: crates/componentize/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ rust-version.workspace = true
1111
[dependencies]
1212
anyhow = { workspace = true }
1313
tracing = { workspace = true }
14-
wasm-encoder = "0.217"
15-
wasm-metadata = "0.217"
16-
wasmparser = "0.217"
17-
wit-component = "0.217"
18-
wit-parser = "0.217"
14+
wasm-encoder = { workspace = true }
15+
wasm-metadata = { workspace = true }
16+
wasmparser = { workspace = true }
17+
wit-component = { workspace = true }
18+
wit-parser = { workspace = true }
1919

2020
[dev-dependencies]
2121
async-trait = { workspace = true }

Diff for: crates/compose/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ async-trait = { workspace = true }
1414
indexmap = "2"
1515
semver = "1"
1616
spin-app = { path = "../app" }
17+
spin-common = { path = "../common" }
18+
spin-componentize = { path = "../componentize" }
1719
spin-serde = { path = "../serde" }
1820
thiserror = { workspace = true }
21+
tokio = { workspace = true, features = ["fs"] }
1922
wac-graph = "0.6"
2023

2124
[lints]

Diff for: crates/compose/src/lib.rs

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::Context;
22
use indexmap::IndexMap;
33
use semver::Version;
44
use spin_app::locked::{self, InheritConfiguration, LockedComponent, LockedComponentDependency};
5+
use spin_common::{ui::quoted_path, url::parse_file_url};
56
use spin_serde::{DependencyName, KebabId};
67
use std::collections::BTreeMap;
78
use thiserror::Error;
@@ -42,6 +43,36 @@ pub trait ComponentSourceLoader {
4243
) -> anyhow::Result<Vec<u8>>;
4344
}
4445

46+
/// A ComponentSourceLoader that loads component sources from the filesystem.
47+
pub struct ComponentSourceLoaderFs;
48+
49+
#[async_trait::async_trait]
50+
impl ComponentSourceLoader for ComponentSourceLoaderFs {
51+
async fn load_component_source(
52+
&self,
53+
source: &locked::LockedComponentSource,
54+
) -> anyhow::Result<Vec<u8>> {
55+
let source = source
56+
.content
57+
.source
58+
.as_ref()
59+
.context("LockedComponentSource missing source field")?;
60+
61+
let path = parse_file_url(source)?;
62+
63+
let bytes: Vec<u8> = tokio::fs::read(&path).await.with_context(|| {
64+
format!(
65+
"failed to read component source from disk at path {}",
66+
quoted_path(&path)
67+
)
68+
})?;
69+
70+
let component = spin_componentize::componentize_if_necessary(&bytes)?;
71+
72+
Ok(component.into())
73+
}
74+
}
75+
4576
/// Represents an error that can occur when composing dependencies.
4677
#[derive(Debug, Error)]
4778
pub enum ComposeError {

Diff for: crates/oci/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ reqwest = "0.12"
2222
serde = { workspace = true }
2323
serde_json = { workspace = true }
2424
spin-common = { path = "../common" }
25+
spin-compose = { path = "../compose" }
2526
spin-loader = { path = "../loader" }
2627
spin-locked-app = { path = "../locked-app" }
2728
tempfile = { workspace = true }
2829
tokio = { workspace = true, features = ["fs"] }
2930
tokio-util = { version = "0.7", features = ["compat"] }
3031
tracing = { workspace = true }
3132
walkdir = "2"
33+
34+
[dev-dependencies]
35+
wasm-encoder = { workspace = true }
36+
wit-component = { workspace = true, features = ["dummy-module"] }
37+
wit-parser = { workspace = true }

0 commit comments

Comments
 (0)