Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
feat: dagger-run support
Browse files Browse the repository at this point in the history
  • Loading branch information
kjuulh committed Apr 29, 2023
1 parent 7d186c4 commit 2a29a66
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/dagger-codegen/src/rust/templates/object_tmpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn render_object(funcs: &CommonFunctions, t: &FullType) -> eyre::Result<rust
Ok(quote! {
#[derive(Clone)]
pub struct $(t.name.pipe(|s| format_name(s))) {
pub proc: $arc<$child>,
pub proc: Option<$arc<$child>>,
pub selection: $selection,
pub graphql_client: $graphql_client
}
Expand Down
21 changes: 18 additions & 3 deletions crates/dagger-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,25 @@ impl Engine {
pub async fn start(
&self,
cfg: &Config,
) -> eyre::Result<(ConnectParams, tokio::process::Child)> {
) -> eyre::Result<(ConnectParams, Option<tokio::process::Child>)> {
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<ConnectParams> {
let port = std::env::var("DAGGER_SESSION_PORT").map(|p| p.parse::<u64>())??;
let token = std::env::var("DAGGER_SESSION_TOKEN")?;

Ok(ConnectParams {
port,
session_token: token,
})
}
}
2 changes: 1 addition & 1 deletion crates/dagger-sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn connect_opts(cfg: Config) -> eyre::Result<DaggerConn> {
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)),
}))
Expand Down
30 changes: 15 additions & 15 deletions crates/dagger-sdk/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct PipelineLabel {
}
#[derive(Clone)]
pub struct CacheVolume {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -129,7 +129,7 @@ impl CacheVolume {
}
#[derive(Clone)]
pub struct Container {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -1728,7 +1728,7 @@ impl Container {
}
#[derive(Clone)]
pub struct Directory {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2235,7 +2235,7 @@ impl Directory {
}
#[derive(Clone)]
pub struct EnvVariable {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -2256,7 +2256,7 @@ impl EnvVariable {
}
#[derive(Clone)]
pub struct File {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2323,7 +2323,7 @@ impl File {
}
#[derive(Clone)]
pub struct GitRef {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2382,7 +2382,7 @@ impl GitRef {
}
#[derive(Clone)]
pub struct GitRepository {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2451,7 +2451,7 @@ impl GitRepository {
}
#[derive(Clone)]
pub struct Host {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2592,7 +2592,7 @@ impl Host {
}
#[derive(Clone)]
pub struct HostVariable {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -2617,7 +2617,7 @@ impl HostVariable {
}
#[derive(Clone)]
pub struct Label {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -2638,7 +2638,7 @@ impl Label {
}
#[derive(Clone)]
pub struct Port {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -2665,7 +2665,7 @@ impl Port {
}
#[derive(Clone)]
pub struct Project {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -2718,7 +2718,7 @@ impl Project {
}
#[derive(Clone)]
pub struct Query {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down Expand Up @@ -3087,7 +3087,7 @@ impl Query {
}
#[derive(Clone)]
pub struct Secret {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand All @@ -3108,7 +3108,7 @@ impl Secret {
}
#[derive(Clone)]
pub struct Socket {
pub proc: Arc<Child>,
pub proc: Option<Arc<Child>>,
pub selection: Selection,
pub graphql_client: DynGraphQLClient,
}
Expand Down

0 comments on commit 2a29a66

Please sign in to comment.