swiftide_docker_executor/
docker_tool_executor.rs1use std::path::PathBuf;
2use uuid::Uuid;
3
4use crate::{DockerExecutorError, RunningDockerExecutor};
5
6#[derive(Clone, Debug)]
8pub struct DockerExecutor {
9 context_path: PathBuf,
10 image_name: String,
11 dockerfile: Option<PathBuf>,
12 container_uuid: Uuid,
13}
14
15impl Default for DockerExecutor {
16 fn default() -> Self {
17 Self {
18 container_uuid: Uuid::new_v4(),
19 context_path: ".".into(),
20 image_name: "docker-executor".into(),
21 dockerfile: Some("Dockerfile".into()),
22 }
23 }
24}
25
26impl DockerExecutor {
27 pub fn with_context_path(&mut self, path: impl Into<PathBuf>) -> &mut Self {
29 self.context_path = path.into();
30
31 self
32 }
33
34 pub fn with_existing_image(&mut self, path: impl Into<String>) -> &mut Self {
37 self.image_name = path.into();
38
39 self.dockerfile = None;
41
42 self
43 }
44
45 pub fn with_image_name(&mut self, name: impl Into<String>) -> &mut Self {
47 self.image_name = name.into();
48
49 self
50 }
51
52 pub fn with_container_uuid(&mut self, uuid: impl Into<Uuid>) -> &mut Self {
54 self.container_uuid = uuid.into();
55
56 self
57 }
58
59 pub fn with_dockerfile(&mut self, path: impl Into<PathBuf>) -> &mut Self {
61 self.dockerfile = Some(path.into());
62 self
63 }
64
65 pub async fn start(self) -> Result<RunningDockerExecutor, DockerExecutorError> {
69 RunningDockerExecutor::start(
70 self.container_uuid,
71 &self.context_path,
72 self.dockerfile.as_deref(),
73 &self.image_name,
74 )
75 .await
76 }
77}