Skip to content

Commit 264ff83

Browse files
committed
feat: generate container name with info to better track execution
1 parent 1001719 commit 264ff83

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Cargo.lock

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ env_logger = "0.11.3"
1414
log = "0.4.21"
1515
serde = { version = "1.0.201", features = ["derive"] }
1616
serde_json = "1.0.117"
17-
shellexpand = "3.1.0"
17+
shellexpand = "3.1.0"
18+
rand = "0.8.5"

src/runner.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::io::{stdin, BufRead, BufReader, IsTerminal, Read, Write};
55
use std::path::Path;
66
use std::process::{Command, Stdio};
77
use std::thread;
8+
use rand::{thread_rng, Rng};
9+
use rand::distributions::Alphanumeric;
810

911
pub fn pull(package: &Package) -> bool {
1012
let image = format!("{}:{}", package.index.image, package.versions.current);
@@ -21,7 +23,7 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
2123
.expect("Failed to read stdin");
2224
}
2325

24-
let mut args = vec!["run".to_string(), "--rm".to_string()];
26+
let mut args = vec!["run".to_string(), "--rm".to_string(), "--name".to_string(), generate_random_name(&package)];
2527
if interactive {
2628
args.push("-i".to_string());
2729
} else {
@@ -43,6 +45,11 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
4345
run_command_with_args("docker", &args, Some(buffer))
4446
}
4547

48+
fn generate_random_name(package: &Package) -> String {
49+
let id: String = thread_rng().sample_iter(&Alphanumeric).take(10).map(char::from).collect();
50+
format!("hbox-{}-{}-{}", package.name, package.versions.current, id)
51+
}
52+
4653
fn add_volumes(package: &Package, args: &mut Vec<String>) {
4754
if let Some(volumes) = &package.index.volumes {
4855
for volume in volumes {

0 commit comments

Comments
 (0)