10 Commits
1.0.8 ... 1.1.0

Author SHA1 Message Date
52f4e54bc4 Fix CI 2023-09-07 18:26:18 +03:00
9dc659cea1 Fix CI 2023-09-07 18:24:54 +03:00
1235e17f6b Fix CI 2023-09-07 17:55:38 +03:00
aaa28eae67 Fix CI 2023-09-07 17:54:43 +03:00
c016ef8a0f Added multiple -e 2023-09-07 17:41:12 +03:00
13ab3f3dbd Update README.md 2023-09-07 17:01:23 +03:00
70136e9074 Improve readability 2023-09-07 16:05:38 +03:00
2334c1a8f3 Fix logging 2023-09-07 15:34:13 +03:00
da6ae2ce37 Improve readability 2023-09-07 15:33:15 +03:00
e2cc36adf1 Drop ARM build 2023-09-07 15:06:24 +03:00
7 changed files with 88 additions and 115 deletions

View File

@ -1,39 +0,0 @@
name: ARM Rust static build and publish
on: ["push"]
# push:
# tags:
# - '*'
#
env:
CARGO_TERM_COLOR: always
BUILD_TARGET: x86_64-unknown-linux-musl
BINARY_NAME: rexec
jobs:
build:
name: Build static binary
runs-on: self-hosted
container:
image: rust:latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
# - uses: dtolnay/rust-toolchain@stable
# - name: Build-musl
# uses: gmiam/rust-musl-action@master
# with:
# args: cargo build --target $BUILD_TARGET --release
- name: Deps
run: |
rustup target add x86_64-unknown-linux-musl
cargo build --target ${{ env.BUILD_TARGET }} --release
- name: Get version
run: echo "VERSION=$(grep -P '^version = \"\d+\.\d+\.\d+\"' Cargo.toml | awk -F '\"' '{print $2}')" >> $GITHUB_ENV
- name: Show version
run: echo ${{ env.VERSION }}
- uses: actions/upload-artifact@v3.1.2
name: Upload artifact
with:
name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
path: target/${{ env.BUILD_TARGET }}/release/${{ env.BINARY_NAME }}

View File

@ -96,3 +96,22 @@ jobs:
artifacts: "${{ steps.download_binary.outputs.download-path }}/*,${{ steps.download_pkg.outputs.download-path }}/*"
allowUpdates: true
body: Static musl build for x86_64-linux and Arch Linux package
dispatch:
name: Notify my Arch Repo
needs:
- build
- build_arch
- release
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Dispatch to workflows
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ACTIONS_KEY }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/house-of-vanity/arch_repo/dispatches \
-d '{"event_type":"new_package","client_payload":{}}'

15
.github/workflows/update_repo.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Dispatcher
on: ["push"]
jobs:
dispatch:
name: Dispatch
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Dispatch to workflows
run: |
curl -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${{ secrets.ACTIONS_KEY }}" \
--request POST \
--data '{"event_type": "some_event", "client_payload": { "foo": "bar" }}' https://api.github.com/repos/house-of-vanity/arch_repo/dispatches

2
Cargo.lock generated
View File

