use crate::client::graphql_client; use crate::querybuilder::Selection; use dagger_core::connect_params::ConnectParams; use serde::{Deserialize, Serialize}; use std::process::Child; use std::sync::Arc; #[derive(Serialize, Deserialize)] pub struct CacheId(String); #[derive(Serialize, Deserialize)] pub struct ContainerId(String); #[derive(Serialize, Deserialize)] pub struct DirectoryId(String); #[derive(Serialize, Deserialize)] pub struct FileId(String); #[derive(Serialize, Deserialize)] pub struct Platform(String); #[derive(Serialize, Deserialize)] pub struct SecretId(String); #[derive(Serialize, Deserialize)] pub struct SocketId(String); #[derive(Serialize, Deserialize)] pub struct BuildArg { pub value: String, pub name: String, } pub struct CacheVolume { pub proc: Arc, pub selection: Selection, pub conn: ConnectParams, } impl CacheVolume { pub fn id(&self) -> CacheId { let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)).unwrap() } } pub struct Container { pub proc: Arc, pub selection: Selection, pub conn: ConnectParams, } pub struct ContainerBuildOpts { pub dockerfile: Option, pub build_args: Option>, pub target: Option, } pub struct ContainerExecOpts { pub args: Option>, pub stdin: Option, pub redirect_stdout: Option, pub redirect_stderr: Option, pub experimental_privileged_nesting: Option, } pub struct ContainerExportOpts { pub platform_variants: Option>, } pub struct ContainerPipelineOpts { pub description: Option, } pub struct ContainerPublishOpts { pub platform_variants: Option>, } pub struct ContainerWithDefaultArgsOpts { pub args: Option>, } pub struct ContainerWithDirectoryOpts { pub exclude: Option>, pub include: Option>, } pub struct ContainerWithExecOpts { pub stdin: Option, pub redirect_stdout: Option, pub redirect_stderr: Option, pub experimental_privileged_nesting: Option, } pub struct ContainerWithFileOpts { pub permissions: Option, } pub struct ContainerWithMountedCacheOpts { pub source: Option, pub sharing: Option, } pub struct ContainerWithNewFileOpts { pub contents: 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) -> Vec { let mut query = self.selection.select("defaultArgs"); query.execute(&graphql_client(&self.conn)).unwrap() } pub fn directory(&self, path: String) -> Directory { let mut query = self.selection.select("directory"); query = query.arg("path", path); return Directory { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn entrypoint(&self) -> Vec { let mut query = self.selection.select("entrypoint"); query.execute(&graphql_client(&self.conn)).unwrap() } pub fn env_variable(&self, name: String) -> String { let mut query = self.selection.select("envVariable"); query = query.arg("name", name); query.execute(&graphql_client(&self.conn)).unwrap() } 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) -> isize { let mut query = self.selection.select("exitCode"); query.execute(&graphql_client(&self.conn)).unwrap() } pub fn export(&self, path: String, opts: Option) -> bool { let mut query = self.selection.select("export"); query = query.arg("path", path); 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)).unwrap() } pub fn file(&self, path: String) -> File { let mut query = self.selection.select("file"); query = query.arg("path", path); return File { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), }; } pub fn from(&self, address: String) -> Container { let mut query = self.selection.select("from"); query = query.arg("address", address); 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) -> ContainerId { let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)).unwrap() } pub fn label(&self, name: String) -> String { let mut query = self.selection.select("label"); query = query.arg("name", name); query.execute(&graphql_client(&self.conn)).unwrap() } pub fn labels(&self) -> Vec