Skip to content

Commit 2f0f5b2

Browse files
committed
feat: add support to Podman as container engine
1 parent 1824e90 commit 2f0f5b2

File tree

5 files changed

+89
-56
lines changed

5 files changed

+89
-56
lines changed

README.md

+58-53
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ hbox offers the following features:
1717
- **Support for Pipes**: Supports the use of pipes in `hbox run`, enabling efficient command chaining.
1818
- **Convenient Shims**: 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**: Provides direct access to internal binaries within images. Users can override the default entrypoint to access essential tools and utilities within containers directly.
20-
- **Customizable Environment Variables**: Allows setting environment variables for each package, enabling finer control over runtime configurations.
20+
- **Customizable Environment Variables**: Allows setting environment variables for each package, enabling finer control over runtime configurations.]()
21+
- **Support for Docker and Podman**: Provides seamless support for both Docker and Podman container engines, offering flexibility in container runtime choices.
2122

2223
## Installation
2324

@@ -139,9 +140,64 @@ These examples should provide a quick start guide for you to understand the basi
139140

140141
## Configuration
141142

143+
### Configuration via config.json
144+
145+
The general configuration of hbox is managed by the `$HBOX_DIR/config.json` file. Currently, you can control the container engine, how logs are used and enable some experimental features:
146+
147+
```json
148+
{
149+
"engine": "docker",
150+
"logs": {
151+
"enabled": true,
152+
"level": "debug",
153+
"strategy": "truncate"
154+
},
155+
"experimental": {
156+
"capture_stdout": false,
157+
"capture_stderr": false
158+
}
159+
}
160+
```
161+
162+
#### Properties
163+
164+
The `config.json` file is used to control how hbox should behave. Below are the details of each property available in this configuration file.
165+
166+
| Property | Type | Description |
167+
|-------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
168+
| `engine` | `string` | Indicates what container engine to use. Possible values: `docker`, `podman`. Example: `docker` |
169+
| `logs` | `object` | Configuration for logging behavior. |
170+
| `logs.enabled` | `boolean` | Indicates if logging is enabled. Example: `true` |
171+
| `logs.level` | `string` | Specifies the logging level. Possible values: `debug`, `info`, `warn`, `error`. Example: `debug` |
172+
| `logs.strategy` | `string` | Strategy for handling log files. Possible values: `append`, `truncate`. Example: `truncate` |
173+
| `experimental` | `object` | Configuration for experimental features. |
174+
| `experimental.capture_stdout` | `boolean` | Indicates if standard output should be captured and sent to logs. Regardless of this option, stdout will always be printed normally. Example: `false` |
175+
| `experimental.capture_stderr` | `boolean` | Indicates if standard error should be captured and sent to logs. Regardless of this option, stderr will always be printed normally. Example: `false` |
176+
177+
#### Property Details
178+
179+
- **engine**: Specifies whether to use `docker` or `podman` as a container engine. `docker` is the default.
180+
181+
- **logs**: This object configures logging behavior for hbox.
182+
- `enabled`: A boolean indicating if logging is enabled. If set to `true`, logging is active.
183+
- `level`: Specifies the verbosity of the logs. Options include:
184+
- `debug`: Detailed information typically useful for developers.
185+
- `info`: General information about the application's operation.
186+
- `warn`: Warnings about potentially problematic situations.
187+
- `error`: Error messages indicating serious issues.
188+
- `strategy`: Determines how log files are managed. Options include:
189+
- `append`: Adds new log entries to the end of existing log files.
190+
- `truncate`: Overwrites existing log files with new entries.
191+
192+
- **experimental**: This object contains settings for experimental features that are not yet fully supported.
193+
- `capture_stdout`: A boolean indicating if the standard output of commands should be captured and sent to logs. Regardless of this option, stdout will always be printed normally.
194+
- `capture_stderr`: A boolean indicating if the standard error of commands should be captured and sent to logs. Regardless of this option, stderr will always be printed normally.
195+
196+
These properties allow you to customize the behavior of hbox, particularly how it handles logging and experimental features, providing better control over the application's operation.
197+
142198
### Shims
143199

144-
hbox utilizes shims and a configuration file to effectively manage your installed packages. There are two types of shims: _package shims_ and _binary shims_.
200+
hbox utilizes shims to effectively manage your installed packages. There are two types of shims: _package shims_ and _binary shims_.
145201

146202
#### Package Shims
147203

@@ -307,57 +363,6 @@ We also set `-c` as the default command and specified that all arguments should
307363
docker run -it --rm --name hbox-busybox-latest-qNDyEVzrUb -v .:/app -w /app -e HTTP_PROXY=$HTTP_PROXY -e HTTPS_PROXY=$HTTPS_PROXY -e NO_PROXY=$NO_PROXY --entrypoint /bin/sh docker.io/busybox:latest -c "ls -alh"
308364
```
309365

310-
### Configuration via config.json
311-
312-
The general configuration of hbox is managed by the `$HBOX_DIR/config.json` file. Currently, you can control how logs are used and enable some experimental features:
313-
314-
```json
315-
{
316-
"logs": {
317-
"enabled": true,
318-
"level": "debug",
319-
"strategy": "truncate"
320-
},
321-
"experimental": {
322-
"capture_stdout": false,
323-
"capture_stderr": false
324-
}
325-
}
326-
```
327-
328-
#### Properties
329-
330-
The `config.json` file is used to control how hbox should behave. Below are the details of each property available in this configuration file.
331-
332-
| Property | Type | Description |
333-
|-------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
334-
| `logs` | `object` | Configuration for logging behavior. |
335-
| `logs.enabled` | `boolean` | Indicates if logging is enabled. Example: `true` |
336-
| `logs.level` | `string` | Specifies the logging level. Possible values: `debug`, `info`, `warn`, `error`. Example: `debug` |
337-
| `logs.strategy` | `string` | Strategy for handling log files. Possible values: `append`, `truncate`. Example: `truncate` |
338-
| `experimental` | `object` | Configuration for experimental features. |
339-
| `experimental.capture_stdout` | `boolean` | Indicates if standard output should be captured and sent to logs. Regardless of this option, stdout will always be printed normally. Example: `false` |
340-
| `experimental.capture_stderr` | `boolean` | Indicates if standard error should be captured and sent to logs. Regardless of this option, stderr will always be printed normally. Example: `false` |
341-
342-
#### Property Details
343-
344-
- **logs**: This object configures logging behavior for hbox.
345-
- `enabled`: A boolean indicating if logging is enabled. If set to `true`, logging is active.
346-
- `level`: Specifies the verbosity of the logs. Options include:
347-
- `debug`: Detailed information typically useful for developers.
348-
- `info`: General information about the application's operation.
349-
- `warn`: Warnings about potentially problematic situations.
350-
- `error`: Error messages indicating serious issues.
351-
- `strategy`: Determines how log files are managed. Options include:
352-
- `append`: Adds new log entries to the end of existing log files.
353-
- `truncate`: Overwrites existing log files with new entries.
354-
355-
- **experimental**: This object contains settings for experimental features that are not yet fully supported.
356-
- `capture_stdout`: A boolean indicating if the standard output of commands should be captured and sent to logs. Regardless of this option, stdout will always be printed normally.
357-
- `capture_stderr`: A boolean indicating if the standard error of commands should be captured and sent to logs. Regardless of this option, stderr will always be printed normally.
358-
359-
These properties allow you to customize the behavior of hbox, particularly how it handles logging and experimental features, providing better control over the application's operation.
360-
361366
### Package Version Management
362367

363368
hbox maintains a directory `$HBOX_DIR/versions` that tracks the current version of each package. Each package has a file in this directory, managed by hbox, and should not be manually edited.

ROADMAP.md

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
List of ideas I want to implement in the future.
44

55
- Miscellaneous:
6-
- Support `podman`
76
- Support private registries and mirrors
87
- maybe via registry mapping in `config.json`?
98
- Add a .gif showcasing hbox

src/commands.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use crate::shims::{add_shim, remove_shim};
66
use log::info;
77
use std::env;
88
use std::error::Error;
9+
use crate::configs::user::UserConfig;
910

1011
pub fn show_info() -> Result<(), Box<dyn Error>> {
1112
let config = AppConfig::load();
13+
let user_config = UserConfig::load().unwrap_or_default();
1214
info!("");
1315
info!("[System Information]");
1416
info!("OS Details:");
@@ -18,6 +20,7 @@ pub fn show_info() -> Result<(), Box<dyn Error>> {
1820
info!("");
1921
info!("[Application Configuration]");
2022
info!("Version : {}", env!("CARGO_PKG_VERSION"));
23+
info!("Engine : {}", user_config.engine.as_str());
2124
info!("Directories and Files:");
2225
info!(
2326
" base dir : {}",

src/configs/user.rs

+23
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,33 @@ impl UserConfig {
2323

2424
#[derive(Serialize, Deserialize, Debug, Default)]
2525
pub struct Root {
26+
pub engine: Engine,
2627
pub logs: Logs,
2728
pub experimental: Experimental,
2829
}
2930

31+
#[derive(Serialize, Deserialize, Debug)]
32+
#[serde(rename_all = "lowercase")]
33+
pub enum Engine {
34+
Docker,
35+
Podman
36+
}
37+
38+
impl Default for Engine {
39+
fn default() -> Self {
40+
Self::Docker
41+
}
42+
}
43+
44+
impl Engine {
45+
pub fn as_str(&self) -> &'static str {
46+
match self {
47+
Self::Docker => "docker",
48+
Self::Podman => "podman",
49+
}
50+
}
51+
}
52+
3053
#[derive(Serialize, Deserialize, Debug)]
3154
pub struct Logs {
3255
#[serde(default)]

src/runner.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ use std::process::{Command, Stdio};
99
use std::thread;
1010

1111
pub fn pull(package: &Package) -> bool {
12+
let config = UserConfig::load().unwrap_or_default();
1213
let image = format!("{}:{}", package.index.image, package.versions.current);
13-
run_command_with_args("docker", &["pull".to_string(), image], None)
14+
run_command_with_args(config.engine.as_str(), &["pull".to_string(), image], None)
1415
}
1516

1617
pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> bool {
18+
let config = UserConfig::load().unwrap_or_default();
19+
1720
let interactive = !stdin().is_terminal();
1821
let mut buffer = Vec::new();
1922
if interactive {
@@ -51,7 +54,7 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
5154
args.extend(params.iter().cloned());
5255
}
5356

54-
run_command_with_args("docker", &args, Some(buffer))
57+
run_command_with_args(config.engine.as_str(), &args, Some(buffer))
5558
}
5659

5760
fn should_wrap_args(binary: Option<&Binary>) -> bool {

0 commit comments

Comments
 (0)