Skip to content

Commit

Permalink
add more reasonable config values and artifactType
Browse files Browse the repository at this point in the history
Signed-off-by: David Justice <[email protected]>
  • Loading branch information
devigned authored and jsturtevant committed Jul 25, 2023
1 parent acab609 commit 87d6a49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional
diesel_json = { workspace = true, optional = true}
diesel_migrations = { workspace = true, optional = true }
diesel-derive-enum = { workspace = true, optional = true, features = ["postgres"] }
serde_json = { workspace = true, optional = true }
serde_json = { workspace = true }
chrono = { workspace = true, optional = true }
oci-distribution = { git = "https://github.com/krustlet/oci-distribution", branch = "main" }
oci-distribution = { git = "https://github.com/devigned/oci-distribution", branch = "os-wasi" }

[features]
default = []
debug = []
postgres = ["diesel", "diesel-async", "diesel_json", "diesel_migrations", "diesel-derive-enum", "serde_json", "chrono"]
postgres = ["diesel", "diesel-async", "diesel_json", "diesel_migrations", "diesel-derive-enum", "chrono"]
29 changes: 22 additions & 7 deletions crates/server/src/contentstore/oci/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use oci_distribution::{
Reference,
secrets::RegistryAuth,
};
use oci_distribution::config::{Architecture, ConfigFile, Config as DistConfig, Os};
use serde_json;
use tokio::fs::File;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::runtime::Handle;
Expand All @@ -22,8 +24,9 @@ use crate::{
contentstore::ContentStoreError::ContentStoreInternalError,
};

// const COMPONENT_CONFIG_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.component.v1+config";
const WASM_LAYER_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.wasm.content.layer.v1+wasm";
const COMPONENT_ARTIFACT_TYPE: &str = "application/vnd.bytecodealliance.component.v1+wasm";
const WASM_LAYER_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.wasm.component.layer.v0+wasm";
// const COMPONENT_COMPOSE_MANIFEST_MEDIA_TYPE: &str = "application/vnd.bytecodealliance.component.compose.v0+yaml";

/// Client for interacting with an OCI registry
pub struct Client {
Expand Down Expand Up @@ -99,24 +102,36 @@ impl Client {
&self,
reference: impl AsRef<str>,
file: &mut File,
_digest: &AnyHash,
digest: &AnyHash,
) -> Result<String, ContentStoreError> {
let reference: Reference = reference
.as_ref()
.parse()
.with_context(|| format!("cannot parse reference {}", reference.as_ref()))
.map_err(|e| ContentStoreInternalError(e.to_string()))?;

let oci_config = Config::oci_v1("{}".as_bytes().to_vec(), None);
let entrypoint = format!("/{}", digest.to_string().strip_prefix("sha256:").unwrap());
let config = ConfigFile {
architecture: Architecture::Wasm,
os: Os::Wasi,
config: Some(DistConfig {
// use the sha256 hash as the file name for the entrypoint
entrypoint: vec![entrypoint],
..Default::default()
}),
..Default::default()
};
let config_data = serde_json::to_vec(&config)
.map_err(|e| ContentStoreInternalError(e.to_string()))?;
let oci_config = Config::oci_v1(config_data, None);
let mut layers = Vec::new();
let wasm_layer = Self::wasm_layer(file)
.await
.context("cannot create wasm layer")
.map_err(|e| ContentStoreInternalError(e.to_string()))?;
layers.insert(0, wasm_layer);
let manifest = OciImageManifest::build(&layers, &oci_config, None);
// TODO: add artifactType to describe the mediaType for the component.
// Candidate mediaType: "application/vnd.bytecodealliance.wasm.component.v1+config"
let mut manifest = OciImageManifest::build(&layers, &oci_config, None);
manifest.artifact_type = Some(COMPONENT_ARTIFACT_TYPE.to_string());

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

0 comments on commit 87d6a49

Please sign in to comment.