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/// Download artifact for one horizond release platform.
93#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
94#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
95#[serde(rename_all = "camelCase")]
96pub struct HorizondArtifact {
97    /// HTTPS URL for the artifact.
98    pub url: String,
99    /// SHA-256 digest for the artifact payload.
100    pub sha256: String,
101}
102
103/// Horizon machine image catalog.
104///
105/// Platform resolves concrete provider images from this catalog during rollout.
106#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
107#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
108#[serde(rename_all = "camelCase")]
109pub struct HorizonMachineImage {
110    /// Logical image channel, such as prod, staging, or canary.
111    pub channel: String,
112    /// Published immutable machine image version.
113    pub machine_image_version: String,
114    /// horizond daemon version baked into the image.
115    pub horizond_version: String,
116    /// Git commit SHA used to build the image.
117    pub git_sha: String,
118    /// Image manifest creation timestamp.
119    pub created_at: String,
120    /// Base OS image metadata.
121    pub base_image: HorizonMachineBaseImage,
122    /// Per-architecture horizond artifacts by release-platform key.
123    pub horizond_artifacts: HashMap<String, HorizondArtifact>,
124    /// AWS image catalog.
125    #[serde(default, skip_serializing_if = "Option::is_none")]
126    pub aws: Option<HorizonAwsMachineImages>,
127    /// GCP image catalog.
128    #[serde(default, skip_serializing_if = "Option::is_none")]
129    pub gcp: Option<HorizonGcpMachineImages>,
130    /// Azure image catalog.
131    #[serde(default, skip_serializing_if = "Option::is_none")]
132    pub azure: Option<HorizonAzureMachineImages>,
133}
134
135/// Horizon control-plane configuration for container orchestration.
136///
137/// Contains all the information needed for Alien to interact with managed
138/// container clusters during deployment. Each ComputeCluster resource gets its own
139/// entry in the clusters map.
140#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
141#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
142#[serde(rename_all = "camelCase")]
143pub struct HorizonConfig {
144    /// Horizon control-plane API base URL.
145    pub url: String,
146
147    /// Horizon machine image catalog.
148    #[serde(default, skip_serializing_if = "Option::is_none")]
149    pub horizon_machine_image: Option<HorizonMachineImage>,
150
151    /// Cluster configurations (one per ComputeCluster resource)
152    /// Key: ComputeCluster resource ID from stack
153    /// Value: Cluster ID and management token for that cluster
154    pub clusters: HashMap<String, HorizonClusterConfig>,
155}
156
157/// Compute backend for Container and Worker resources.
158///
159/// Determines how compute workloads are orchestrated on cloud platforms.
160/// When None, the platform default is used for cloud platforms.
161#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
162#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
163#[serde(tag = "type", rename_all = "camelCase")]
164pub enum ComputeBackend {
165    /// VM-backed container orchestration (default for cloud platforms)
166    Horizon(HorizonConfig),
167    // Future backends:
168    // /// Deploy to existing Kubernetes cluster (EKS/GKE/AKS)
169    // Kubernetes(KubernetesCredentials),
170    // /// AWS ECS Fargate (serverless containers)
171    // EcsFargate,
172}