Skip to content

Commit

Permalink
feat(get-ctr::cli): +compatibility_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
2moe committed Apr 2, 2024
1 parent 19aa2ec commit 518050e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/get-ctr.rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
PKG: get-ctr
steps:
- name: install zsh
if: (matrix.machine != 'armbian')
shell: sh -e {0}
run: ${{ vars.INSTALL_ZSH }}

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/get-ctr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "get-ctr"
version = "0.0.0-alpha.11"
version = "0.0.0-alpha.12"
edition = "2021"

[dependencies]
Expand Down
13 changes: 12 additions & 1 deletion crates/get-ctr/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ pub(crate) struct Cli {
#[arg(long, num_args = 0..=1, default_missing_value = " ")]
tag: Option<String>,

/// e.g., For noble, auto add: noble-updates,noble-backports,noble-security
/// e.g., for noble, auto add: noble-updates,noble-backports,noble-security
#[arg(long)]
auto_add_extra_suites: bool,

/// It is recommended to use it only when the rootfs build fails.
#[arg(long)]
compatibility_mode: bool,

/// download or build rootfs
#[arg(long, help_heading = "Operation")]
obtain: bool,
Expand Down Expand Up @@ -308,6 +312,8 @@ impl Cli {
Self::static_auto_add_extra_suites(Some(
*self.get_auto_add_extra_suites(),
));
Self::static_compatibility_mode(Some(*self.get_compatibility_mode()));

build_rootfs::obtain(&repos)?;
}

Expand All @@ -320,6 +326,11 @@ impl Cli {
*B.get_or_init(|| init.unwrap_or(false))
}

pub(crate) fn static_compatibility_mode(init: Option<bool>) -> bool {
static B: OnceLock<bool> = OnceLock::new();
*B.get_or_init(|| init.unwrap_or(false))
}

fn cli_common(&self, repos: Vec<Repository>) -> Result<(), anyhow::Error> {
if *self.get_repack() {
old_old_debian::repack(&repos, self.get_zstd_level().as_ref())?;
Expand Down
43 changes: 42 additions & 1 deletion crates/get-ctr/src/task/build_rootfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,22 @@ pub(crate) fn obtain<'a, I: IntoIterator<Item = &'a Repository<'a>>>(
}
_ => {}
};
run_debootstrap(deb_src, repo, &rootfs_dir, &ex_pkgs)?;

let comp_mode = Cli::static_compatibility_mode(None);

if comp_mode {
get_rootfs_from_old_docker_image(
docker_dir,
repo.ghcr_repos()
.first()
.expect("Empty GHCR REPO"),
&rootfs_dir,
)?
}

if !comp_mode {
run_debootstrap(deb_src, repo, &rootfs_dir, &ex_pkgs)?
}
}
}
}
Expand All @@ -145,6 +160,32 @@ pub(crate) fn obtain<'a, I: IntoIterator<Item = &'a Repository<'a>>>(
Ok(())
}

fn get_rootfs_from_old_docker_image(
docker_dir: &Path,
repo: &str,
rootfs_dir: &Path,
) -> anyhow::Result<()> {
log::info!("Creating the container: {repo}");

let container = run_and_get_stdout("docker", &["create", repo])?;
let id = container.trim();

let tar = docker_dir.join("base.tar");
{
let osstr = OsStr::new;
let mut args = TinyVec::<[&OsStr; 4]>::new();
args.extend(["export", id, "-o"].map(osstr));
args.push(tar.as_ref());
log::info!("cmd: docker, args: {args:?}");
run("docker", &args, true);
}
run("docker", &["rm", id], true);

extract_tar_as_root(&tar, rootfs_dir)?;
force_remove_item_as_root(tar);
Ok(())
}

fn get_old_rootfs(
docker_dir: &Path,
rootfs_dir: &Path,
Expand Down

0 comments on commit 518050e

Please sign in to comment.