-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper to run
cargo windsock --cloud
within docker for libc com…
…patibility reasons (#1309) Co-authored-by: Conor <[email protected]>
- Loading branch information
Showing
7 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters