Skip to content

Commit 86bf605

Browse files
committed
feat: add environment variables support
1 parent cc330a0 commit 86bf605

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ hbox offers the following features:
1717
- **Support for Pipes**: hbox supports the use of pipes in `hbox run`, which allows you to chain commands efficiently.
1818
- **Convenient Shims**: hbox creates `shims` (alias shortcuts) for all installed packages, simplifying command entry from `hbox run <package alias> <commands>` to `<package alias> <commands>`.
1919
- **Accessible Internal Binaries**: hbox has the ability to provide direct access to internal binaries within images. Users can override the default entrypoint, meaning essential tools and utilities within containers can be accessed directly. This feature further expands the capabilities of hbox `shims`, making it even more convenient to launch and utilize container tools.
20+
- **Customizable Environment Variables**: hbox supports setting environment variables for each package, enabling finer control over runtime configurations.
2021

2122
## Commands
2223

@@ -84,7 +85,25 @@ In the future this will be centralized in on its own repo/server, so you can fet
8485
"path": "/bin/tree"
8586
}
8687
],
87-
"only_shim_binaries": true
88+
"only_shim_binaries": true,
89+
"environment_variables": [
90+
{
91+
"name": "FOO",
92+
"value": "abc123"
93+
},
94+
{
95+
"name": "HTTP_PROXY",
96+
"value": "$HTTP_PROXY"
97+
},
98+
{
99+
"name": "HTTPS_PROXY",
100+
"value": "$HTTPS_PROXY"
101+
},
102+
{
103+
"name": "NO_PROXY",
104+
"value": "$NO_PROXY"
105+
}
106+
]
88107
},
89108
"golang": {
90109
"image": "docker.io/golang",

src/files/index.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Package {
1414
pub image: String,
1515
pub volumes: Option<Vec<Volume>>,
1616
pub current_directory: Option<String>,
17+
pub environment_variables: Option<Vec<EnvironmentVariable>>,
1718
pub binaries: Option<Vec<Binary>>,
1819
#[serde(default)]
1920
pub only_shim_binaries: bool,
@@ -25,6 +26,7 @@ impl Package {
2526
image: format!("docker.io/{}", name),
2627
volumes: None,
2728
current_directory: None,
29+
environment_variables: None,
2830
binaries: None,
2931
only_shim_binaries: false
3032
}
@@ -43,6 +45,12 @@ pub struct Binary {
4345
pub path: String,
4446
}
4547

48+
#[derive(Serialize, Deserialize, Debug, Clone)]
49+
pub struct EnvironmentVariable {
50+
pub name: String,
51+
pub value: String,
52+
}
53+
4654
pub fn parse() -> Result<Root, Box<dyn Error>> {
4755
let config = AppConfig::new();
4856
parse_json(&config.index_path())

src/packages.rs

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl Package {
5858
println!(" - {}:{}", volume.source, volume.target);
5959
}
6060
}
61+
if let Some(environment_variables) = &self.index.environment_variables {
62+
println!(" - environment variables:");
63+
for env_var in environment_variables {
64+
println!(" - {}={}", env_var.name, env_var.value);
65+
}
66+
}
6167
if let Some(binaries) = &self.index.binaries {
6268
println!(" - binaries:");
6369
for binary in binaries {

src/runner.rs

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
6969
args.push(current_directory.clone());
7070
}
7171

72+
if let Some(environment_variables) = &package.index.environment_variables {
73+
for env_var in environment_variables {
74+
args.push("-e".to_string());
75+
args.push(format!("{}={}", env_var.name, env_var.value));
76+
}
77+
}
78+
7279
if let Some(b) = binary {
7380
if let Some(binaries) = &package.index.binaries {
7481
for binary in binaries {

0 commit comments

Comments
 (0)