Skip to content

Commit

Permalink
Bugfix for args
Browse files Browse the repository at this point in the history
Add some logging and messaging
  • Loading branch information
Colonial-Dev committed Jan 16, 2025
1 parent b035e64 commit 6667028
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "box"
authors = ["Colonial"]
version = "1.0.0"
version = "0.5.0"
edition = "2021"
description = "A simple container manager for your shell."
repository = "https://github.com/Colonial-Dev/box"
Expand Down
10 changes: 5 additions & 5 deletions DEFINITIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Currently, only two keys are recognized:

These are the recommended way to write definitions for Box.

## DSL Commands
## Commands

Box provides (approximate) implementations of all OCI Containerfile operations as shell functions, as well as several additional tools.

Expand Down Expand Up @@ -136,9 +136,9 @@ PRESET <NAME> [ARGS...]
| Name | Function | Arguments |
| ---- | -------- | --------- |
| `cp-user` | Copies a user from the host into the container. | Optionally takes the name of the user to copy. If one is not provided, it defaults to the user executing the program (i.e. the result of `whoami`.) |
| `bind-fix` | Fixes permission issues encountered with rootless bind mounts on SELinux systems. | None. |
| `ssh-agent` | Mounts and exports `SSH_AUTH_SOCK` into the container. Implies `bind-fix`. | None. |
| `devices` | Mounts `/dev` into the container. Implies `bind-fix` and `--privileged`. | None. |
| `bind-fix` | Fixes permission issues encountered with rootless bind mounts on SELinux systems. Disables SELinux label separation and maps the host user to the same UID inside the container. | None. |
| `ssh-agent` | Mounts and exports `SSH_AUTH_SOCK` into the container. | None. |
| `devices` | Mounts `/dev` into the container. Implies `--privileged`! | None. |

### `COMMIT`
> *Corresponding manual page: `buildah commit`*
Expand Down Expand Up @@ -177,4 +177,4 @@ trap cp

This is not included in the POSIX harness, which automatically applies `set -eu` to abort on non-zero exit codes or uses of unset variables.

[^1]: If you're wondering "how the hell does it do that" - it saves them as OCI annotations that are read back at creation time. [Did you know you can just use the ASCII separator characters to separate things?](https://github.com/Colonial-Dev/box/blob/0c45cfe2c51a4ff1c3f62b3f753bcfeab882a56b/src/podman.rs#L341-L352) They're right there. Nobody can stop you.
[^1]: If you're wondering "how the hell does it do that" - it saves them as OCI annotations that are read back at creation time. <br> [Did you know you can just use the ASCII separator characters to separate things?](https://github.com/Colonial-Dev/box/blob/0c45cfe2c51a4ff1c3f62b3f753bcfeab882a56b/src/podman.rs#L341-L352) They're right there. Nobody can stop you.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,8 @@ So:
### "Why not just use Kubernetes YAML or `compose`?"
A few reasons:

1. For Box's target use case of "bespoke interactive containers," separating the information on how to *build* the image from information on how to *run* it is [lame](https://htmx.org/essays/locality-of-behaviour/).
1. For Box's target use case of "bespoke interactive containers," separating the information on how to *build* the image from information on how to *run* it is [suboptimal](https://htmx.org/essays/locality-of-behaviour/).
2. Kubernetes YAML is massively overcomplicated for what I wanted to do, and the `podman` version of `compose` was somewhat buggy when I tried it.
3. YAML is... [yeah](https://github.com/Colonial-Dev/satpaper/blob/b2016c63ffeafc70538fd2b02fa60d1c077fd694/.github/workflows/release.yml#L1-L3).

### "Creating containers (`up`) is extremely slow."

This seems to be a `podman` issue with the default `overlay` storage driver on BTRFS (and possibly ZFS) systems that causes expensive copies during container creation.
I followed [this](https://www.jwillikers.com/podman-with-btrfs-and-zfs) guide to switch my storage driver to use BTRFS subvolumes and experienced massive speedups.

[^1]: Single Rust binary compiled from ~2000 lines of boring plumbing code. Red Hat and the OCI have already done all the heavy lifting here!
21 changes: 21 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ impl Definition {
use std::fs;

let path = p.as_ref().to_owned();

debug!("Attempting to fetch definition from path {path:?}");

let data = fs::read_to_string(&path)
.context("Failed to read in definition data")
Expand Down Expand Up @@ -161,6 +163,8 @@ impl Definition {

let tree = hash;

debug!("Fetched definition from path {path:?}");

Ok(Self { path, bang, hash, tree, meta })
}

Expand Down Expand Up @@ -516,6 +520,8 @@ pub fn definition_directory() -> Result<PathBuf> {
}

pub fn build_set(defs: &[String], all: bool, force: bool) -> Result<()> {
use colored::Colorize;

use petgraph::Graph;
use petgraph::algo::toposort;
use petgraph::visit::Dfs;
Expand Down Expand Up @@ -591,6 +597,13 @@ pub fn build_set(defs: &[String], all: bool, force: bool) -> Result<()> {
names.insert(name);
}

eprintln!(
"Building {} definitions ({} requested, {} transitive)",
(set.len() + deps.len()).to_string().green().bold(),
set.len().to_string().green().bold(),
deps.len().to_string().yellow().bold(),
);

set.extend(deps);

debug!(
Expand Down Expand Up @@ -706,7 +719,15 @@ pub fn build_set(defs: &[String], all: bool, force: bool) -> Result<()> {

if *own != def.hash || *tree != def.tree {
def.build()?;
continue
}

// If we got here, the build was skipped.
eprintln!(
"{} {} (unchanged)",
"Skipped definition".bright_white().bold(),
def.name().yellow().bold(),
)
}

Ok(())
Expand Down
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,19 @@ fn evaluate_config(operation: String, args: Vec<String>) -> Result<()> {
"preset" => {
evaluate_preset(&ctr, args)?
},
"args" => {
if args.is_empty() {
bail!("Configuration value not specified")
}

for a in args {
push_annotation(
&ctr,
"box.args",
a
)?;
}
}
o if ANNOTATIONS.contains(&o) => {
let Some(val) = args.first() else {
bail!("Configuration value not specified")
Expand Down Expand Up @@ -542,11 +555,6 @@ fn evaluate_preset(ctr: &str, args: &[String]) -> Result<()> {
return Err(err)
};

if matches!(name.as_str(), "bind-fix" | "ssh-agent" | "devices") {
push_annotation("box.security-opt", "label=disable")?;
push_annotation("box.userns", "keep-id")?;
}

match name.as_str() {
"cp-user" => {
use uzers::os::unix::UserExt;
Expand Down Expand Up @@ -607,7 +615,8 @@ fn evaluate_preset(ctr: &str, args: &[String]) -> Result<()> {
push_annotation("box.mount", "type=bind,src=/dev,dst=/dev,rslave=true")?;
},
"bind-fix" => {
// No-op. Covered in the blanket case above.
push_annotation("box.security-opt", "label=disable")?;
push_annotation("box.userns", "keep-id")?;
}
_ => {
let err = eyre!("Unrecognized preset {name}")
Expand Down

0 comments on commit 6667028

Please sign in to comment.