wrkflw_runtime/
container.rs1use async_trait::async_trait;
2use std::path::Path;
3
4#[async_trait]
5pub trait ContainerRuntime {
6 async fn run_container(
7 &self,
8 image: &str,
9 cmd: &[&str],
10 env_vars: &[(&str, &str)],
11 working_dir: &Path,
12 volumes: &[(&Path, &Path)],
13 ) -> Result<ContainerOutput, ContainerError>;
14
15 async fn pull_image(&self, image: &str) -> Result<(), ContainerError>;
16
17 async fn build_image(&self, dockerfile: &Path, tag: &str) -> Result<(), ContainerError>;
18
19 async fn prepare_language_environment(
20 &self,
21 language: &str,
22 version: Option<&str>,
23 additional_packages: Option<Vec<String>>,
24 ) -> Result<String, ContainerError>;
25}
26
27#[derive(Debug)]
28pub struct ContainerOutput {
29 pub stdout: String,
30 pub stderr: String,
31 pub exit_code: i32,
32}
33
34use std::fmt;
35
36#[derive(Debug)]
37pub enum ContainerError {
38 ImagePull(String),
39 ImageBuild(String),
40 ContainerStart(String),
41 ContainerExecution(String),
42 NetworkCreation(String),
43 NetworkOperation(String),
44}
45
46impl fmt::Display for ContainerError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 ContainerError::ImagePull(msg) => write!(f, "Failed to pull image: {}", msg),
50 ContainerError::ImageBuild(msg) => write!(f, "Failed to build image: {}", msg),
51 ContainerError::ContainerStart(msg) => {
52 write!(f, "Failed to start container: {}", msg)
53 }
54 ContainerError::ContainerExecution(msg) => {
55 write!(f, "Container execution failed: {}", msg)
56 }
57 ContainerError::NetworkCreation(msg) => {
58 write!(f, "Failed to create Docker network: {}", msg)
59 }
60 ContainerError::NetworkOperation(msg) => {
61 write!(f, "Network operation failed: {}", msg)
62 }
63 }
64 }
65}