Skip to content

Commit 4c62005

Browse files
author
Lucas Kent
committed
ec2-cargo-fixes
1 parent 609b5ef commit 4c62005

File tree

6 files changed

+274
-372
lines changed

6 files changed

+274
-372
lines changed

Cargo.lock

Lines changed: 6 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ec2-cargo/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ description = "A tool for running cargo commands in an EC2 instance"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11+
anyhow.workspace = true
1112
tokio.workspace = true
1213
clap.workspace = true
1314
tracing-subscriber.workspace = true
1415
aws-throwaway.workspace = true
1516
tracing-appender.workspace = true
16-
shellfish = { version = "0.10.0", features = ["async"] }
17+
serde.workspace = true
18+
serde_json.workspace = true
1719
cargo_metadata = "0.23.0"
1820
shell-quote.workspace = true

ec2-cargo/readme.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
ec2-cargo is a small tool for running shotover tests on an EC2 instance.
44

5+
Instance state is persisted to disk between invocations, so each command is a short-lived process that connects, does its work, and exits.
6+
57
## AWS credentials
68

79
Refer to the [aws-sdk docs](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/credentials.html) for full information on credentials.
@@ -24,22 +26,30 @@ Replace `TODO` with your credentials.
2426

2527
Then invoke like `ec2-cargo.sh your-flags-here`
2628

27-
## Running
28-
29-
ec2-cargo has reasonable default configurations so you can just:
30-
31-
* `cargo run` the project to use default credentials
32-
* `ec2-cargo.sh` to use specific env vars as described above.
33-
34-
You can also specify the instance type e.g. `ec2-cargo.sh --instance-type c7g.2xlarge`
35-
3629
## Usage
3730

38-
While the tool is running it will present you with a shell in which to enter commands.
39-
40-
Some possible commands are:
31+
```bash
32+
# Create and provision an EC2 instance (one-time setup)
33+
# Before creating the new instance, any existing ec2 instances created by ec2-cargo will be destroyed
34+
cargo run -- create
35+
# Or,
36+
# cargo run -- create --instance-type c7g.2xlarge
37+
38+
# Run tests (can be called repeatedly against the same instance)
39+
cargo run -- test my_test_name
40+
cargo run -- test --test-threads=1
41+
42+
# Run windsock benchmarks
43+
cargo run -- windsock $args
44+
cargo run -- windsock-kafka $args
45+
cargo run -- windsock-cassandra $args
46+
cargo run -- windsock-valkey $args
47+
48+
# Print SSH connection instructions
49+
cargo run -- ssh-instructions
50+
51+
# Tear down all AWS resources and delete the persisted state
52+
cargo run -- cleanup
53+
```
4154

42-
* `test $args` - Uploads shotover project source code and runs `cargo nextest run $args`
43-
* `ssh-instructions` - Print a bash snippet that can be used to ssh into the machine
44-
* `exit` - Exits the shell and terminates the EC2 instance.
45-
* `help` - Display all possible commands
55+
Or using the script setup: `ec2-cargo.sh create`, `ec2-cargo.sh test my_test_name`, etc.

ec2-cargo/src/cli.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use clap::{Parser, Subcommand};
2+
3+
/// A tool for running cargo commands on an EC2 instance.
4+
///
5+
/// Create an instance with `create`, run commands against it with `test`/`windsock`/etc,
6+
/// and tear it down with `cleanup`. Instance state is persisted to disk between invocations.
7+
#[derive(Parser)]
8+
#[clap()]
9+
pub struct Args {
10+
#[command(subcommand)]
11+
pub command: Cmd,
12+
}
13+
14+
#[derive(Subcommand)]
15+
pub enum Cmd {
16+
/// Create and provision an EC2 instance, persisting node address+credentials to disk for other commands to use.
17+
Create {
18+
/// Specify the instance type to provision.
19+
#[clap(long, default_value = "c7g.2xlarge")]
20+
instance_type: String,
21+
},
22+
23+
/// Upload changes and run `cargo nextest run <args>`.
24+
Test {
25+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
26+
args: Vec<String>,
27+
},
28+
29+
/// Upload changes and run `cargo windsock <args>`. Windsock results are downloaded to target/windsock_data.
30+
Windsock {
31+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
32+
args: Vec<String>,
33+
},
34+
35+
/// Upload changes and run `cargo windsock-kafka <args>`. Windsock results are downloaded to target/windsock_data.
36+
WindsockKafka {
37+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
38+
args: Vec<String>,
39+
},
40+
41+
/// Upload changes and run `cargo windsock-cassandra <args>`. Windsock results are downloaded to target/windsock_data.
42+
WindsockCassandra {
43+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
44+
args: Vec<String>,
45+
},
46+
47+
/// Upload changes and run `cargo windsock-valkey <args>`. Windsock results are downloaded to target/windsock_data.
48+
WindsockValkey {
49+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
50+
args: Vec<String>,
51+
},
52+
53+
/// Print a bash snippet that can be used to ssh into the machine.
54+
SshInstructions,
55+
56+
/// Cleanup all AWS resources and delete the persisted state file.
57+
/// This includes resources created by ec2-cargo and resources created by windsock, as they both use the same aws-throwaway library.
58+
/// But note that windsock's cleanup logic avoids cleaning up ec2-cargo resources.
59+
Cleanup,
60+
}

0 commit comments

Comments
 (0)