use crate::client::graphql_client; use crate::querybuilder::Selection; use dagger_core::connect_params::ConnectParams; use derive_builder::Builder; use serde::{Deserialize, Serialize}; use std::process::Child; use std::sync::Arc; #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct CacheId(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct ContainerId(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct DirectoryId(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct FileId(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct Platform(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct SecretId(String); #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct SocketId(String); #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct BuildArg { pub name: String, pub value: String, } pub struct CacheVolume { pub proc: Arc, pub selection: Selection, pub conn: ConnectParams, } impl CacheVolume { pub fn id(&self) -> eyre::Result { let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)) } } pub struct Container { pub proc: Arc, pub selection: Selection, pub conn: ConnectParams, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerBuildOpts<'a> { #[builder(setter(into, strip_option))] pub dockerfile: Option<&'a str>, #[builder(setter(into, strip_option))] pub build_args: Option>, #[builder(setter(into, strip_option))] pub target: Option<&'a str>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerExecOpts<'a> { #[builder(setter(into, strip_option))] pub args: Option>, #[builder(setter(into, strip_option))] pub stdin: Option<&'a str>, #[builder(setter(into, strip_option))] pub redirect_stdout: Option<&'a str>, #[builder(setter(into, strip_option))] pub redirect_stderr: Option<&'a str>, #[builder(setter(into, strip_option))] pub experimental_privileged_nesting: Option, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerExportOpts<'a> { #[builder(setter(into, strip_option))] pub platform_variants: Option>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerPipelineOpts<'a> { #[builder(setter(into, strip_option))] pub description: Option<&'a str>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerPublishOpts<'a> { #[builder(setter(into, strip_option))] pub platform_variants: Option>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithDefaultArgsOpts<'a> { #[builder(setter(into, strip_option))] pub args: Option>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithDirectoryOpts<'a> { #[builder(setter(into, strip_option))] pub exclude: Option>, #[builder(setter(into, strip_option))] pub include: Option>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithExecOpts<'a> { #[builder(setter(into, strip_option))] pub stdin: Option<&'a str>, #[builder(setter(into, strip_option))] pub redirect_stdout: Option<&'a str>, #[builder(setter(into, strip_option))] pub redirect_stderr: Option<&'a str>, #[builder(setter(into, strip_option))] pub experimental_privileged_nesting: Option, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithFileOpts<'a> { #[builder(setter(into, strip_option))] pub permissions: Option, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithMountedCacheOpts<'a> { #[builder(setter(into, strip_option))] pub source: Option, #[builder(setter(into, strip_option))] pub sharing: Option, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithNewFileOpts<'a> { #[builder(setter(into, strip_option))] pub contents: Option<&'a str>, #[builder(setter(into, strip_option))] pub permissions: Option, } impl Container { pub fn build(&self, context: DirectoryId, opts: Option) -> Container { let mut query = self.selection.select("build"); query = query.arg("context", context); if let Some(opts) = opts { if let Some(dockerfile) = opts.dockerfile { query = query.arg("dockerfile", dockerfile); } if let Some(build_args) = opts.build_args { query = query.arg("buildArgs", build_args); } if let Some(target) = opts.target { query = query.arg("target", target); } } return Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn default_args(&self) -> eyre::Result> { let mut query = self.selection.select("defaultArgs"); query.execute(&graphql_client(&self.conn)) } pub fn directory(&self, path: impl Into) -> Directory { let mut query = self.selection.select("directory"); query = query.arg("path", path.into()); return Directory { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn entrypoint(&self) -> eyre::Result> { let mut query = self.selection.select("entrypoint"); query.execute(&graphql_client(&self.conn)) } pub fn env_variable(&self, name: impl Into) -> eyre::Result { let mut query = self.selection.select("envVariable"); query = query.arg("name", name.into()); query.execute(&graphql_client(&self.conn)) } pub fn env_variables(&self) -> Vec { let mut query = self.selection.select("envVariables"); return vec![EnvVariable { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }]; } pub fn exec(&self, opts: Option) -> Container { let mut query = self.selection.select("exec"); if let Some(opts) = opts { if let Some(args) = opts.args { query = query.arg("args", args); } if let Some(stdin) = opts.stdin { query = query.arg("stdin", stdin); } if let Some(redirect_stdout) = opts.redirect_stdout { query = query.arg("redirectStdout", redirect_stdout); } if let Some(redirect_stderr) = opts.redirect_stderr { query = query.arg("redirectStderr", redirect_stderr); } if let Some(experimental_privileged_nesting) = opts.experimental_privileged_nesting { query = query.arg( "experimentalPrivilegedNesting", experimental_privileged_nesting, ); } } return Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn exit_code(&self) -> eyre::Result { let mut query = self.selection.select("exitCode"); query.execute(&graphql_client(&self.conn)) } pub fn export( &self, path: impl Into, opts: Option, ) -> eyre::Result { let mut query = self.selection.select("export"); query = query.arg("path", path.into()); if let Some(opts) = opts { if let Some(platform_variants) = opts.platform_variants { query = query.arg("platformVariants", platform_variants); } } query.execute(&graphql_client(&self.conn)) } pub fn file(&self, path: impl Into) -> File { let mut query = self.selection.select("file"); query = query.arg("path", path.into()); return File { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn from(&self, address: impl Into) -> Container { let mut query = self.selection.select("from"); query = query.arg("address", address.into()); return Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn fs(&self) -> Directory { let mut query = self.selection.select("fs"); return Directory { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn id(&self) -> eyre::Result { let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)) } pub fn label(&self, name: impl Into) -> eyre::Result { let mut query = self.selection.select("label"); query = query.arg("name", name.into()); query.execute(&graphql_client(&self.conn)) } pub fn labels(&self) -> Vec