Skip to main content

orca_core/config/
service.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::types::{
6    DeployStrategy, PlacementConstraint, Replicas, ResourceLimits, RuntimeKind, VolumeSpec,
7};
8
9/// Probe configuration for readiness/liveness checks.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct ProbeConfig {
12    /// HTTP path to probe (e.g., "/healthz").
13    pub path: String,
14    /// Port to probe (defaults to service port).
15    pub port: Option<u16>,
16    /// Seconds between probes (default: 10).
17    #[serde(default = "default_probe_interval")]
18    pub interval_secs: u64,
19    /// Seconds to wait for response (default: 3).
20    #[serde(default = "default_probe_timeout")]
21    pub timeout_secs: u64,
22    /// Failures before action (default: 3).
23    #[serde(default = "default_probe_failures")]
24    pub failure_threshold: u32,
25    /// Seconds to wait before first probe (default: 5).
26    #[serde(default = "default_initial_delay")]
27    pub initial_delay_secs: u64,
28}
29
30fn default_probe_interval() -> u64 {
31    10
32}
33fn default_probe_timeout() -> u64 {
34    3
35}
36fn default_probe_failures() -> u32 {
37    3
38}
39fn default_initial_delay() -> u64 {
40    5
41}
42
43/// Services configuration (`services.toml`).
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct ServicesConfig {
46    pub service: Vec<ServiceConfig>,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct ServiceConfig {
51    pub name: String,
52    #[serde(default)]
53    pub runtime: RuntimeKind,
54    /// Container image (for container runtime).
55    pub image: Option<String>,
56    /// Wasm module path or OCI reference (for wasm runtime).
57    pub module: Option<String>,
58    #[serde(default)]
59    pub replicas: Replicas,
60    /// Container port (internal).
61    pub port: Option<u16>,
62    /// Host port to bind (e.g., 443 for edge proxies). If omitted, ephemeral.
63    pub host_port: Option<u16>,
64    /// Domain for reverse proxy routing (orca proxy handles TLS).
65    pub domain: Option<String>,
66    /// Path routes under the domain (e.g., ["/api/*", "/admin/*"]).
67    /// Default: ["/*"] (catch-all).
68    #[serde(default)]
69    pub routes: Vec<String>,
70    /// Health check path (e.g., "/healthz"). Legacy shorthand for liveness probe.
71    pub health: Option<String>,
72    /// Readiness probe: container must pass before receiving traffic.
73    pub readiness: Option<ProbeConfig>,
74    /// Liveness probe: container is restarted if this fails.
75    pub liveness: Option<ProbeConfig>,
76    #[serde(default)]
77    pub env: HashMap<String, String>,
78    pub resources: Option<ResourceLimits>,
79    pub volume: Option<VolumeSpec>,
80    pub deploy: Option<DeployStrategy>,
81    pub placement: Option<PlacementConstraint>,
82    /// Docker network name. Services with the same network can reach each other.
83    /// Auto-prefixed with "orca-". If omitted, derived from service name prefix.
84    pub network: Option<String>,
85    /// Network aliases (resolvable names within the Docker network).
86    #[serde(default)]
87    pub aliases: Vec<String>,
88    /// Host bind mounts (e.g., ["/host/path:/container/path:ro"]).
89    #[serde(default)]
90    pub mounts: Vec<String>,
91    /// Wasm triggers: "http:/path", "cron:expr", "queue:topic", "event:pattern"
92    #[serde(default)]
93    pub triggers: Vec<String>,
94    /// Static assets directory (for builtin:static-server Wasm module).
95    pub assets: Option<String>,
96}