Skip to content

Commit

Permalink
Add windsock-cloud-docker helper
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Aug 28, 2023
1 parent 679e5bd commit 317b781
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 2 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ linker = "aarch64-linux-gnu-gcc"
[alias]
windsock = "test --release --bench windsock --features alpha-transforms --"
windsock-debug = "test --bench windsock --features alpha-transforms --"
windsock-cloud-docker = "run --package windsock-cloud-docker --"
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[workspace]
members = ["windsock", "shotover", "shotover-proxy", "test-helpers", "custom-transforms-example", "ec2-cargo"]
members = [
"windsock",
"shotover",
"shotover-proxy",
"test-helpers",
"custom-transforms-example",
"ec2-cargo",
"windsock-cloud-docker"
]
resolver = "2"

# https://deterministic.space/high-performance-rust.html
Expand Down
2 changes: 1 addition & 1 deletion test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use subprocess::{Exec, Redirection};
/// # Arguments
/// * `command` - The system command to run
/// * `args` - An array of command line arguments for the command
pub(crate) fn run_command(command: &str, args: &[&str]) -> Result<String> {
pub fn run_command(command: &str, args: &[&str]) -> Result<String> {
tracing::trace!("executing {}", command);
let data = Exec::cmd(command)
.args(args)
Expand Down
10 changes: 10 additions & 0 deletions windsock-cloud-docker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "windsock-cloud-docker"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
test-helpers = {path = "../test-helpers"}
86 changes: 86 additions & 0 deletions windsock-cloud-docker/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// A helper to run `windsock --cloud` within docker to workaround libc issues
// It is not possible to use this helper to run windsock locally as that would involve running docker within docker

use test_helpers::run_command;

fn main() {
let mut args = std::env::args();
args.next(); // skip binary name
let args: Vec<String> = args.collect();
let args = args.join(" ");

// ensure container is setup
let container_status = docker(&[
"container",
"ls",
"-a",
"--filter",
"Name=windsock-cloud",
"--format",
"{{.Status}}",
]);
if container_status.starts_with("Exited") {
docker(&["start", "windsock-cloud"]);
} else if !container_status.starts_with("Up") {
docker(&[
"run",
"-d",
"--name",
"windsock-cloud",
"ubuntu:20.04",
"sleep",
"infinity",
]);
container_bash("apt-get update");
container_bash(
"DEBIAN_FRONTEND=noninteractive apt-get install -y curl git cmake pkg-config g++ libssl-dev librdkafka-dev uidmap",
);
container_bash("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y");
}

// copy in shotover project
let root = std::env::current_dir().unwrap();
container_bash("rm -r /shotover-proxy");
// TODO: This copy will be very expensive if the user doesnt have their target directory setup as a symlink
// Maybe we should do something like:
// 1. rsync to target/shotover-copy-for-docker with the target directory filtered out
// 2. `docker cp target/shotover-copy-for-docker windsock-cloud:/shotover-proxy`
docker(&[
"cp",
root.to_str().unwrap(),
"windsock-cloud:/shotover-proxy",
]);
container_bash("rm -r /shotover-proxy/target");

// run windsock
let access_key_id = std::env::var("AWS_ACCESS_KEY_ID").unwrap();
let secret_access_key = std::env::var("AWS_SECRET_ACCESS_KEY").unwrap();
container_bash(&format!(
r#"cd shotover-proxy;
source "$HOME/.cargo/env";
AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} CARGO_TERM_COLOR=always cargo test --target-dir /target --release --bench windsock --features alpha-transforms -- {args}"#
));
}

pub fn docker(args: &[&str]) -> String {
run_command("docker", args).unwrap()
}

pub fn container_bash(command: &str) {
run_command_to_stdout("docker", &["exec", "windsock-cloud", "bash", "-c", command])
}

pub fn run_command_to_stdout(command: &str, args: &[&str]) {
let status = std::process::Command::new("docker")
.args(args)
.status()
.unwrap();

if !status.success() {
println!(
"Failed to run windsock, command {} {:?} exited with {:?}",
command, args, status
);
std::process::exit(status.code().unwrap_or(1))
}
}
8 changes: 8 additions & 0 deletions windsock/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ pub(crate) fn display_results_table(reports: &[ReportColumn]) {
}

fn base(reports: &[ReportColumn], table_type: &str) {
// if the user has set CARGO_TERM_COLOR to force cargo to use colors then they probably want us to use colors too
if std::env::var("CARGO_TERM_COLOR")
.map(|x| x.to_lowercase() == "always")
.unwrap_or(false)
{
console::set_colors_enabled(true);
}

let mut intersection = reports[0].current.tags.clone();
for report in reports {
intersection = intersection.intersection(&report.current.tags);
Expand Down

0 comments on commit 317b781

Please sign in to comment.