Skip to main content

butterflow_models/
runtime.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use ts_rs::TS;
4/// Type of runtime
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
6#[serde(rename_all = "lowercase")]
7pub enum RuntimeType {
8    /// Direct execution on the host
9    Direct,
10
11    /// Docker container execution
12    Docker,
13
14    /// Podman container execution
15    Podman,
16}
17
18impl std::fmt::Display for RuntimeType {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            RuntimeType::Direct => write!(f, "direct"),
22            RuntimeType::Docker => write!(f, "docker"),
23            RuntimeType::Podman => write!(f, "podman"),
24        }
25    }
26}
27
28/// Represents a runtime configuration
29#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
30pub struct Runtime {
31    /// Type of runtime
32    pub r#type: RuntimeType,
33
34    /// Container image (for Docker and Podman)
35    #[serde(default)]
36    #[ts(optional=nullable)]
37    pub image: Option<String>,
38
39    /// Working directory inside the container
40    #[serde(default)]
41    #[ts(optional=nullable)]
42    pub working_dir: Option<String>,
43
44    /// User to run as inside the container
45    #[serde(default)]
46    #[ts(optional=nullable)]
47    pub user: Option<String>,
48
49    /// Network mode for the container
50    #[serde(default)]
51    #[ts(optional=nullable)]
52    pub network: Option<String>,
53
54    /// Additional container options
55    #[serde(default)]
56    #[ts(optional=nullable)]
57    pub options: Option<Vec<String>>,
58}