| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use crate::topology::Node; |
| 22 |
use anyhow::{Context, Result}; |
| 23 |
use std::path::{Path, PathBuf}; |
| 24 |
use tokio::process::Command; |
| 25 |
|
| 26 |
pub async fn deploy_local(release_root: &Path, version: &str, binary: &Path) -> Result<PathBuf> { |
| 27 |
let release_dir = release_root.join("releases").join(version); |
| 28 |
tokio::fs::create_dir_all(&release_dir).await?; |
| 29 |
let dest = release_dir.join("server"); |
| 30 |
tokio::fs::copy(binary, &dest) |
| 31 |
.await |
| 32 |
.with_context(|| format!("copy {} -> {}", binary.display(), dest.display()))?; |
| 33 |
|
| 34 |
let current = release_root.join("current"); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
let target = format!("releases/{version}"); |
| 39 |
let out = Command::new("ln") |
| 40 |
.args(["-sfn", &target]) |
| 41 |
.arg(¤t) |
| 42 |
.output() |
| 43 |
.await?; |
| 44 |
anyhow::ensure!( |
| 45 |
out.status.success(), |
| 46 |
"symlink swap failed: {}", |
| 47 |
String::from_utf8_lossy(&out.stderr), |
| 48 |
); |
| 49 |
Ok(release_dir) |
| 50 |
} |
| 51 |
|
| 52 |
pub async fn deploy_node(node: &Node, version: &str, binary: &Path) -> Result<PathBuf> { |
| 53 |
if node.ssh_target == "local" || node.ssh_target.is_empty() { |
| 54 |
return deploy_local(Path::new(&node.release_root), version, binary).await; |
| 55 |
} |
| 56 |
remote_deploy_stub(node, version, binary).await |
| 57 |
} |
| 58 |
|
| 59 |
async fn remote_deploy_stub(node: &Node, version: &str, _binary: &Path) -> Result<PathBuf> { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
anyhow::bail!( |
| 65 |
"remote deploy not yet implemented (node {} -> {}); use ssh_target=local for dev", |
| 66 |
node.name, |
| 67 |
node.ssh_target, |
| 68 |
); |
| 69 |
#[allow(unreachable_code)] |
| 70 |
Ok(PathBuf::from(&node.release_root).join("releases").join(version)) |
| 71 |
} |
| 72 |
|