use std::path::PathBuf;
#[derive(Debug, Clone, Default)]
pub struct Cmd {
pub argv: Vec<String>,
pub workdir: Option<PathBuf>,
pub env: Vec<(String, String)>,
}
impl Cmd {
pub fn is_empty(&self) -> bool {
self.argv.is_empty()
}
pub fn display(&self) -> String {
self.argv.join(" ")
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TargetKind {
Local,
Kubernetes,
#[allow(dead_code)]
DockerCompose,
}
impl TargetKind {
pub fn target_type(&self) -> &'static str {
match self {
TargetKind::Local => "local",
TargetKind::Kubernetes => "k8s",
TargetKind::DockerCompose => "docker-compose",
}
}
}
#[derive(Debug, Clone)]
pub enum LiveUpdateStep {
Sync { local: String, remote: String },
Run { cmd: String },
FallBackOn(#[allow(dead_code)] Vec<String>),
RestartContainer,
InitialSync,
}
#[derive(Debug, Clone)]
pub struct DockerBuild {
pub image_ref: String,
pub context: PathBuf,
pub dockerfile: Option<PathBuf>,
#[allow(dead_code)]
pub target: Option<String>,
pub build_args: Vec<(String, String)>,
pub command: Option<Cmd>,
pub deps: Vec<PathBuf>,
pub live_update: Vec<LiveUpdateStep>,
}
#[derive(Debug, Clone)]
pub struct Manifest {
pub name: String,
pub kind: TargetKind,
pub update_cmd: Cmd,
pub serve_cmd: Cmd,
pub serve_port: Option<u16>,
pub deps: Vec<PathBuf>,
pub resource_deps: Vec<String>,
pub trigger_mode: i32,
pub links: Vec<(String, String)>,
pub labels: std::collections::BTreeMap<String, String>,
pub notes: Vec<String>,
pub auto_init: bool,
pub k8s_apply_docs: Vec<String>,
pub docker_builds: Vec<DockerBuild>,
pub k8s_workload: Option<String>,
pub pod_selector: std::collections::BTreeMap<String, String>,
pub live_update: Vec<LiveUpdateStep>,
}
impl Manifest {
pub fn auto_on_change(&self) -> bool {
matches!(self.trigger_mode, 0 | 3)
}
pub fn new(name: impl Into<String>, kind: TargetKind) -> Self {
Manifest {
name: name.into(),
kind,
update_cmd: Cmd::default(),
serve_cmd: Cmd::default(),
serve_port: None,
deps: vec![],
resource_deps: vec![],
trigger_mode: 0,
links: vec![],
labels: std::collections::BTreeMap::new(),
notes: vec![],
auto_init: true,
k8s_apply_docs: vec![],
docker_builds: vec![],
k8s_workload: None,
pod_selector: std::collections::BTreeMap::new(),
live_update: vec![],
}
}
}