From 614a3bc305c80eb1bf2d8fb1fc65d4232234c049 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 12 Aug 2023 21:29:24 +0200 Subject: [PATCH] feat(rust-publish): with rust publish Signed-off-by: kjuulh --- crates/dagger-rust/src/lib.rs | 1 + crates/dagger-rust/src/publish.rs | 38 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 crates/dagger-rust/src/publish.rs diff --git a/crates/dagger-rust/src/lib.rs b/crates/dagger-rust/src/lib.rs index a6df437..4412e33 100644 --- a/crates/dagger-rust/src/lib.rs +++ b/crates/dagger-rust/src/lib.rs @@ -1,3 +1,4 @@ pub mod build; +pub mod publish; pub mod source; pub mod test; diff --git a/crates/dagger-rust/src/publish.rs b/crates/dagger-rust/src/publish.rs new file mode 100644 index 0000000..505976b --- /dev/null +++ b/crates/dagger-rust/src/publish.rs @@ -0,0 +1,38 @@ +use std::sync::Arc; + +pub struct RustPublish { + client: Arc, +} + +impl RustPublish { + pub fn new(client: Arc) -> Self { + Self { client } + } + + pub async fn publish( + &self, + image: impl Into, + tag: impl Into, + containers: impl IntoIterator, + ) -> 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), + }, + ) + .await?; + println!("published: {}", image); + + Ok(()) + } +}