Skip to content

Commit

Permalink
Fix Ephemeral command edge case
Browse files Browse the repository at this point in the history
Extend args fix to other annotations
Mention Tini in README
  • Loading branch information
Colonial-Dev committed Jan 16, 2025
1 parent e973a55 commit b1ea339
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ USER $USER
WORKDIR /home/$USER
# A dummy 'infinite command' like this keeps the container alive so processes on the host
# can spawn 'exec' sessions inside.
#
# You could also use a minimal `init` implementation, such as `tini`,
# to ensure that zombie processes are reaped correctly.
CMD "sleep inf"

# Commit the image.
Expand Down
25 changes: 5 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,14 @@ fn main() -> Result<()> {

ctr.exec(&path, &args)?;
},
Ephemeral { name, path, args } => {
Ephemeral { name, path, mut args } => {
let image = Image::from_id(&name)?;

let args = match args.len() {
0 => format!("--entrypoint={path}"),
_ => format!("--entrypoint={path} {}", args.join(" "))
};
args.insert(0, path);

image.instantiate_ext(
false,
true,
&[args]
&args
)?;
},

Expand Down Expand Up @@ -485,29 +481,18 @@ fn evaluate_config(operation: String, args: Vec<String>) -> Result<()> {
"preset" => {
evaluate_preset(&ctr, args)?
},
"args" => {
o if ANNOTATIONS.contains(&o) => {
if args.is_empty() {
bail!("Configuration value not specified")
}

for a in args {
push_annotation(
&ctr,
"box.args",
&format!("box.{o}"),
a
)?;
}
}
o if ANNOTATIONS.contains(&o) => {
let Some(val) = args.first() else {
bail!("Configuration value not specified")
};

push_annotation(
&ctr,
&format!("box.{o}"),
val
)?;
},
o if CONFIG_FLAGS.contains(&o) => {
if args.is_empty() {
Expand Down
20 changes: 10 additions & 10 deletions src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ impl Image {
}

pub fn instantiate(&self, replace: bool) -> Result<()> {
self.instantiate_ext(replace, false, &[])
self.instantiate_ext(replace, &[])
}

pub fn instantiate_ext(&self, replace: bool, ephemeral: bool, addl_args: &[String]) -> Result<()> {
pub fn instantiate_ext(&self, replace: bool, ephemeral_args: &[String]) -> Result<()> {
let name = self.annotation("box.name")
.expect("Name annotation should be set");

Expand Down Expand Up @@ -358,9 +358,9 @@ impl Image {
)
}

let name_args = match ephemeral {
false => vec!["-d", "--name", name, "--hostname", name],
true => vec!["--rm", "-it", "--hostname", name]
let name_args = match ephemeral_args.is_empty() {
false => vec!["--rm", "-it", "--hostname", name],
true => vec!["-d", "--name", name, "--hostname", name]
};

let mut c = Command::new("podman");
Expand All @@ -369,7 +369,6 @@ impl Image {
.arg("run")
.args(name_args)
.args(args)
.args(addl_args)
.args([
"--annotation",
"manager=box"
Expand All @@ -378,11 +377,12 @@ impl Image {
.arg(format!("box.name={name}"))
.arg("--annotation")
.arg(format!("box.hash={hash}"))
.arg(name);
.arg(name)
.args(ephemeral_args);

match ephemeral {
false => c.output_ok().map(drop),
true => c.spawn_ok()
match ephemeral_args.is_empty() {
false => c.spawn_ok(),
true => c.output_ok().map(drop)
}.context("Fault when instantiating image")?;

Ok(())
Expand Down

0 comments on commit b1ea339

Please sign in to comment.