Skip to content

Commit

Permalink
Merge pull request #24 from AaronKutch/dev15
Browse files Browse the repository at this point in the history
Dev15
  • Loading branch information
AaronKutch authored Jan 4, 2025
2 parents 060a570 + 5231c14 commit f9f56b7
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 476 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.15.0] - 2025-01-03
### Crate
- Updated to `stacked_errors` 0.7 which has significantly better debug

### Changes
- Moved `stacked_get*` to `stacked_errors`
- No longer export `stacked_errors` from this crate so that we don't have versioning problems when
`stacked_errors` becomes more stable.

## [0.14.0] - 2024-11-21
### Changes
- Updated to `stacked_errors` 0.6 which changes the MSRV to 1.81
Expand Down
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "super_orchestrator"
version = "0.14.0"
version = "0.15.0"
edition = "2021"
authors = ["Aaron Kutch <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -16,21 +16,22 @@ bstr = "1"
ctrlc = { version = "3", default-features = false }
dunce = "1.0"
nix = { version = "0.29", optional = true, default-features = false, features = ["signal"] }
owo-colors = { version = "4.0", default-features = false }
owo-colors = { version = "4.1", default-features = false }
postcard = { version = "1", features = ["use-std"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
sha3 = "0.10"
stacked_errors = "0.6"
#stacked_errors = { git = "https://github.com/AaronKutch/stacked_errors", rev = "3f216ecfaad63f58b9ca9e44c9b5814f4637c21b" }
#stacked_errors = { git = "https://github.com/AaronKutch/stacked_errors", rev = "f323882419ea4dca9e6985abf811a3bf1cb24dca" }
#stacked_errors = { path = "../stacked_errors" }
stacked_errors = "0.7"
thiserror = "2"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
uuid = { version = "1", features = ["v4"] }

[dev-dependencies]
clap = { version = "4", features = ["derive", "env"] }
tracing-subscriber = "0.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
default = []
Expand Down
9 changes: 5 additions & 4 deletions examples/basic_commands.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::time::Duration;

use stacked_errors::{ensure, ensure_eq, StackableErr};
use super_orchestrator::{
sh, stacked_errors::Result, Command, CommandResult, CommandResultNoDebug, FileOptions,
};
use stacked_errors::{ensure, ensure_eq, Result, StackableErr};
use super_orchestrator::{sh, Command, CommandResult, CommandResultNoDebug, FileOptions};
use tokio::time::sleep;
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down Expand Up @@ -215,5 +214,7 @@ async fn main() -> Result<()> {
comres.assert_success().stack()?;
ensure_eq!(comres.stdout_as_utf8().unwrap(), "hello\n");

info!("test completed successfully");

Ok(())
}
4 changes: 3 additions & 1 deletion examples/basic_containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn main() -> Result<()> {
.wait_get_ip_addr(20, Duration::from_millis(300), "example5")
.await
.stack()?;
dbg!(&host_ip);
info!("{}", &host_ip);

// use port 0 to just detect that the host container exists
wait_for_ok_lookup_host(2, Duration::from_millis(300), &format!("{host_ip:?}:0"))
Expand All @@ -121,5 +121,7 @@ async fn main() -> Result<()> {
// always run this at the end, ensuring the containers are logically terminated
cn.terminate_all().await;

info!("test completed successfully");

Ok(())
}
6 changes: 2 additions & 4 deletions examples/clean.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use stacked_errors::ensure;
use super_orchestrator::{
acquire_file_path, remove_files_in_dir, stacked_errors::Result, FileOptions,
};
use stacked_errors::{ensure, Result};
use super_orchestrator::{acquire_file_path, remove_files_in_dir, FileOptions};

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions examples/commands.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{io::Write, iter, time::Duration};

use clap::Parser;
use stacked_errors::{ensure, ensure_eq, StackableErr};
use super_orchestrator::{remove_files_in_dir, stacked_errors::Result, Command, FileOptions};
use stacked_errors::{ensure, ensure_eq, Result, StackableErr};
use super_orchestrator::{remove_files_in_dir, Command, FileOptions};
use tokio::time::sleep;
use tracing::info;

Expand Down
17 changes: 10 additions & 7 deletions examples/docker_entrypoint_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::Duration;

use clap::Parser;
use serde::{Deserialize, Serialize};
use stacked_errors::{ensure_eq, Error, Result, StackableErr};
use stacked_errors::{bail, ensure_eq, Result, StackableErr};
use super_orchestrator::{
ctrlc_init,
docker::{Container, ContainerNetwork, Dockerfile},
Expand All @@ -22,7 +22,7 @@ use super_orchestrator::{
use tokio::time::sleep;
use tracing::info;

const BASE_CONTAINER: &str = "alpine:3.20";
const BASE_CONTAINER: &str = "alpine:3.21";
// need this for Alpine
const TARGET: &str = "x86_64-unknown-linux-musl";

Expand Down Expand Up @@ -80,13 +80,13 @@ async fn main() -> Result<()> {

if let Some(ref s) = args.entry_name {
match s.as_str() {
"container0" => container0_runner(&args).await.stack(),
"container1" => container1_runner(&args).await.stack(),
"container2" => container2_runner(&args).await.stack(),
_ => Err(Error::from(format!("entrypoint \"{s}\" is not recognized"))),
"container0" => container0_runner(&args).await,
"container1" => container1_runner(&args).await,
"container2" => container2_runner(&args).await,
_ => bail!("entrypoint \"{s}\" is not recognized"),
}
} else {
container_runner(&args).await.stack()
container_runner(&args).await
}
}

Expand Down Expand Up @@ -208,6 +208,9 @@ async fn container_runner(args: &Args) -> Result<()> {
// passing UUID information through common arguments
cn.add_common_entrypoint_args(["--uuid", &uuid]);

// debug the build step
cn.debug_build(true);

// Whenever using the docker entrypoint pattern or similar setup where there is
// a dedicated container runner function that is just calling
// `wait_with_timeout` before `terminate_all` and exiting, `ctrlc_init`
Expand Down
43 changes: 20 additions & 23 deletions examples/file_options.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use std::path::PathBuf;

use stacked_errors::{ensure, ensure_eq, StackableErr};
use super_orchestrator::{
close_file, remove_files_in_dir, stacked_errors::Result, FileOptions, ReadOrWrite,
};
use stacked_errors::{ensure, ensure_eq, Result, StackableErr};
use super_orchestrator::{close_file, remove_files_in_dir, FileOptions, ReadOrWrite};
use tokio::{
fs::{File, OpenOptions},
io::{AsyncReadExt, AsyncWriteExt},
};
use tracing::info;
use tracing::{debug, info};

#[tokio::main]
#[rustfmt::skip]
async fn main() -> Result<()> {
tracing_subscriber::fmt().init();
tracing_subscriber::fmt().with_env_filter("debug").init();

remove_files_in_dir("./logs/", &["example.log"])
.await
Expand Down Expand Up @@ -65,32 +63,31 @@ async fn main() -> Result<()> {
let e = FileOptions::write_str("./nonexistent/example.log", "test")
.await
.stack()
.unwrap_err()
.to_string();
println!("{}", e);
.unwrap_err();
debug!("{:?}", e);
// (omitting the line number and OS error from the test, but see the printed
// result)
ensure!(
e.contains(r#"FileOptions::write_str
FileOptions::acquire_file()
FileOptions { path: "./nonexistent/example.log", options: Write(WriteOptions { create: true, append: false }) }.preacquire() could not acquire directory
acquire_dir_path(dir_path: "./nonexistent")
BoxedError"#)
e.to_string().contains(r#"
FileOptions::write_str
FileOptions::acquire_file()
FileOptions { path: "./nonexistent/example.log", options: Write(WriteOptions { create: true, append: false }) }.preacquire() could not acquire directory
acquire_dir_path(dir_path: "./nonexistent")"#)
);

let e = FileOptions::read_to_string("./logs/nonexistent.log")
.await
.stack()
.unwrap_err()
.to_string();
println!("{}", e);
.unwrap_err();
debug!("{:?}", e);
// (omitting the line number and OS error from the test, but see the printed
// result)
ensure!(
e.contains(r#"FileOptions::read_to_string
FileOptions::acquire_file()
FileOptions { path: "./logs/nonexistent.log", options: Read }.precheck() could not acquire path to combined directory and file name
acquire_file_path(file_path:"#)
e.to_string().contains(r#"
FileOptions::read_to_string
FileOptions::acquire_file()
FileOptions { path: "./logs/nonexistent.log", options: Read }.precheck() could not acquire path to combined directory and file name
acquire_file_path(file_path:"#)
);

// the shorthand functions can be broken down into more steps if needed
Expand All @@ -99,13 +96,13 @@ acquire_file_path(file_path:"#)
.preacquire()
.await
.stack()?;
println!("checked path: {file_path:?}");
debug!("checked path: {file_path:?}");

let file: File = FileOptions::read("./logs/example.log")
.acquire_file()
.await
.stack()?;
println!("file: {file:?}");
debug!("file: {file:?}");

let mut file = FileOptions::new("./logs/example.log", ReadOrWrite::write(false, true))
.acquire_file()
Expand Down
6 changes: 2 additions & 4 deletions examples/paths.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use stacked_errors::{ensure, StackableErr};
use super_orchestrator::{
acquire_dir_path, acquire_file_path, acquire_path, stacked_errors::Result,
};
use stacked_errors::{ensure, Result, StackableErr};
use super_orchestrator::{acquire_dir_path, acquire_file_path, acquire_path};

#[rustfmt::skip]
#[tokio::main]
Expand Down
13 changes: 7 additions & 6 deletions examples/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
use std::time::Duration;

use clap::Parser;
use stacked_errors::{bail, Result, StackableErr};
use super_orchestrator::{
acquire_dir_path,
docker::{Container, ContainerNetwork, Dockerfile},
sh,
stacked_errors::{Error, Result, StackableErr},
wait_for_ok, Command,
sh, wait_for_ok, Command,
};
use tokio::{fs, time::sleep};
use tracing::info;

const BASE_CONTAINER: &str = "fedora:40";
const BASE_CONTAINER: &str = "fedora:41";
const TARGET: &str = "x86_64-unknown-linux-gnu";
const TIMEOUT: Duration = Duration::from_secs(3600);

Expand Down Expand Up @@ -57,7 +56,7 @@ async fn main() -> Result<()> {
if let Some(ref s) = args.entry_name {
match s.as_str() {
"test_runner" => test_runner().await,
_ => Err(Error::from(format!("entry_name \"{s}\" is not recognized"))),
_ => bail!("entry_name \"{s}\" is not recognized"),
}
} else {
container_runner(&args).await.stack()
Expand Down Expand Up @@ -95,13 +94,15 @@ async fn container_runner(args: &Args) -> Result<()> {
// because postgres doesn't like the .gitignore
let mut pg_data_path = acquire_dir_path(&args.pg_data_base_path)
.await
.stack_err(|| "you need to run from the repo root")?;
.stack_err("you need to run from the repo root")?;
pg_data_path.push(&args.pg_data_dir);
if acquire_dir_path(&pg_data_path).await.is_err() {
fs::create_dir_all(&pg_data_path).await.stack()?;
}

let mut cn = ContainerNetwork::new("test", Some(dockerfiles_dir), logs_dir);
// display all of the build steps
cn.debug_all(true);
cn.add_container(
Container::new("test_runner", Dockerfile::contents(test_dockerfile()))
.external_entrypoint(entrypoint, ["--entry-name", "test_runner"])
Expand Down
28 changes: 12 additions & 16 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
};

use serde::{Deserialize, Serialize};
use stacked_errors::{DisplayStr, Error, Result, StackableErr};
use stacked_errors::{bail_locationless, DisplayStr, Result, StackableErr};
use tokio::io::AsyncWriteExt;

use crate::{command_runner, CommandRunner, FileOptions};
Expand Down Expand Up @@ -372,7 +372,7 @@ impl Command {
pub async fn run_to_completion(self) -> Result<CommandResult> {
self.run()
.await
.stack_err_locationless(|| "Command::run_to_completion")?
.stack_err_locationless("Command::run_to_completion")?
.wait_with_output()
.await
}
Expand All @@ -383,11 +383,11 @@ impl Command {
let mut runner = self
.run_with_stdin(Stdio::piped())
.await
.stack_err_locationless(|| "Command::run_with_input_to_completion")?;
.stack_err_locationless("Command::run_with_input_to_completion")?;
let mut stdin = runner.child_process.as_mut().unwrap().stdin.take().unwrap();
stdin.write_all(input).await.stack_err_locationless(|| {
"Command::run_with_input_to_completion -> failed to write_all to process stdin"
})?;
stdin.write_all(input).await.stack_err_locationless(
"Command::run_with_input_to_completion -> failed to write_all to process stdin",
)?;
// needs to close to actually finish
drop(stdin);
runner.wait_with_output().await
Expand Down Expand Up @@ -468,14 +468,12 @@ impl CommandResult {
if status.success() {
Ok(())
} else {
Err(Error::from_kind_locationless(format!(
"{self:#?}.assert_success() -> unsuccessful"
)))
bail_locationless!("{self:#?}.assert_success() -> unsuccessful")
}
} else {
Err(Error::from_kind_locationless(format!(
bail_locationless!(
"{self:#?}.assert_success() -> termination was called before completion"
)))
)
}
}

Expand Down Expand Up @@ -563,14 +561,12 @@ impl CommandResultNoDebug {
if status.success() {
Ok(())
} else {
Err(Error::from_kind_locationless(format!(
"{self:#?}.assert_success() -> unsuccessful"
)))
bail_locationless!("{self:#?}.assert_success() -> unsuccessful")
}
} else {
Err(Error::from_kind_locationless(format!(
bail_locationless!(
"{self:#?}.assert_success() -> termination was called before completion"
)))
)
}
}

Expand Down
Loading

0 comments on commit f9f56b7

Please sign in to comment.