Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev7 #9

Merged
merged 9 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [0.7.0] - TODO
### Fixes
- Fixed that `ContainerNetwork`s were using the `name` for hostnames instead of the `host_name` that
was meant for that purpose
- `Command` stdout copiers no longer panic on invalid utf-8

### Changes
- `Command` and `CommandResult` stdout and stderr are now `Vec<u8>` instead of `String`
- `ContainerNetwork` now adds on a UUID suffix to docker names and hostnames in order to allow
running them in parallel
- there are no more `track_caller` functions, use `stacked_errors`
- Many dependency updates, use `postcard` internally instead of `bincode`

### Additions
- Added `CommandResult::stdout_as_utf8` and some other related functions for convenience
- Added `ContainerNetwork::terminate_containers` which just terminates containers and not the
network

## [0.6.0] - 2023-10-07
### Changes
- `stacked_errors` 0.4.0, and removal of several now unnecessary feature flags
Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "super_orchestrator"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
authors = ["Aaron Kutch <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -11,21 +11,22 @@ keywords = ["container", "docker"]
description = "advanced container orchestration tools"

[dependencies]
bincode = { version = "1.3" }
clap = { version = "4.2", features = ["derive"] }
ctrlc = { version = "3.0", optional = true, default-features = false }
clap = { version = "4", features = ["derive"] }
ctrlc = { version = "3", optional = true, default-features = false }
env_logger = { version = "0.10", optional = true, default-features = false }
log = "0.4"
nix = { version = "0.26", optional = true, default-features = false, features = ["signal"] }
nix = { version = "0.27", optional = true, default-features = false, features = ["signal"] }
owo-colors = { version = "3.5", default-features = false }
postcard = { version = "1", features = ["use-std"] }
serde = { version = "1.0" }
serde_json = { version = "1.0" }
serde_yaml = { version = "0.9" }
sha3 = "0.10"
stacked_errors = { version = "0.4", default-features = false }
#stacked_errors = { git = "https://github.com/AaronKutch/stacked_errors", rev = "74d52fd24ff7ec1faab4f2065f37ff356f089137", default-features = false }
#stacked_errors = { path = "../stacked_errors", default-features = false }
tokio = { version = "1.29", features = ["full"] }
tokio = { version = "1", features = ["full"] }
uuid = { version = "1", features = ["v4"] }

[features]
default = ["ctrlc_support", "env_logger_support", "nix_support"]
Expand Down
60 changes: 42 additions & 18 deletions examples/docker_entrypoint_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ const TIMEOUT: Duration = Duration::from_secs(300);
struct Args {
/// If left `None`, the container runner program runs, otherwise this
/// specifies the entrypoint to run
#[arg(short, long)]
#[arg(long)]
entry_name: Option<String>,
/// In order to enable simultaneous `super_orchestrator` uses with the same
/// names, UUIDs are appended to some things such as the hostname. This
/// is used to pass the information around.
#[arg(long)]
uuid: Option<String>,
}

#[tokio::main]
Expand All @@ -37,13 +42,13 @@ async fn main() -> Result<()> {

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

Expand All @@ -59,7 +64,7 @@ async fn container_runner() -> Result<()> {
// "--target",
// container_target,
//])
//.await?;
//.await.stack()?;
//let entrypoint =
// &format!("./target/{container_target}/release/{bin_entrypoint}");

Expand All @@ -69,7 +74,8 @@ async fn container_runner() -> Result<()> {
"--target",
container_target,
])
.await?;
.await
.stack()?;
let entrypoint = Some(format!(
"./target/{container_target}/release/examples/{bin_entrypoint}"
));
Expand Down Expand Up @@ -107,25 +113,37 @@ async fn container_runner() -> Result<()> {
// TODO see issue on `ContainerNetwork` struct documentation
true,
logs_dir,
)?
)
.stack()?;
// check the local ./logs directory
.add_common_volumes(&[(logs_dir, "/logs")]);
cn.run_all(true).await?;
cn.add_common_volumes(&[(logs_dir, "/logs")]);
let uuid = cn.uuid_as_string();
// passing UUID information through common arguments
cn.add_common_entrypoint_args(&["--uuid", &uuid]);
cn.run_all(true).await.stack()?;

// container2 ends early
cn.wait_with_timeout(&mut vec!["container2".to_owned()], true, TIMEOUT)
.await?;
.await
.stack()?;
assert_eq!(cn.active_names(), &["container0", "container1"]);
assert_eq!(cn.inactive_names(), &["container2"]);

info!("waiting on rest of containers to finish");
cn.wait_with_timeout_all(true, TIMEOUT).await?;
cn.wait_with_timeout_all(true, TIMEOUT).await.stack()?;
// there will be a warning if we do not properly terminate the container network
// and there are still running containers or docker networks when the
// `ContainerNetwork` is dropped
cn.terminate_all().await;
Ok(())
}

async fn container0_runner() -> Result<()> {
let host = "container1:26000";
let mut nm = NetMessenger::connect(STD_TRIES, STD_DELAY, host)
async fn container0_runner(args: &Args) -> Result<()> {
// it might seem annoying to use `stack` at every fallible point, but this is
// more than worth it when trying to decipher where an error is coming from
let uuid = args.uuid.clone().stack()?;
let container1_host = &format!("container1_{}:26000", uuid);
let mut nm = NetMessenger::connect(STD_TRIES, STD_DELAY, container1_host)
.await
.stack()?;
let s = "hello world".to_owned();
Expand All @@ -138,18 +156,24 @@ async fn container0_runner() -> Result<()> {
// check out the results of a panic
//panic!("uh oh");

info!("container 0 runner is waiting for 20 seconds");
info!("container 0 runner is waiting for 20 seconds before sending");
sleep(Duration::from_secs(20)).await;
nm.send::<String>(&s).await?;
nm.send::<String>(&s).await.stack()?;

Ok(())
}

async fn container1_runner() -> Result<()> {
let host = "0.0.0.0:26000";
let mut nm = NetMessenger::listen_single_connect(host, TIMEOUT).await?;
let mut nm = NetMessenger::listen_single_connect(host, TIMEOUT)
.await
.stack()?;

info!("container 1 runner is waiting to get something from container 0");
let s: String = nm.recv().await?;
let s: String = nm.recv().await.stack()?;
info!("container 1 received \"{s}\"");

assert_eq!(&s, "hello world");

Ok(())
}
Loading
Loading