Skip to content

Commit

Permalink
Merge pull request dragonflyoss#538 from ccx1024cc/morgan/nydus-tar-t…
Browse files Browse the repository at this point in the history
…o-tar

feat: support convert Nydus image layers to tar files
  • Loading branch information
imeoer authored Jun 29, 2022
2 parents 58c05b4 + e246ee1 commit 46d4b6b
Show file tree
Hide file tree
Showing 7 changed files with 1,601 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::core::prefetch::Prefetch;
use crate::core::tree;
use crate::merge::Merger;
use crate::trace::{EventTracerClass, TimingTracerClass, TraceClass};
use crate::unpack::{OCIUnpacker, Unpacker};
use crate::validator::Validator;

#[macro_use]
Expand All @@ -53,6 +54,7 @@ mod core;
mod inspect;
mod merge;
mod stat;
mod unpack;
mod validator;

const BLOB_ID_MAXIMUM_LENGTH: usize = 255;
Expand Down Expand Up @@ -509,6 +511,33 @@ fn prepare_cmd_args(bti_string: String) -> ArgMatches<'static> {
.help("path to JSON output file")
.takes_value(true))
)
.subcommand(
SubCommand::with_name("unpack")
.about("Unpack nydus image layer to a tar file")
.arg(
Arg::with_name("bootstrap")
.long("bootstrap")
.short("B")
.help("path to bootstrap file")
.required(true)
.takes_value(true))
.arg(
Arg::with_name("blob")
.long("blob")
.short("b")
.help("path to blob file")
.required(false)
.takes_value(true)
)
.arg(
Arg::with_name("output")
.long("output")
.short("o")
.help("path to output tar file")
.required(true)
.takes_value(true)
)
)
.arg(
Arg::with_name("log-file")
.long("log-file")
Expand Down Expand Up @@ -567,6 +596,8 @@ fn main() -> Result<()> {
Command::stat(matches)
} else if let Some(matches) = cmd.subcommand_matches("compact") {
Command::compact(matches, &build_info)
} else if let Some(matches) = cmd.subcommand_matches("unpack") {
Command::unpack(matches)
} else {
println!("{}", cmd.usage());
Ok(())
Expand Down Expand Up @@ -765,6 +796,17 @@ impl Command {
Ok(())
}

fn unpack(args: &clap::ArgMatches) -> Result<()> {
let bootstrap = args.value_of("bootstrap").expect("pass in bootstrap");
let blob = args.value_of("blob");
let output = args.value_of("output").expect("pass in output");

let unpacker =
OCIUnpacker::new(bootstrap, blob, output).with_context(|| "fail to create unpacker")?;

unpacker.unpack().with_context(|| "fail to unpack")
}

fn check(matches: &clap::ArgMatches, build_info: &BuildTimeInfo) -> Result<()> {
let bootstrap_path = Self::get_bootstrap(matches)?;
let verbose = matches.is_present("verbose");
Expand Down
Loading

0 comments on commit 46d4b6b

Please sign in to comment.