dagger-components/crates/dagger-rust/src/publish.rs
kjuulh 52914e08e6
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing
feat: with updated dagger-sdk
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-10-21 12:45:33 +02:00

41 lines
1.0 KiB
Rust

use std::sync::Arc;
pub struct RustPublish {
client: Arc<dagger_sdk::Query>,
}
impl RustPublish {
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
Self { client }
}
pub async fn publish(
&self,
image: impl Into<String>,
tag: impl Into<String>,
containers: impl IntoIterator<Item = dagger_sdk::Container>,
) -> eyre::Result<()> {
let mut ids = Vec::new();
for container in containers.into_iter() {
let id = container.id().await?;
ids.push(id);
}
let image = self
.client
.container()
.publish_opts(
format!("{}:{}", image.into(), tag.into()),
dagger_sdk::ContainerPublishOpts {
platform_variants: Some(ids),
forced_compression: None,
media_types: None,
},
)
.await?;
println!("published: {}", image);
Ok(())
}
}