Skip to main content

alien_core/deployment/
compute.rs

1//! Compute backend configuration for container orchestration.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Configuration for a single container worker cluster.
8///
9/// Contains the cluster ID and management token needed to interact with
10/// the managed container control plane API for container operations.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
13#[serde(rename_all = "camelCase")]
14pub struct HorizonClusterConfig {
15    /// Cluster ID (deterministic: workspace/project/deployment/resourceid)
16    pub cluster_id: String,
17
18    /// Management token for API access (hm_...)
19    /// Used by alien-deployment controllers to create/update containers
20    pub management_token: String,
21}
22
23/// Horizon machine image architecture.
24#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
25#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
26#[serde(rename_all = "camelCase")]
27pub enum HorizonMachineArchitecture {
28    /// Linux arm64 / aarch64 machine image.
29    #[serde(rename = "arm64")]
30    Arm64,
31    /// Linux amd64 / x86_64 machine image.
32    #[serde(rename = "amd64")]
33    Amd64,
34}
35
36/// AWS Horizon machine image catalog.
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
38#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
39#[serde(rename_all = "camelCase")]
40pub struct HorizonAwsMachineImages {
41    /// AMI IDs by architecture, then AWS region.
42    pub amis: HashMap<HorizonMachineArchitecture, HashMap<String, String>>,
43}
44
45/// GCP Horizon machine image entry.
46#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
47#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
48#[serde(rename_all = "camelCase")]
49pub struct HorizonGcpMachineImage {
50    /// Source image self link or image-family URL.
51    pub source_image: String,
52}
53
54/// GCP Horizon machine image catalog.
55#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
56#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
57#[serde(rename_all = "camelCase")]
58pub struct HorizonGcpMachineImages {
59    /// Images by architecture.
60    pub images: HashMap<HorizonMachineArchitecture, HorizonGcpMachineImage>,
61}
62
63/// Azure Horizon machine image entry.
64#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
65#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
66#[serde(rename_all = "camelCase")]
67pub struct HorizonAzureMachineImage {
68    /// Azure Compute Gallery image version ID.
69    pub image_version_id: String,
70}
71
72/// Base image metadata for the Horizon machine image.
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
74#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
75#[serde(rename_all = "camelCase")]
76pub struct HorizonMachineBaseImage {
77    /// Base OS image name.
78    pub name: String,
79    /// Base OS image version or channel.
80    pub version: String,
81}
82
83/// Azure Horizon machine image catalog.
84#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
85#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
86#[serde(rename_all = "camelCase")]
87pub struct HorizonAzureMachineImages {
88    /// Images by architecture.
89    pub images: HashMap<HorizonMachineArchitecture, HorizonAzureMachineImage>,
90}
91
92/// Horizon machine image catalog.
93///
94/// Platform resolves concrete provider images from this catalog during rollout.
95#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
96#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
97#[serde(rename_all = "camelCase")]
98pub struct HorizonMachineImage {
99    /// Logical image channel, such as prod, staging, or canary.
100    pub channel: String,
101    /// Published immutable machine image version.
102    pub machine_image_version: String,
103    /// horizond daemon version baked into the image.
104    pub horizond_version: String,
105    /// Git commit SHA used to build the image.
106    pub git_sha: String,
107    /// Image manifest creation timestamp.
108    pub created_at: String,
109    /// Base OS image metadata.
110    pub base_image: HorizonMachineBaseImage,
111    /// AWS image catalog.
112    #[serde(default, skip_serializing_if = "Option::is_none")]
113    pub aws: Option<HorizonAwsMachineImages>,
114    /// GCP image catalog.
115    #[serde(default, skip_serializing_if = "Option::is_none")]
116    pub gcp: Option<HorizonGcpMachineImages>,
117    /// Azure image catalog.
118    #[serde(default, skip_serializing_if = "Option::is_none")]
119    pub azure: Option<HorizonAzureMachineImages>,
120}
121
122/// Horizon control-plane configuration for container orchestration.
123///
124/// Contains all the information needed for Alien to interact with managed
125/// container clusters during deployment. Each ComputeCluster resource gets its own
126/// entry in the clusters map.
127#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
128#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
129#[serde(rename_all = "camelCase")]
130pub struct HorizonConfig {
131    /// Horizon control-plane API base URL.
132    pub url: String,
133
134    /// Horizon machine image catalog.
135    #[serde(default, skip_serializing_if = "Option::is_none")]
136    pub horizon_machine_image: Option<HorizonMachineImage>,
137
138    /// Cluster configurations (one per ComputeCluster resource)
139    /// Key: ComputeCluster resource ID from stack
140    /// Value: Cluster ID and management token for that cluster
141    pub clusters: HashMap<String, HorizonClusterConfig>,
142}
143
144/// Compute backend for Container and Worker resources.
145///
146/// Determines how compute workloads are orchestrated on cloud platforms.
147/// When None, the platform default is used for cloud platforms.
148#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
149#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
150#[serde(tag = "type", rename_all = "camelCase")]
151pub enum ComputeBackend {
152    /// VM-backed container orchestration (default for cloud platforms)
153    Horizon(HorizonConfig),
154    // Future backends:
155    // /// Deploy to existing Kubernetes cluster (EKS/GKE/AKS)
156    // Kubernetes(KubernetesCredentials),
157    // /// AWS ECS Fargate (serverless containers)
158    // EcsFargate,
159}