Skip to main content

life_cli/deploy/
backend.rs

1//! Deploy backend trait — abstracts over Railway, Fly.io, AWS ECS.
2
3use std::collections::HashMap;
4
5use anyhow::Result;
6use async_trait::async_trait;
7use serde::{Deserialize, Serialize};
8
9use crate::template::AgentTemplate;
10
11/// A deployed service instance.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct DeployedService {
14    /// Cloud-specific service identifier.
15    pub service_id: String,
16    /// Public URL if the service is exposed.
17    pub url: Option<String>,
18    /// Deployment status (BUILDING, DEPLOYING, SUCCESS, FAILED, etc.).
19    pub status: String,
20}
21
22/// Result of a full deployment operation.
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct DeploymentResult {
25    /// Cloud-specific project identifier.
26    pub project_id: String,
27    /// Cloud-specific environment identifier.
28    pub environment_id: String,
29    /// Deployed services by name.
30    pub services: HashMap<String, DeployedService>,
31}
32
33/// Trait for cloud deployment backends.
34///
35/// Implementations handle the specifics of provisioning, monitoring, and
36/// tearing down agent stacks on different cloud providers.
37#[async_trait]
38pub trait DeployBackend: Send + Sync {
39    /// Deploy an agent template to the cloud target.
40    async fn deploy(
41        &self,
42        project_name: &str,
43        template: &AgentTemplate,
44        extra_env: &HashMap<String, String>,
45    ) -> Result<DeploymentResult>;
46
47    /// Get the deployment status for all services in a project.
48    async fn status(&self, project_id: &str) -> Result<HashMap<String, DeployedService>>;
49
50    /// Destroy a project and all its services.
51    async fn destroy(&self, project_id: &str) -> Result<()>;
52
53    /// Restart all services in a project.
54    #[allow(dead_code)]
55    async fn restart(&self, project_id: &str) -> Result<()>;
56
57    /// Scale a specific service to the given number of replicas.
58    #[allow(dead_code)]
59    async fn scale(&self, project_id: &str, service_name: &str, replicas: u32) -> Result<()>;
60}