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: 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: "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_image_name(&mut self, name: impl Into<String>) -> &mut Self {
36 self.image_name = name.into();
37
38 self
39 }
40
41 pub fn with_container_uuid(&mut self, uuid: impl Into<Uuid>) -> &mut Self {
43 self.container_uuid = uuid.into();
44
45 self
46 }
47
48 pub fn with_dockerfile(&mut self, path: impl Into<PathBuf>) -> &mut Self {
50 self.dockerfile = path.into();
51 self
52 }
53
54 pub async fn start(self) -> Result<RunningDockerExecutor, DockerExecutorError> {
58 RunningDockerExecutor::start(
59 self.container_uuid,
60 &self.context_path,
61 &self.dockerfile,
62 &self.image_name,
63 )
64 .await
65 }
66}