1 Commits

Author SHA1 Message Date
1eb9c5c17d Added multiple -e 2023-09-07 17:40:37 +03:00
6 changed files with 147 additions and 230 deletions

View File

@ -1,140 +1,98 @@
name: Rust static build and publish name: Rust static build and publish
on: on:
push: push:
tags: tags:
- 'v*.*.*' - '*'
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
BUILD_TARGET: x86_64-unknown-linux-musl
BINARY_NAME: rexec BINARY_NAME: rexec
jobs: jobs:
build: build:
name: Build static binary name: Build static binary
runs-on: ${{ matrix.os }} runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
build_target: x86_64-unknown-linux-musl
platform_name: linux-amd64
- os: windows-latest
build_target: x86_64-pc-windows-msvc
platform_name: windows-amd64
- os: macos-latest
build_target: aarch64-apple-darwin
platform_name: macos-arm64
permissions: permissions:
contents: write contents: write
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
- uses: mbrobbel/rustfmt-check@master - uses: mbrobbel/rustfmt-check@master
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Build-musl
- name: Install rust targets
run: rustup target add ${{ matrix.build_target }}
- name: Build Linux MUSL
if: matrix.os == 'ubuntu-latest'
uses: gmiam/rust-musl-action@master uses: gmiam/rust-musl-action@master
with: with:
args: cargo build --target ${{ matrix.build_target }} --release args: cargo build --target $BUILD_TARGET --release
- name: Build MacOS
if: matrix.os == 'macos-latest'
run: cargo build --target ${{ matrix.build_target }} --release
- name: Build Windows
if: matrix.os == 'windows-latest'
run: cargo build --target ${{ matrix.build_target }} --release
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }}
path: target/${{ matrix.build_target }}/release/${{ env.BINARY_NAME }}*
release:
name: Create Release Page
needs: build
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Get version - name: Get version
run: echo "VERSION=$(grep -P '^version = \"\d+\.\d+\.\d+\"' Cargo.toml | awk -F '\"' '{print $2}')" >> $GITHUB_ENV run: echo "VERSION=$(grep -P '^version = \"\d+\.\d+\.\d+\"' Cargo.toml | awk -F '\"' '{print $2}')" >> $GITHUB_ENV
- name: Show version - name: Show version
run: echo ${{ env.VERSION }} run: echo ${{ env.VERSION }}
- uses: ncipollo/release-action@v1 - uses: actions/upload-artifact@v3.1.2
id: create_release name: Upload artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
allowUpdates: true name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
body: "Релиз rexec версии ${{ env.VERSION }}. Статические сборки для Linux (x86_64), Windows (x86_64) и MacOS (arm64)." path: target/${{ env.BUILD_TARGET }}/release/${{ env.BINARY_NAME }}
build_arch:
upload: name: Arch Linux package
name: Upload Release Assets runs-on: ubuntu-latest
needs: release needs: ["build"]
runs-on: ${{ matrix.os }} container:
strategy: image: archlinux:base-devel
matrix: options: --user 1001
os: [ubuntu-latest, windows-latest, macos-latest] permissions:
include: contents: write
- os: ubuntu-latest
platform_name: linux-amd64
- os: windows-latest
platform_name: windows-amd64
- os: macos-latest
platform_name: macos-arm64
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Get version
- uses: actions/download-artifact@v4 run: echo "VERSION=$(grep -P '^version = \"\d+\.\d+\.\d+\"' Cargo.toml | awk -F '\"' '{print $2}')" >> $GITHUB_ENV
name: Download ${{ matrix.platform_name }} artifact - uses: actions/download-artifact@master
name: Download
id: download_binary
with: with:
name: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }} name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
path: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }} path: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
- name: Prepare build env
- name: Upload Release Asset run: |
uses: actions/upload-release-asset@v1 mkdir -p target/${{ env.BUILD_TARGET }}/release/
env: mv ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}/rexec target/${{ env.BUILD_TARGET }}/release/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} sed -i -e "s/some_ver/${{ env.VERSION }}/" PKGBUILD
- name: Build ZST package
run: |
makepkg -f
- uses: actions/upload-artifact@v3.1.2
name: Upload artifact
with: with:
upload_url: ${{ needs.release.outputs.upload_url }} name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}.zst
asset_path: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }}/${{ env.BINARY_NAME }}${{ matrix.platform_name == 'windows-amd64' && '.exe' || '' }} path: ${{ github.workspace }}/*zst
asset_name: ${{ env.BINARY_NAME }}_${{ matrix.platform_name }}${{ matrix.platform_name == 'windows-amd64' && '.exe' || '' }}
asset_content_type: application/octet-stream
release:
name: Making New Release ^_^
needs:
- build
- build_arch
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Get version
run: echo "VERSION=$(grep -P '^version = \"\d+\.\d+\.\d+\"' Cargo.toml | awk -F '\"' '{print $2}')" >> $GITHUB_ENV
- uses: actions/download-artifact@master
name: Download binary
id: download_binary
with:
name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
path: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}
- uses: actions/download-artifact@master
id: download_pkg
name: Download ZST package
with:
name: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}.zst
path: ${{ env.BINARY_NAME }}_${{ env.VERSION }}_${{ env.BUILD_TARGET }}.zst
- uses: ncipollo/release-action@v1
name: Update release page
with:
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

View File

@ -6,14 +6,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.0] - 2023-09-13
### Improved
- Logging. Fix bugs
## [1.0.7] - 2023-08-31 ## [1.0.7] - 2023-08-31
### Changed ### Changed

50
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 3
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
@ -244,31 +244,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.6" version = "0.1.6"
@ -1054,26 +1029,6 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.16" version = "0.2.16"
@ -1111,7 +1066,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "rexec" name = "rexec"
version = "1.1.0" version = "1.0.9"
dependencies = [ dependencies = [
"brace-expand", "brace-expand",
"clap 4.3.4", "clap 4.3.4",
@ -1124,7 +1079,6 @@ dependencies = [
"massh", "massh",
"openssl", "openssl",
"question", "question",
"rayon",
"regex", "regex",
"whoami", "whoami",
] ]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rexec" name = "rexec"
version = "1.2.0" version = "1.0.9"
readme = "https://github.com/house-of-vanity/rexec#readme" readme = "https://github.com/house-of-vanity/rexec#readme"
edition = "2021" edition = "2021"
description = "Parallel SSH executor" description = "Parallel SSH executor"
@ -14,7 +14,6 @@ authors = ["AB <gh@hexor.ru>"]
[dependencies] [dependencies]
dns-lookup = "2.0.2" dns-lookup = "2.0.2"
rayon = "1.10"
log = "0.4.0" log = "0.4.0"
env_logger = "0.10.0" env_logger = "0.10.0"
massh = "0.6.3" massh = "0.6.3"
@ -23,6 +22,7 @@ lazy-st = "0.2.2"
regex = "1" regex = "1"
clap = { version = "4.3.4", features = ["derive"] } clap = { version = "4.3.4", features = ["derive"] }
colored = "2.0.0" colored = "2.0.0"
#dialoguer = "0.10.4"
itertools = "0.10.5" itertools = "0.10.5"
brace-expand = "0.1.0" brace-expand = "0.1.0"
question = "0.2.2" question = "0.2.2"

View File

@ -32,31 +32,63 @@ Options:
``` ```
--- ---
![image](https://github.com/house-of-vanity/rexec/assets/4666566/4c52915d-2bc1-46b9-9833-b0d7c0527f2d)
## Examples ## Examples
```shell ```shell
$ rexec -f \ [ab@test]$ rexec -e 'cassandra-gce-sc-[1:3].bbs-prod.*' -u ab -c 'df -h /srv/cassandra'
-e 'cassandra-gce-or-[1:2]' \
-u ab \
-c 'uname -r; date'
[INFO ] Using string expansion to build server list. [INFO ] Using string expansion to build server list.
[INFO ] Matched hosts: [INFO ] Matched hosts:
[INFO ] cassandra-gce-or-1.prod.example.com [2.22.123.79] [INFO ] cassandra-gce-sc-1.bbs-prod.* [35.221.18.35]
[INFO ] cassandra-gce-or-2.prod.example.com [2.22.123.158] [INFO ] cassandra-gce-sc-2.bbs-prod.* [35.212.13.174]
Continue on following 2 servers? y [INFO ] cassandra-gce-sc-3.bbs-prod.* [35.211.213.123]
[INFO ] Run command on 2 servers. Continue on following 3 servers? y
[INFO ]
cassandra-gce-or-1.prod.example.com [INFO ] Run command on 3 servers.
Exit code [0] / stdout 45 bytes / stderr 0 bytes [INFO ]
STDOUT
║ 5.15.0-1040-gcp
║ Thu Sep 7 13:44:40 UTC 2023
cassandra-gce-or-2.prod.example.com [INFO ] cassandra-gce-sc-2.bbs-prod.*
Exit code [0] / stdout 45 bytes / stderr 0 bytes Code 0
STDOUT STDOUT:
║ 5.15.0-1040-gcp Filesystem Size Used Avail Use% Mounted on
║ Thu Sep 7 13:44:40 UTC 2023 /dev/mapper/storage-cassandra 1.0T 613G 411G 60% /srv/cassandra
[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
[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
``` ```

View File

@ -6,7 +6,6 @@ use std::fs::read_to_string;
use std::hash::Hash; use std::hash::Hash;
use std::net::IpAddr; use std::net::IpAddr;
use std::process; use std::process;
use std::sync::{Arc, Mutex};
use clap::Parser; use clap::Parser;
use colored::*; use colored::*;
@ -16,7 +15,6 @@ use itertools::Itertools;
use log::{error, info}; use log::{error, info};
use massh::{MasshClient, MasshConfig, MasshHostConfig, SshAuth}; use massh::{MasshClient, MasshConfig, MasshHostConfig, SshAuth};
use question::{Answer, Question}; use question::{Answer, Question};
use rayon::prelude::*;
use regex::Regex; use regex::Regex;
// Define args // Define args
@ -189,6 +187,8 @@ fn main() {
let matched_hosts: Vec<_> = hosts.into_iter().unique().collect(); let matched_hosts: Vec<_> = hosts.into_iter().unique().collect();
// Build MasshHostConfig hostnames list // Build MasshHostConfig hostnames list
let mut massh_hosts: Vec<MasshHostConfig> = vec![];
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
if args.parallel != 100 { if args.parallel != 100 {
warn!("Parallelism: {} thread{}", &args.parallel, { warn!("Parallelism: {} thread{}", &args.parallel, {
if args.parallel != 1 { if args.parallel != 1 {
@ -200,42 +200,23 @@ fn main() {
} }
info!("Matched hosts:"); info!("Matched hosts:");
let resolved_ips = Arc::new(Mutex::new(Vec::<(String, IpAddr)>::new())); for host in matched_hosts.iter() {
let ip = match lookup_host(&host.name) {
matched_hosts Ok(ip) => ip[0],
.par_iter()
.for_each(|host| match lookup_host(&host.name) {
Ok(ips) if !ips.is_empty() => {
let ip = ips[0];
info!("{} [{}]", &host.name, ip);
let mut results = resolved_ips.lock().unwrap();
results.push((host.name.clone(), ip));
}
Ok(_) => {
error!("DNS resolved, but IP not found: {}", &host.name.red());
}
Err(_) => { Err(_) => {
error!("DNS resolve failed: {}", &host.name.red()); error!("{} couldn't be resolved.", &host.name.red());
continue;
} }
}); };
info!("{} [{}]", &host.name, ip);
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new(); hosts_and_ips.insert(ip, host.name.clone());
let mut massh_hosts: Vec<MasshHostConfig> = Vec::new();
if let Ok(results) = resolved_ips.lock() {
for (hostname, ip) in results.iter() {
hosts_and_ips.insert(*ip, hostname.clone());
massh_hosts.push(MasshHostConfig { massh_hosts.push(MasshHostConfig {
addr: *ip, addr: ip,
auth: None, auth: None,
port: None, port: None,
user: None, user: None,
}); })
} }
}
// Build MasshConfig using massh_hosts vector // Build MasshConfig using massh_hosts vector
let config = MasshConfig { let config = MasshConfig {
default_auth: SshAuth::Agent, default_auth: SshAuth::Agent,
@ -312,9 +293,9 @@ fn main() {
"" => {} "" => {}
_ => { _ => {
let prefix = if output.exit_status != 0 { let prefix = if output.exit_status != 0 {
format!("{}", "".cyan()) format!("{}", "".cyan())
} else { } else {
format!("{}", "".green()) format!("{}", "".green())
}; };
for line in stdout.lines() { for line in stdout.lines() {
println!("{} {}", prefix, line); println!("{} {}", prefix, line);