Skip to main content

consortium_skypilot/
lib.rs

1//! # consortium-skypilot
2//!
3//! SkyPilot multi-cloud job orchestration with nix-built environments.
4//!
5//! Launches cloud clusters via SkyPilot, executes commands, and tears
6//! down resources. Uses nix for reproducible task definitions.
7
8pub mod error;
9pub mod tasks;
10
11pub use error::{Result, SkypilotError};
12
13use consortium::dag::{DagBuilder, DagContext, DagReport, ErrorPolicy};
14use consortium_nix::FleetConfig;
15
16/// Launch a SkyPilot task on a cloud cluster.
17pub fn launch_task(
18    config: &FleetConfig,
19    cluster_name: &str,
20    task_yaml: &str,
21    teardown: bool,
22) -> Result<DagReport> {
23    let sky_config = config
24        .skypilot_config
25        .as_ref()
26        .ok_or(SkypilotError::NoConfig)?;
27
28    let ctx = DagContext::new();
29    ctx.set_state("fleet_config", config.clone());
30
31    let mut dag = DagBuilder::new();
32
33    // Build environment
34    let build_id = format!("build-sky-env:{}", cluster_name);
35    dag.add_task(
36        &build_id,
37        tasks::NixBuildSkyEnvTask::new(cluster_name, &config.flake_uri),
38    );
39
40    // Launch cluster
41    let launch_id = format!("sky-launch:{}", cluster_name);
42    dag.add_task(
43        &launch_id,
44        tasks::SkyLaunchTask {
45            cluster_name: cluster_name.to_string(),
46            task_yaml: task_yaml.to_string(),
47            cloud: Some(sky_config.cloud.clone()),
48            region: sky_config.region.clone(),
49        },
50    );
51    dag.add_dep(&launch_id, &build_id);
52
53    // Teardown (optional)
54    if teardown {
55        let down_id = format!("sky-down:{}", cluster_name);
56        dag.add_task(
57            &down_id,
58            tasks::SkyDownTask {
59                cluster_name: cluster_name.to_string(),
60            },
61        );
62        dag.add_dep(&down_id, &launch_id);
63    }
64
65    dag.error_policy(ErrorPolicy::FailFast);
66    dag.context(ctx);
67
68    let report = dag
69        .build()
70        .map_err(|e| SkypilotError::Dag(e.to_string()))?
71        .run()
72        .map_err(|e| SkypilotError::Dag(e.to_string()))?;
73
74    Ok(report)
75}