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 7f1083a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
8 changes: 4 additions & 4 deletions DEFINITIONS.md
Original file line number Diff line number Diff line change
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.
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 7f1083a

Please sign in to comment.