|
11 | 11 | //! `logs`, a global `-j/--json`). |
12 | 12 |
|
13 | 13 | use anyhow::{bail, Context, Result}; |
14 | | -use clap::{Parser, Subcommand}; |
| 14 | +use clap::{Parser, Subcommand, ValueEnum}; |
15 | 15 | use dstack_cli_core::layout::InstallLayout; |
16 | 16 | use dstack_cli_core::vmm::{Vmm, DEFAULT_HOST}; |
17 | 17 | use dstack_cli_core::{compose, ports, rpc}; |
@@ -46,6 +46,37 @@ struct Cli { |
46 | 46 | command: Command, |
47 | 47 | } |
48 | 48 |
|
| 49 | +#[derive(Clone, Copy, Debug, Default, ValueEnum)] |
| 50 | +enum ComposeRunner { |
| 51 | + #[default] |
| 52 | + DockerCompose, |
| 53 | + NerdctlCompose, |
| 54 | +} |
| 55 | + |
| 56 | +impl ComposeRunner { |
| 57 | + fn as_str(self) -> &'static str { |
| 58 | + match self { |
| 59 | + Self::DockerCompose => "docker-compose", |
| 60 | + Self::NerdctlCompose => "nerdctl-compose", |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#[derive(Clone, Copy, Debug, ValueEnum)] |
| 66 | +enum Snapshotter { |
| 67 | + Overlayfs, |
| 68 | + Stargz, |
| 69 | +} |
| 70 | + |
| 71 | +impl Snapshotter { |
| 72 | + fn as_str(self) -> &'static str { |
| 73 | + match self { |
| 74 | + Self::Overlayfs => "overlayfs", |
| 75 | + Self::Stargz => "stargz", |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
49 | 80 | #[derive(Subcommand)] |
50 | 81 | enum Command { |
51 | 82 | /// Deploy an app from a docker-compose file. |
@@ -84,6 +115,12 @@ enum Command { |
84 | 115 | /// build + hash the compose and print it, without deploying. |
85 | 116 | #[arg(long)] |
86 | 117 | dry_run: bool, |
| 118 | + /// compose frontend used inside the guest. |
| 119 | + #[arg(long, value_enum, default_value = "docker-compose")] |
| 120 | + runner: ComposeRunner, |
| 121 | + /// containerd snapshotter (supported only with --runner nerdctl-compose). |
| 122 | + #[arg(long, value_enum)] |
| 123 | + snapshotter: Option<Snapshotter>, |
87 | 124 | }, |
88 | 125 | /// List deployed apps. |
89 | 126 | Apps, |
@@ -144,6 +181,8 @@ async fn main() -> Result<()> { |
144 | 181 | no_kms, |
145 | 182 | allowlist, |
146 | 183 | dry_run, |
| 184 | + runner, |
| 185 | + snapshotter, |
147 | 186 | } => { |
148 | 187 | let compose = resolve_compose_arg(compose, compose_file)?; |
149 | 188 | let image = if use_local_defaults { |
@@ -174,6 +213,8 @@ async fn main() -> Result<()> { |
174 | 213 | allowlist.as_deref(), |
175 | 214 | dry_run, |
176 | 215 | json, |
| 216 | + runner, |
| 217 | + snapshotter, |
177 | 218 | ) |
178 | 219 | .await |
179 | 220 | } |
@@ -347,10 +388,21 @@ async fn cmd_deploy( |
347 | 388 | allowlist: Option<&str>, |
348 | 389 | dry_run: bool, |
349 | 390 | json: bool, |
| 391 | + runner: ComposeRunner, |
| 392 | + snapshotter: Option<Snapshotter>, |
350 | 393 | ) -> Result<()> { |
| 394 | + if matches!(runner, ComposeRunner::DockerCompose) && snapshotter.is_some() { |
| 395 | + bail!("--snapshotter is only supported with --runner nerdctl-compose"); |
| 396 | + } |
351 | 397 | let yaml = std::fs::read_to_string(compose_path) |
352 | 398 | .with_context(|| format!("reading compose file '{compose_path}'"))?; |
353 | | - let app_compose = compose::build_app_compose(name, &yaml, !no_kms); |
| 399 | + let app_compose = compose::build_app_compose_with_runtime( |
| 400 | + name, |
| 401 | + &yaml, |
| 402 | + !no_kms, |
| 403 | + runner.as_str(), |
| 404 | + snapshotter.map(Snapshotter::as_str), |
| 405 | + ); |
354 | 406 |
|
355 | 407 | let mut port_maps = Vec::new(); |
356 | 408 | for spec in port_specs { |
|
0 commit comments