Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 20 additions & 92 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ indexmap = "2.5"
oci-client = { version = "0.17", default-features = false, features = [
"rustls-tls",
] }
oci-wasm = { version = "0.5", default-features = false, features = [
oci-wasm = { version = "0.6", default-features = false, features = [
"rustls-tls",
] }
petgraph = "0.8.3"
Expand Down
29 changes: 21 additions & 8 deletions crates/wasm-pkg-client/src/oci/publisher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use std::collections::BTreeMap;

use oci_client::{Reference, RegistryOperation};
use oci_client::{
Reference, RegistryOperation,
annotations::{
ORG_OPENCONTAINERS_IMAGE_AUTHORS, ORG_OPENCONTAINERS_IMAGE_DESCRIPTION,
ORG_OPENCONTAINERS_IMAGE_LICENSES, ORG_OPENCONTAINERS_IMAGE_SOURCE,
ORG_OPENCONTAINERS_IMAGE_TITLE, ORG_OPENCONTAINERS_IMAGE_URL,
ORG_OPENCONTAINERS_IMAGE_VERSION,
},
};
use tokio::io::AsyncReadExt;

use crate::publisher::PackagePublisher;
Expand All @@ -26,39 +34,44 @@ impl PackagePublisher for OciBackend {
crate::Error::InvalidComponent(anyhow::anyhow!("Unable to parse WASM: {e}"))
})?;
let meta = payload.metadata();
let (config, layer) = oci_wasm::WasmConfig::from_raw_component(buf, None)
let (config, mut layer) = oci_wasm::WasmConfig::from_raw_component(buf, None)
.map_err(crate::Error::InvalidComponent)?;
// Set the layer title so OCI tools can name the file on disk
layer.annotations = Some(BTreeMap::from_iter([(
ORG_OPENCONTAINERS_IMAGE_TITLE.to_string(),
format!("{}.wasm", package.name()),
)]));
let mut annotations = BTreeMap::from_iter([(
"org.opencontainers.image.version".to_string(),
ORG_OPENCONTAINERS_IMAGE_VERSION.to_string(),
version.to_string(),
)]);
if let Some(desc) = &meta.description {
annotations.insert(
"org.opencontainers.image.description".to_string(),
ORG_OPENCONTAINERS_IMAGE_DESCRIPTION.to_string(),
desc.to_string(),
);
}
if let Some(licenses) = &meta.licenses {
annotations.insert(
"org.opencontainers.image.licenses".to_string(),
ORG_OPENCONTAINERS_IMAGE_LICENSES.to_string(),
licenses.to_string(),
);
}
if let Some(source) = &meta.source {
annotations.insert(
"org.opencontainers.image.source".to_string(),
ORG_OPENCONTAINERS_IMAGE_SOURCE.to_string(),
source.to_string(),
);
}
if let Some(homepage) = &meta.homepage {
annotations.insert(
"org.opencontainers.image.url".to_string(),
ORG_OPENCONTAINERS_IMAGE_URL.to_string(),
homepage.to_string(),
);
}
if let Some(authors) = &meta.authors {
annotations.insert(
"org.opencontainers.image.authors".to_string(),
ORG_OPENCONTAINERS_IMAGE_AUTHORS.to_string(),
authors.to_string(),
);
}
Expand Down
15 changes: 14 additions & 1 deletion crates/wkg/src/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::{Args, Subcommand};
use docker_credential::DockerCredential;
use oci_client::{
Reference,
annotations::ORG_OPENCONTAINERS_IMAGE_TITLE,
client::{ClientConfig, ClientProtocol, PushResponse},
secrets::RegistryAuth,
};
Expand Down Expand Up @@ -146,10 +147,22 @@ fn parse_key_val(s: &str) -> anyhow::Result<(String, String)> {
impl PushArgs {
pub async fn run(self) -> anyhow::Result<()> {
let client = get_client(self.common);
let (conf, layer) = WasmConfig::from_component(&self.file, self.author)
let (conf, mut layer) = WasmConfig::from_component(&self.file, self.author)
.await
.context("Unable to parse component")?;

let title = self
.file
.file_name()
.map(|n| n.to_string_lossy().into_owned())
.unwrap_or_else(|| format!("{}.wasm", self.reference.repository().replace('/', "_")));
// Set the layer title so OCI tools can name the file on disk
// TODO: unify with OciBackend::publish
layer.annotations = Some(std::collections::BTreeMap::from_iter([(
ORG_OPENCONTAINERS_IMAGE_TITLE.to_string(),
title,
)]));

let annotations = match self.annotation.len() {
0 => None,
_ => Some(self.annotation.into_iter().collect()),
Expand Down
Loading