// 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/. //! The targets this machine offers: Linux (systemd) on Linux, none elsewhere in v0.1. use std::path::Path; use std::time::Duration; use legatus_linux::{DeployError, HttpHealth, Layout, LinuxBackend, Outcome, Plan, Systemctl}; use legatus_protocol::msg::{DeployJob, Deployed, Target as JobTarget}; use crate::pipeline::Target; /// The Linux target with real systemd. pub struct Linux { backend: LinuxBackend, } impl Linux { /// Apps under `root` (normally `/var/lib/legatus/apps`). pub fn new(root: impl Into) -> Linux { Linux { backend: LinuxBackend::new(Layout::new(root), Systemctl, HttpHealth), } } } impl Target for Linux { fn kinds(&self) -> Vec { if cfg!(target_os = "linux") { vec!["linux".into()] } else { Vec::new() } } fn deploy( &self, job: &DeployJob, artifact: &Path, sha256: &str, ) -> Result { let JobTarget::Linux(t) = &job.target; let file = std::fs::File::open(artifact).map_err(|e| DeployError::Switch(e.to_string()))?; let plan = Plan { app: &job.app, version: &job.version, unit: &t.unit, health_url: t.health_url.as_deref(), health_timeout: Duration::from_secs(u64::from(t.health_timeout_seconds)), keep: t.keep, }; self.backend .deploy(&plan, std::io::BufReader::new(file), sha256) } fn deployed(&self) -> Vec { self.backend .deployed() .into_iter() .map(|(app, version)| Deployed { app, version }) .collect() } }