@ -1066,7 +1066,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rexec"
version = "1.0.8"
version = "1.0.9"
dependencies = [
"brace-expand",
"clap 4.3.4",

View File

@ -1,6 +1,6 @@
[package]
name = "rexec"
version = "1.0.8"
version = "1.1.0"
readme = "https://github.com/house-of-vanity/rexec#readme"
edition = "2021"
description = "Parallel SSH executor"
@ -22,7 +22,6 @@ lazy-st = "0.2.2"
regex = "1"
clap = { version = "4.3.4", features = ["derive"] }
colored = "2.0.0"
#dialoguer = "0.10.4"
itertools = "0.10.5"
brace-expand = "0.1.0"
question = "0.2.2"

View File

@ -32,63 +32,31 @@ Options:
```
---
![image](https://github.com/house-of-vanity/rexec/assets/4666566/4c52915d-2bc1-46b9-9833-b0d7c0527f2d)
## Examples
```shell
[ab@test]$ rexec -e 'cassandra-gce-sc-[1:3].bbs-prod.*' -u ab -c 'df -h /srv/cassandra'
$ rexec -f \
-e 'cassandra-gce-or-[1:2]' \
-u ab \
-c 'uname -r; date'
[INFO ] Using string expansion to build server list.
[INFO ] Matched hosts:
[INFO ] cassandra-gce-sc-1.bbs-prod.* [35.221.18.35]
[INFO ] cassandra-gce-sc-2.bbs-prod.* [35.212.13.174]
[INFO ] cassandra-gce-sc-3.bbs-prod.* [35.211.213.123]
Continue on following 3 servers? y
[INFO ]
[INFO ] Run command on 3 servers.
[INFO ]
[INFO ] cassandra-gce-sc-2.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 613G 411G 60% /srv/cassandra
[INFO ] cassandra-gce-or-1.prod.example.com [2.22.123.79]
[INFO ] cassandra-gce-or-2.prod.example.com [2.22.123.158]
Continue on following 2 servers? y
[INFO ] Run command on 2 servers.
[INFO ] cassandra-gce-sc-1.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 594G 430G 59% /srv/cassandra
cassandra-gce-or-1.prod.example.com
Exit code [0] / stdout 45 bytes / stderr 0 bytes
STDOUT
║ 5.15.0-1040-gcp
║ Thu Sep 7 13:44:40 UTC 2023
[INFO ] cassandra-gce-sc-3.bbs-prod.*
Code 0
STDOUT:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-cassandra 1.0T 523G 502G 52% /srv/cassandra
```
---
```shell
[ab@test]$ ./rexec -u ab -k -c uptime -e admin.* -f
[INFO ] Matched hosts:
[INFO ] admin-gce-sc-1.lca-prod.** [35.211.27.195]
[INFO ] admin-gce-sc-1.mmk-prod.** [35.211.79.202]
[ERROR] admin-gce-sc-1.led-prod.** couldn't be resolved.
[INFO ] admin-gce-sc-1.msq-dev.** [35.211.0.24]
[ERROR] admin-gce-sc-1.hui-dev.** couldn't be resolved.
[INFO ] Run command on 3 servers.
[INFO ] admin.gnb-prod.**
Code 0
STDOUT:
23:31:21 up 294 days, 14:14, 0 users, load average: 0.53, 0.64, 0.52
[INFO ] admin.abe-prod.**
Code 0
STDOUT:
23:31:22 up 154 days, 9:24, 0 users, load average: 0.31, 0.25, 0.18
[INFO ] admin-gce-be-1.toy-prod.**
Code 0
STDOUT:
23:31:22 up 98 days, 6:20, 0 users, load average: 0.88, 0.74, 0.80
cassandra-gce-or-2.prod.example.com
Exit code [0] / stdout 45 bytes / stderr 0 bytes
STDOUT
║ 5.15.0-1040-gcp
║ Thu Sep 7 13:44:40 UTC 2023
```

View File

@ -34,9 +34,10 @@ struct Args {
#[arg(
short,
long,
num_args = 1..,
help = "Expression to build server list. List and range expansion are supported. Example: 'web-[1:12]-io-{prod,dev}'"
)]
expression: String,
expression: Vec<String>,
#[arg(short, long, help = "Command to execute on servers")]
command: String,
@ -156,22 +157,30 @@ fn main() {
let hosts = if args.known_hosts {
info!("Using ~/.ssh/known_hosts to build server list.");
let known_hosts = read_known_hosts();
// Build regex
let re = match Regex::new(&args.expression) {
Ok(result) => result,
Err(e) => {
error!("Error parsing regex. {}", e);
process::exit(1);
}
};
// match hostnames from known_hosts to regex
known_hosts
.into_iter()
.filter(|r| re.is_match(&r.name.clone()))
.collect()
let mut all_hosts = Vec::new();
for expression in args.expression.iter() {
let re = match Regex::new(expression) {
Ok(result) => result,
Err(e) => {
error!("Error parsing regex. {}", e);
process::exit(1);
}
};
let matched: Vec<Host> = known_hosts
.clone()
.into_iter()
.filter(|r| re.is_match(&r.name.clone()))
.collect();
all_hosts.extend(matched);
}
all_hosts
} else {
info!("Using string expansion to build server list.");
expand_string(&args.expression)
let mut all_hosts = Vec::new();
for expression in args.expression.iter() {
all_hosts.extend(expand_string(expression));
}
all_hosts
};
// Dedup hosts from known_hosts file
@ -270,7 +279,7 @@ fn main() {
println!(
"{}",
format!(
"Exit code [{}] / stdout {} bytes / stderr {} bytes",
"Exit code [{}] | std out/err [{}/{}] bytes",
code_string,
output.stdout.len(),
output.stderr.len()
@ -283,10 +292,13 @@ fn main() {
Ok(stdout) => match stdout.as_str() {
"" => {}
_ => {
println!("{}", "STDOUT".bold().blue());
let prefix = if output.exit_status != 0 {
format!("{}", "".cyan())
} else {
format!("{}", "".green())
};
for line in stdout.lines() {
println!("{} {}", "".green(), line);
println!("{} {}", prefix, line);
}
}
},
@ -296,7 +308,6 @@ fn main() {
Ok(stderr) => match stderr.as_str() {
"" => {}
_ => {
println!("{}", "STDERR".bold().bright_red());
for line in stderr.lines() {
println!("{} {}", "".red(), line);
}