Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit a3c1655

Browse files
devignedjsturtevant
authored andcommitted
add more reasonable config values and artifactType
Signed-off-by: David Justice <david@devigned.com>
1 parent c8f9e94 commit a3c1655

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/server/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional
3434
diesel_json = { workspace = true, optional = true}
3535
diesel_migrations = { workspace = true, optional = true }
3636
diesel-derive-enum = { workspace = true, optional = true, features = ["postgres"] }
37-
serde_json = { workspace = true, optional = true }
37+
serde_json = { workspace = true }
3838
chrono = { workspace = true, optional = true }
39-
oci-distribution = { git = "https://github.com/krustlet/oci-distribution", branch = "main" }
39+
oci-distribution = { git = "https://github.com/devigned/oci-distribution", branch = "os-wasi" }
4040

4141
[features]
4242
default = []
43-
debug = []
44-
postgres = ["diesel", "diesel-async", "diesel_json", "diesel_migrations", "diesel-derive-enum", "serde_json", "chrono"]
43+
postgres = ["diesel", "diesel-async", "diesel_json", "diesel_migrations", "diesel-derive-enum", "chrono"]

crates/server/src/contentstore/oci/client.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use oci_distribution::{
99
Reference,
1010
secrets::RegistryAuth,
1111
};
12+
use oci_distribution::config::{Architecture, ConfigFile, Config as DistConfig, Os};
13+
use serde_json;
1214
use tokio::fs::File;
1315
use tokio::io::{AsyncReadExt, AsyncWriteExt};
1416
use tokio::runtime::Handle;
@@ -22,8 +24,9 @@ use crate::{
2224
contentstore::ContentStoreError::ContentStoreInternalError,
2325
};
2426

25-
// const COMPONENT_CONFIG_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.component.v1+config";
26-
const WASM_LAYER_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.wasm.content.layer.v1+wasm";
27+
const COMPONENT_ARTIFACT_TYPE: &str = "application/vnd.bytecodealliance.component.v1+wasm";
28+
const WASM_LAYER_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.wasm.component.layer.v0+wasm";
29+
// const COMPONENT_COMPOSE_MANIFEST_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.component.compose.v0+yaml";
2730

2831
/// Client for interacting with an OCI registry
2932
pub struct Client {
@@ -99,24 +102,36 @@ impl Client {
99102
&self,
100103
reference: impl AsRef<str>,
101104
file: &mut File,
102-
_digest: &AnyHash,
105+
digest: &AnyHash,
103106
) -> Result<String, ContentStoreError> {
104107
let reference: Reference = reference
105108
.as_ref()
106109
.parse()
107110
.with_context(|| format!("cannot parse reference {}", reference.as_ref()))
108111
.map_err(|e| ContentStoreInternalError(e.to_string()))?;
109112

110-
let oci_config = Config::oci_v1("{}".as_bytes().to_vec(), None);
113+
let entrypoint = format!("/{}", digest.to_string().strip_prefix("sha256:").unwrap());
114+
let config = ConfigFile {
115+
architecture: Architecture::Wasm,
116+
os: Os::Wasi,
117+
config: Some(DistConfig {
118+
// use the sha256 hash as the file name for the entrypoint
119+
entrypoint: vec![entrypoint],
120+
..Default::default()
121+
}),
122+
..Default::default()
123+
};
124+
let config_data = serde_json::to_vec(&config)
125+
.map_err(|e| ContentStoreInternalError(e.to_string()))?;
126+
let oci_config = Config::oci_v1(config_data, None);
111127
let mut layers = Vec::new();
112128
let wasm_layer = Self::wasm_layer(file)
113129
.await
114130
.context("cannot create wasm layer")
115131
.map_err(|e| ContentStoreInternalError(e.to_string()))?;
116132
layers.insert(0, wasm_layer);
117-
let manifest = OciImageManifest::build(&layers, &oci_config, None);
118-
// TODO: add artifactType to describe the mediaType for the component.
119-
// Candidate mediaType: "application/vnd.bytecodealliance.wasm.component.v1+config"
133+
let mut manifest = OciImageManifest::build(&layers, &oci_config, None);
134+
manifest.artifact_type = Some(COMPONENT_ARTIFACT_TYPE.to_string());
120135

121136
// TODO: fix the higher-level lifetime error that occurs when not using block_in_place and
122137
// block_on.

0 commit comments

Comments
 (0)