From d7317e5cf34ee84a7b092357f5fbb15cd2bae2e3 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 13 Mar 2023 20:26:13 +0100 Subject: [PATCH] fix: add public tuple field and into func --- .../src/rust/templates/scalar_tmpl.rs | 8 ++- crates/dagger-sdk/examples/iss-30-alt/main.rs | 42 ++++++++++++ crates/dagger-sdk/src/gen.rs | 64 +++++++++++++++---- 3 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 crates/dagger-sdk/examples/iss-30-alt/main.rs diff --git a/crates/dagger-codegen/src/rust/templates/scalar_tmpl.rs b/crates/dagger-codegen/src/rust/templates/scalar_tmpl.rs index 4f9a763..f2380d4 100644 --- a/crates/dagger-codegen/src/rust/templates/scalar_tmpl.rs +++ b/crates/dagger-codegen/src/rust/templates/scalar_tmpl.rs @@ -11,6 +11,12 @@ pub fn render_scalar(t: &FullType) -> eyre::Result { Ok(quote! { #[derive($serialize, $deserialize, PartialEq, Debug, Clone)] - pub struct $(t.name.pipe(|n|format_name(n)))(String); + pub struct $(t.name.pipe(|n|format_name(n)))(pub String); + + impl Into<$(t.name.pipe(|n| format_name(n)))> for &str { + fn into(self) -> $(t.name.pipe(|n| format_name(n))) { + $(t.name.pipe(|n| format_name(n)))(self.to_string()) + } + } }) } diff --git a/crates/dagger-sdk/examples/iss-30-alt/main.rs b/crates/dagger-sdk/examples/iss-30-alt/main.rs new file mode 100644 index 0000000..2c2a013 --- /dev/null +++ b/crates/dagger-sdk/examples/iss-30-alt/main.rs @@ -0,0 +1,42 @@ +#![feature(async_closure)] + +use dagger_sdk::{ContainerBuildOptsBuilder, HostDirectoryOpts, QueryContainerOpts}; + +static DOCKER_FILES: [&str; 3] = ["Dockerfile", "Dockerfile.alpine", "Dockerfile.distroless"]; +static PLATFORMS: [&str; 2] = ["linux/arm64", "linux/x86_64"]; + +#[tokio::main] +async fn main() -> eyre::Result<()> { + let client = dagger_sdk::connect().await?; + + let context = client.host().directory_opts( + ".", + HostDirectoryOpts { + exclude: Some(vec!["target", "client/node_modules", "client/build"]), + include: None, + }, + ); + + for file in DOCKER_FILES { + for platform in PLATFORMS { + let ref_ = client + .container_opts(QueryContainerOpts { + id: None, + platform: Some(platform.into()), + }) + .build_opts( + context.id().await?, + ContainerBuildOptsBuilder::default() + .dockerfile(file) + .build() + .unwrap(), + ) + .export("./test") + .await?; + + println!("published image to: {:#?}", ref_); + } + } + + Ok(()) +} diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index 214d6d5..edb9b03 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -7,28 +7,70 @@ use std::sync::Arc; use tokio::process::Child; #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct CacheId(String); +pub struct CacheId(pub String); + +impl Into for &str { + fn into(self) -> CacheId { + CacheId(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct ContainerId(String); +pub struct ContainerId(pub String); + +impl Into for &str { + fn into(self) -> ContainerId { + ContainerId(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct DirectoryId(String); +pub struct DirectoryId(pub String); + +impl Into for &str { + fn into(self) -> DirectoryId { + DirectoryId(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct FileId(String); +pub struct FileId(pub String); + +impl Into for &str { + fn into(self) -> FileId { + FileId(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct Platform(String); +pub struct Platform(pub String); + +impl Into for &str { + fn into(self) -> Platform { + Platform(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct SecretId(String); +pub struct SecretId(pub String); + +impl Into for &str { + fn into(self) -> SecretId { + SecretId(self.to_string()) + } +} #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] -pub struct SocketId(String); +pub struct SocketId(pub String); + +impl Into for &str { + fn into(self) -> SocketId { + SocketId(self.to_string()) + } +} #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct BuildArg { - pub value: String, pub name: String, + pub value: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct PipelineLabel { - pub name: String, pub value: String, + pub name: String, } #[derive(Debug, Clone)] pub struct CacheVolume { @@ -2764,12 +2806,12 @@ impl Socket { } #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] pub enum CacheSharingMode { + SHARED, PRIVATE, LOCKED, - SHARED, } #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] pub enum NetworkProtocol { - UDP, TCP, + UDP, }