Skip to content

Commit

Permalink
Handle incomplete container path
Browse files Browse the repository at this point in the history
If the given oci path does not match a file, the value is treated
as a glob pattern. From the possible match of the pattern the
last match will be used as the file to load. This Fixes #51
  • Loading branch information
rjschwei authored Nov 26, 2024
1 parent dce435a commit d89451c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion doc/flake-ctl-podman-load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ SYNOPSIS
DESCRIPTION
-----------

Load the given OCI image into the local registry.
Load the given OCI image into the local registry. If the provided
file path cannot be found and attempt is made to match the image using
the provided path as the base for a glob. If multiple images match the
glob the highest image in alpha numerical order will be loaded.
The command is based on **podman load**. After completion
the container can be listed via:

Expand Down
3 changes: 3 additions & 0 deletions flake-ctl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ pub enum Podman {
/// Load container
Load {
/// OCI image to load into local podman registry
/// used as the base of a glob if the given image path
/// is not found. Load the highest, in alpha numerical order
/// image if there is a match
#[clap(long)]
oci: String,
},
Expand Down
17 changes: 14 additions & 3 deletions flake-ctl/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::fs;
use std::env;
use std::path::Path;
use std::process::Command;
use glob::glob;
use crate::defaults;
use crate::{app, app_config};
use flakes::container::Container;
Expand Down Expand Up @@ -74,13 +75,23 @@ pub fn load(oci: &String) -> i32 {
/*!
Call podman load with the provided oci tar file
!*/
let mut container_archive: String = oci.to_string();

info!("Loading OCI image...");
info!("podman load -i {}", oci);

if !Path::new(oci).exists() {
let container_archives = oci.to_owned() + "*";
// glob puts things in alpha sorted order which is expected to give
// us the highest version of the archive
for entry in glob(&container_archives)
.expect("Failed to read glob pattern").flatten() {
container_archive = entry.display().to_string()
}
}
info!("podman load -i {}", container_archive);
let mut call = setup_podman_call("any");
call.arg("load")
.arg("-i")
.arg(oci);
.arg(container_archive);
let status = match call.status() {
Ok(status) => {
if status.success() {
Expand Down

0 comments on commit d89451c

Please sign in to comment.