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
27pub struct ContainerOutput {
28 pub stdout: String,
29 pub stderr: String,
30 pub exit_code: i32,
31}
32
33use std::fmt;
34
35#[derive(Debug)]
36pub enum ContainerError {
37 ImagePull(String),
38 ImageBuild(String),
39 ContainerStart(String),
40 ContainerExecution(String),
41 NetworkCreation(String),
42 NetworkOperation(String),
43}
44
45impl fmt::Display for ContainerError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 ContainerError::ImagePull(msg) => write!(f, "Failed to pull image: {}", msg),
49 ContainerError::ImageBuild(msg) => write!(f, "Failed to build image: {}", msg),
50 ContainerError::ContainerStart(msg) => {
51 write!(f, "Failed to start container: {}", msg)
52 }
53 ContainerError::ContainerExecution(msg) => {
54 write!(f, "Container execution failed: {}", msg)
55 }
56 ContainerError::NetworkCreation(msg) => {
57 write!(f, "Failed to create Docker network: {}", msg)
58 }
59 ContainerError::NetworkOperation(msg) => {
60 write!(f, "Network operation failed: {}", msg)
61 }
62 }
63 }
64}