From 0318c3c9817463104a8e23571d302ddeefeed9fb Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 30 Apr 2023 00:09:07 +0200 Subject: [PATCH] feat: dagger-run support --- .../src/rust/templates/object_tmpl.rs | 2 +- crates/dagger-core/src/engine.rs | 21 +++++++++++-- crates/dagger-sdk/src/client.rs | 2 +- crates/dagger-sdk/src/gen.rs | 30 +++++++++---------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/crates/dagger-codegen/src/rust/templates/object_tmpl.rs b/crates/dagger-codegen/src/rust/templates/object_tmpl.rs index 60b4c01..0d2048d 100644 --- a/crates/dagger-codegen/src/rust/templates/object_tmpl.rs +++ b/crates/dagger-codegen/src/rust/templates/object_tmpl.rs @@ -18,7 +18,7 @@ pub fn render_object(funcs: &CommonFunctions, t: &FullType) -> eyre::Result, + pub proc: Option<$arc<$child>>, pub selection: $selection, pub graphql_client: $graphql_client } diff --git a/crates/dagger-core/src/engine.rs b/crates/dagger-core/src/engine.rs index c7df4ac..e72eba3 100644 --- a/crates/dagger-core/src/engine.rs +++ b/crates/dagger-core/src/engine.rs @@ -23,10 +23,25 @@ impl Engine { pub async fn start( &self, cfg: &Config, - ) -> eyre::Result<(ConnectParams, tokio::process::Child)> { + ) -> eyre::Result<(ConnectParams, Option)> { tracing::info!("starting dagger-engine"); - // TODO: Add from existing session as well - self.from_cli(cfg).await + if let Ok(conn) = self.from_session_env().await { + return Ok((conn, None)); + } + + let (conn, proc) = self.from_cli(cfg).await?; + + Ok((conn, Some(proc))) + } + + async fn from_session_env(&self) -> eyre::Result { + let port = std::env::var("DAGGER_SESSION_PORT").map(|p| p.parse::())??; + let token = std::env::var("DAGGER_SESSION_TOKEN")?; + + Ok(ConnectParams { + port, + session_token: token, + }) } } diff --git a/crates/dagger-sdk/src/client.rs b/crates/dagger-sdk/src/client.rs index 913f8f1..604f67a 100644 --- a/crates/dagger-sdk/src/client.rs +++ b/crates/dagger-sdk/src/client.rs @@ -21,7 +21,7 @@ pub async fn connect_opts(cfg: Config) -> eyre::Result { let (conn, proc) = DaggerEngine::new().start(&cfg).await?; Ok(Arc::new(Query { - proc: Arc::new(proc), + proc: proc.map(|p| Arc::new(p)), selection: query(), graphql_client: Arc::new(DefaultGraphQLClient::new(&conn)), })) diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index ede5526..6a79ab2 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -115,7 +115,7 @@ pub struct PipelineLabel { } #[derive(Clone)] pub struct CacheVolume { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -129,7 +129,7 @@ impl CacheVolume { } #[derive(Clone)] pub struct Container { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -1728,7 +1728,7 @@ impl Container { } #[derive(Clone)] pub struct Directory { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2235,7 +2235,7 @@ impl Directory { } #[derive(Clone)] pub struct EnvVariable { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2256,7 +2256,7 @@ impl EnvVariable { } #[derive(Clone)] pub struct File { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2323,7 +2323,7 @@ impl File { } #[derive(Clone)] pub struct GitRef { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2382,7 +2382,7 @@ impl GitRef { } #[derive(Clone)] pub struct GitRepository { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2451,7 +2451,7 @@ impl GitRepository { } #[derive(Clone)] pub struct Host { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2592,7 +2592,7 @@ impl Host { } #[derive(Clone)] pub struct HostVariable { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2617,7 +2617,7 @@ impl HostVariable { } #[derive(Clone)] pub struct Label { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2638,7 +2638,7 @@ impl Label { } #[derive(Clone)] pub struct Port { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2665,7 +2665,7 @@ impl Port { } #[derive(Clone)] pub struct Project { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -2718,7 +2718,7 @@ impl Project { } #[derive(Clone)] pub struct Query { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -3087,7 +3087,7 @@ impl Query { } #[derive(Clone)] pub struct Secret { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, } @@ -3108,7 +3108,7 @@ impl Secret { } #[derive(Clone)] pub struct Socket { - pub proc: Arc, + pub proc: Option>, pub selection: Selection, pub graphql_client: DynGraphQLClient, }