Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support convert Nydus image layers to tar files #538

Merged
merged 7 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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