Files
Legatus/crates/linux/examples/deploy.rs
T

51 lines
1.8 KiB
Rust

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! TEST ONLY: drives the Linux backend with real systemd for tests/linux (the container test).
//! It skips the signature check on purpose, so it is an example, never part of a release.
//!
//! deploy <root> <app> <version> <unit> <health-url|-> <archive.tar.gz>
#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::time::Duration;
use legatus_linux::{HttpHealth, Layout, LinuxBackend, Outcome, Plan, Systemctl};
fn main() {
let a: Vec<String> = std::env::args().skip(1).collect();
let [root, app, version, unit, health, archive] = a.as_slice() else {
eprintln!("usage: deploy <root> <app> <version> <unit> <health-url|-> <archive.tar.gz>");
std::process::exit(2);
};
let bytes = std::fs::read(archive).expect("the archive");
let sha = legatus_protocol::sha256_hex(&bytes);
let backend = LinuxBackend::new(Layout::new(root), Systemctl, HttpHealth);
let plan = Plan {
app,
version,
unit,
health_url: (health != "-").then_some(health.as_str()),
health_timeout: Duration::from_secs(15),
keep: 3,
};
match backend.deploy(&plan, &bytes[..], &sha) {
Ok(Outcome::Succeeded { previous }) => {
println!(
"succeeded previous={}",
previous.unwrap_or_else(|| "-".into())
)
}
Ok(Outcome::RolledBack {
to,
healthy,
reason,
}) => {
println!("rolled_back to={to} healthy={healthy} reason={reason}")
}
Ok(Outcome::Failed { reason }) => println!("failed reason={reason}"),
Err(e) => println!("error {e}"),
}
}