1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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),
                },
            )
            .await?;
        println!("published: {}", image);

        Ok(())
    }
}