@@ -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;
1214use tokio:: fs:: File ;
1315use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
1416use 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
2932pub 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