Skip to main content

arcbox_container/
config.rs

1//! Container configuration.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Port binding configuration.
7///
8/// Maps a container port to a host port for port forwarding.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct PortBinding {
11    /// Host IP to bind to (empty or "0.0.0.0" for all interfaces).
12    pub host_ip: String,
13    /// Host port number.
14    pub host_port: u16,
15    /// Container port number.
16    pub container_port: u16,
17    /// Protocol (tcp or udp).
18    pub protocol: String,
19}
20
21/// Container configuration.
22#[derive(Debug, Clone, Default, Serialize, Deserialize)]
23pub struct ContainerConfig {
24    /// Container name.
25    pub name: Option<String>,
26    /// Image name.
27    pub image: String,
28    /// Command to run.
29    pub cmd: Vec<String>,
30    /// Entrypoint.
31    pub entrypoint: Vec<String>,
32    /// Environment variables.
33    pub env: HashMap<String, String>,
34    /// Working directory.
35    pub working_dir: Option<String>,
36    /// User to run as.
37    pub user: Option<String>,
38    /// Exposed ports.
39    pub exposed_ports: Vec<String>,
40    /// Port bindings (host:container port mappings).
41    pub port_bindings: Vec<PortBinding>,
42    /// Volume mounts.
43    pub volumes: Vec<VolumeMount>,
44    /// Resource limits.
45    pub resources: ResourceLimits,
46    /// Labels.
47    pub labels: HashMap<String, String>,
48    /// Restart policy.
49    pub restart_policy: RestartPolicy,
50    /// TTY allocation.
51    pub tty: Option<bool>,
52    /// Keep stdin open.
53    pub open_stdin: Option<bool>,
54}
55
56/// Volume mount configuration.
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct VolumeMount {
59    /// Host path or volume name.
60    pub source: String,
61    /// Container path.
62    pub target: String,
63    /// Read-only mount.
64    pub read_only: bool,
65}
66
67/// Resource limits.
68#[derive(Debug, Clone, Default, Serialize, Deserialize)]
69pub struct ResourceLimits {
70    /// CPU limit (in millicores, e.g., 1000 = 1 CPU).
71    pub cpu_limit: Option<u64>,
72    /// Memory limit in bytes.
73    pub memory_limit: Option<u64>,
74    /// Memory reservation in bytes.
75    pub memory_reservation: Option<u64>,
76}
77
78/// Restart policy.
79#[derive(Debug, Clone, Default, Serialize, Deserialize)]
80#[serde(rename_all = "kebab-case")]
81pub enum RestartPolicy {
82    /// Never restart.
83    #[default]
84    No,
85    /// Always restart.
86    Always,
87    /// Restart on failure.
88    OnFailure,
89    /// Restart unless stopped.
90    UnlessStopped,
91}