Compare commits
5 Commits
89a8b86aab
...
d2296d7ac8
Author | SHA1 | Date |
---|---|---|
Joe Bellus | d2296d7ac8 | |
Joe Bellus | 18c062f00d | |
Joe Bellus | ee7677625b | |
Joe Bellus | 4725786ee1 | |
Joe Bellus | d49cfb3a36 |
14
.drone.yml
14
.drone.yml
|
@ -13,14 +13,14 @@ steps:
|
||||||
image: rust:latest
|
image: rust:latest
|
||||||
commands:
|
commands:
|
||||||
- cargo build --release
|
- cargo build --release
|
||||||
- tar cvzf conductor.tar.gz -C target/release/conductor conductor
|
- tar cvzf conductor.tar.gz -C target/release conductor
|
||||||
- wget https://dl.min.io/client/mc/release/linux-amd64/mc
|
- wget https://dl.min.io/client/mc/release/linux-amd64/mc
|
||||||
- chmod +x mc
|
- chmod +x mc
|
||||||
- ./mc alias set fivesigma https://objects.5sigma.io $MINIOID $MINIOSECRET
|
- ./mc alias set fivesigma https://objects.5sigma.io $MINIOID $MINIOSECRET
|
||||||
- ./mc cp conductor.tar.gz fivesigma/public/conductor.tar.gz
|
- ./mc cp conductor.tar.gz fivesigma/public/conductor.tar.gz
|
||||||
# when:
|
when:
|
||||||
# event:
|
event:
|
||||||
# - promote
|
- promote
|
||||||
# target:
|
target:
|
||||||
# - staging
|
- staging
|
||||||
# - production
|
- production
|
||||||
|
|
|
@ -193,7 +193,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "conductor"
|
name = "conductor"
|
||||||
version = "0.1.0"
|
version = "2.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix",
|
"actix",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "conductor"
|
name = "conductor"
|
||||||
version = "0.1.0"
|
version = "2.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -28,6 +28,15 @@ impl From<&str> for Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Command {
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Command::Multiple(v) => v.is_empty(),
|
||||||
|
Command::Single(v) => v.is_empty(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Command {
|
impl std::fmt::Display for Command {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -98,7 +107,7 @@ impl Project {
|
||||||
.flat_map(|jobs| jobs.to_vec())
|
.flat_map(|jobs| jobs.to_vec())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
jobs.push(job);
|
jobs.push(job);
|
||||||
Jobs::new(jobs)
|
Jobs::new(jobs.into_iter().filter(|t| !t.command.is_empty()).collect())
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
self.components.iter().find_map(|(c_name, component)| {
|
self.components.iter().find_map(|(c_name, component)| {
|
||||||
|
@ -137,7 +146,7 @@ impl Project {
|
||||||
.flat_map(|jobs| jobs.to_vec())
|
.flat_map(|jobs| jobs.to_vec())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
jobs.push(job);
|
jobs.push(job);
|
||||||
Jobs::new(jobs)
|
Jobs::new(jobs.into_iter().filter(|t| !t.command.is_empty()).collect())
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -311,7 +320,7 @@ impl Default for Component {
|
||||||
#[derive(Serialize, Deserialize, Default, Clone)]
|
#[derive(Serialize, Deserialize, Default, Clone)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct TaskDefinition {
|
pub struct TaskDefinition {
|
||||||
pub description: String,
|
pub description: Option<String>,
|
||||||
/// A map of environment variables that are provided before running the task
|
/// A map of environment variables that are provided before running the task
|
||||||
pub env: HashMap<String, String>,
|
pub env: HashMap<String, String>,
|
||||||
/// The command(s) to execute when the task is launched
|
/// The command(s) to execute when the task is launched
|
||||||
|
@ -329,6 +338,7 @@ impl From<&TaskDefinition> for Job {
|
||||||
command: source.command.clone(),
|
command: source.command.clone(),
|
||||||
retry: false,
|
retry: false,
|
||||||
keep_alive: false,
|
keep_alive: false,
|
||||||
|
path: source.path.clone().unwrap_or_else(|| String::from(".")),
|
||||||
retry_delay: 0,
|
retry_delay: 0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run() -> anyhow::Result<()> {
|
pub async fn run() -> anyhow::Result<()> {
|
||||||
let cfg_path = find_config("conductor.yml").unwrap();
|
let cfg_path = find_config("conductor.yml")
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("No config file found. Create a conductor.yml.\nSee http://conductor.5sigma.io/articles/config"))?;
|
||||||
|
|
||||||
std::env::set_current_dir(cfg_path.parent().unwrap())?;
|
std::env::set_current_dir(cfg_path.parent().unwrap())?;
|
||||||
|
|
||||||
let config_str = std::fs::read_to_string(cfg_path).unwrap();
|
let config_str = std::fs::read_to_string(cfg_path)?;
|
||||||
let project = Project::load_str(&config_str).unwrap();
|
let project = Project::load_str(&config_str)?;
|
||||||
|
|
||||||
let args = std::env::args();
|
let args = std::env::args();
|
||||||
|
|
||||||
|
|
19
src/term.rs
19
src/term.rs
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt::Display};
|
||||||
|
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
|
|
||||||
use crate::definition::{Group, Project};
|
use crate::definition::{Group, Project, TaskDefinition};
|
||||||
|
|
||||||
pub fn header<T: Into<String>>(name: T, msg: &str) {
|
pub fn header<T: Into<String>>(name: T, msg: &str) {
|
||||||
let text = format!(" - --=[ {: <20} {: >20} ]=-- -", name.into(), msg);
|
let text = format!(" - --=[ {: <20} {: >20} ]=-- -", name.into(), msg);
|
||||||
|
@ -50,12 +50,13 @@ pub fn item_list(project: &Project) {
|
||||||
if project.tasks.is_empty() && project.components.values().all(|c| c.tasks.is_empty()) {
|
if project.tasks.is_empty() && project.components.values().all(|c| c.tasks.is_empty()) {
|
||||||
println!("{}", Color::White.dimmed().paint("no tasks defined"));
|
println!("{}", Color::White.dimmed().paint("no tasks defined"));
|
||||||
} else {
|
} else {
|
||||||
for (name, _tasks) in sort_map(&project.tasks).iter() {
|
for (name, task) in sort_map(&project.tasks).iter() {
|
||||||
println!("{}", name);
|
print_task(name, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (c_name, component) in sort_map(&project.components).iter() {
|
for (c_name, component) in sort_map(&project.components).iter() {
|
||||||
for (t_name, _tasks) in sort_map(&component.tasks).iter() {
|
for (t_name, task) in sort_map(&component.tasks).iter() {
|
||||||
println!("{}:{}", c_name, t_name);
|
print_task(&format!("{}:{}", c_name, t_name), task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,14 @@ where
|
||||||
items
|
items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_task(name: &str, task: &TaskDefinition) {
|
||||||
|
if let Some(ref desc) = task.description {
|
||||||
|
println!("{: <31}{}", name, desc);
|
||||||
|
} else {
|
||||||
|
println!("{}", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn print_group(name: &str, group: &Group) {
|
fn print_group(name: &str, group: &Group) {
|
||||||
if let Some(ref desc) = group.description {
|
if let Some(ref desc) = group.description {
|
||||||
println!("{: <31}{}", name, desc);
|
println!("{: <31}{}", name, desc);
|
||||||
|
|
Loading…
Reference in New Issue