Skip to content

Commit

Permalink
keep installroot long enough to containeriz
Browse files Browse the repository at this point in the history
  • Loading branch information
tofay committed Jul 20, 2024
1 parent f8e056f commit 83cb414
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/lockfile/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,28 @@ impl Lockfile {
let oci = OciDir::ensure(&dir).context("Failed to setup OCI layout")?;

let creation_time = creation_time()?;
let installroot = if let Some(vendor_dir) = vendor_dir {
let installroot = TempDir::new()?; // This needs to outlive the layer builder below.
if let Some(vendor_dir) = vendor_dir {
// Use vendored RPMs rather than downloading
self.create_installroot(vendor_dir, false, cfg, &creation_time)
self.create_installroot(installroot.path(), vendor_dir, false, cfg, &creation_time)
} else {
// No vendoring - download RPMs
let tmp_rpm_dir = TempDir::new()?;
self.create_installroot(tmp_rpm_dir.path(), true, cfg, &creation_time)
self.create_installroot(
installroot.path(),
tmp_rpm_dir.path(),
true,
cfg,
&creation_time,
)
}
.context("Failed to create installroot")?;

// Create the root filesystem layer
write::ok("Creating", "root filesystem layer")?;
let mut builder = oci.create_layer(Compression::fast().into())?;
builder.follow_symlinks(false);
append_dir_all_with_xattrs(&mut builder, &installroot, creation_time.timestamp())
append_dir_all_with_xattrs(&mut builder, installroot.path(), creation_time.timestamp())
.context("failed to archive root filesystem")?;
let layer = builder.into_inner()?.complete()?;
let descriptor = layer
Expand Down Expand Up @@ -100,17 +107,16 @@ impl Lockfile {

fn create_installroot(
&self,
installroot: &Path,
rpm_dir: &Path,
download_rpms: bool,
cfg: &Config,
creation_time: &DateTime<chrono::Utc>,
) -> Result<PathBuf, anyhow::Error> {
) -> Result<(), anyhow::Error> {
if download_rpms {
self.download_rpms(cfg, rpm_dir)?;
}
self.check_gpg_keys(rpm_dir)?;
let tmp_dir = TempDir::new()?;
let installroot = PathBuf::from(tmp_dir.path());
let mut dnf_install = Command::new("dnf");
dnf_install
.env("SOURCE_DATE_EPOCH", creation_time.timestamp().to_string())
Expand Down Expand Up @@ -166,7 +172,7 @@ impl Lockfile {
disable_sqlite_journaling(&installroot.join("var/lib/rpm/rpmdb.sqlite"))
.context("Failed to disable sqlite journaling of RPM db")?;
}
Ok(installroot)
Ok(())
}
}

Expand Down

0 comments on commit 83cb414

Please sign in to comment.