Skip to content

Commit

Permalink
🔨 chore: Add a bunch of helpful logging
Browse files Browse the repository at this point in the history
  • Loading branch information
queer committed May 24, 2023
1 parent cdfb08c commit 7cf6f00
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/artifact/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use eyre::Result;
use regex::Regex;
use tokio::fs::File;
use tokio_stream::StreamExt;
use tracing::*;

use crate::fs::MemFS;
use crate::util::config::Injection;
Expand Down Expand Up @@ -191,6 +192,7 @@ impl ArtifactProducer for ArchProducer {
let size = get_artifact_size(previous).await?;
let builddate = util::get_current_time()?;

info!("generating .PKGINFO...");
let content = indoc::formatdoc! {r#"
# generated by peckish
pkgname = {name}
Expand All @@ -212,6 +214,7 @@ impl ArtifactProducer for ArchProducer {
arch = self.package_arch,
};

info!("creating package...");
let mut new_injections = self.injections.clone();
new_injections.push(Injection::Create {
path: PathBuf::from(".PKGINFO"),
Expand Down
9 changes: 8 additions & 1 deletion src/artifact/deb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl DebArtifact {
let mut archive = {
let path = self.path.clone();
tokio::task::spawn_blocking(move || {
debug!("decompressing deb into memory...");
let mut decompressed = vec![];
// Decompress deb into memory
let mut file = std::fs::File::open(path).unwrap();
Expand All @@ -90,6 +91,7 @@ impl DebArtifact {
let mut ar_entry = entry?;
let path = String::from_utf8_lossy(ar_entry.header().identifier()).to_string();
if path.starts_with("data.tar") {
debug!("found data.dar!");
let ar_buf = {
use std::io::Read;
let mut b = vec![];
Expand All @@ -102,6 +104,7 @@ impl DebArtifact {
let decompressed_tarball = produce_from_tmp.path_view().join("decompressed.tar");
let output_tmp = TempDir::new().await?;

debug!("extracting to {}", produce_from_tarball.display());
// Write ar_buf to produce_from_tmp
let mut ar_file = File::create(&produce_from_tarball).await?;
ar_file.write_all(&ar_buf).await?;
Expand All @@ -127,6 +130,7 @@ impl DebArtifact {
.produce_from(&decompressed_artifact)
.await?;

debug!("copying data artifact to memfs...");
// Copy decompressed_data_artifact to fs
fs.copy_files_from_paths(
&vec![output_tmp.path_view()],
Expand Down Expand Up @@ -304,6 +308,7 @@ impl ArtifactProducer for DebProducer {
let tmp = TempDir::new().await?;

// Create data.tar from previous artifact in tmp using TarballProducer
info!("packaging data files...");
debug!("producing data.tar from previous artifact...");
let data_tar = tmp.path_view().join("data.tar");
let _tar_artifact = TarballProducer {
Expand All @@ -316,6 +321,7 @@ impl ArtifactProducer for DebProducer {
.await?;

// Create control.tar from control file in tmp
info!("packaging metadata files...");
debug!("producing control.tar...");
let control_tar = tmp.path_view().join("control.tar");
let mut control_tar_builder = tokio_tar::Builder::new(File::create(&control_tar).await?);
Expand Down Expand Up @@ -361,6 +367,7 @@ impl ArtifactProducer for DebProducer {
debug!("wrote postinst file {} to control.tar", postinst.display());
}

info!("computing checksums...");
// Compute the md5sums of every file in the memfs
let mut md5sums = vec![];
let memfs = previous.extract().await?;
Expand Down Expand Up @@ -412,7 +419,7 @@ impl ArtifactProducer for DebProducer {
}

// Create .deb ar archive from debian-binary, control.tar, and data.tar
debug!("building final .deb...");
info!("building final .deb...");
let mut deb_builder = ar::Builder::new(std::fs::File::create(&self.path)?);

deb_builder.append_path(&debian_binary)?;
Expand Down
6 changes: 5 additions & 1 deletion src/artifact/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Artifact for DockerArtifact {
let docker = Docker::connect_with_local_defaults()?;
let (image, tag) = split_image_name_into_repo_and_tag(&self.image);

info!("attempting to pull {}...", self.image);
// Attempt to download the image
let mut pull = docker.create_image(
Some(CreateImageOptions {
Expand All @@ -61,8 +62,9 @@ impl Artifact for DockerArtifact {
// Export image to a TAR file
let tmp = TempDir::new().await?;

info!("exporting to tarball...");
let mut export = docker.export_image(&self.image);
let export_name = format!("{}.tar", self.name);
let export_name = format!("{}.tar", self.name.replace(['/', ':', ' '], "_"));
let export_path = tmp.path_view().join(&export_name);
tokio::fs::create_dir_all(export_path.parent().unwrap())
.await
Expand All @@ -88,6 +90,7 @@ impl Artifact for DockerArtifact {
tokio::fs::remove_dir_all(&tmp).await?;

// Collect layers
info!("gathering docker layers...");
let mut manifest = basic_tar_fs.open_file("/manifest.json").await?;
let mut buf = String::new();
manifest.read_to_string(&mut buf).await?;
Expand All @@ -105,6 +108,7 @@ impl Artifact for DockerArtifact {
.map(|v| v.as_str().unwrap())
.collect();

info!("extracting docker layers into memfs...");
let tmp = TempDir::new().await?;
for layer in layers {
// For each layer, extract it into the tmp directory.
Expand Down
5 changes: 3 additions & 2 deletions src/artifact/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Artifact for RpmArtifact {
async fn extract(&self) -> Result<MemFS> {
use tokio::io::{AsyncReadExt, AsyncWriteExt};

debug!("reading rpm: {}", &self.path.display());
info!("extracting {}...", &self.path.display());
let mut rpm_file = tokio::fs::File::open(&self.path).await?;
let metadata = rpm_file.metadata().await?;
let size = metadata.len();
Expand Down Expand Up @@ -187,6 +187,7 @@ impl ArtifactProducer for RpmProducer {

/// Produce a new artifact, given a previous artifact.
async fn produce_from(&self, previous: &dyn Artifact) -> Result<Self::Output> {
info!("producing {}", self.path.display());
debug!("extracting previous artifact to tmpdir");
let tmp = TempDir::new().await?;
let file_artifact = FileProducer {
Expand Down Expand Up @@ -225,7 +226,7 @@ impl ArtifactProducer for RpmProducer {
pkg = pkg.requires(rpm::Dependency::any(dep));
}

debug!("building package!");
info!("building final rpm...");
let pkg = pkg.build().unwrap();
let path_clone = self.path.clone();
let join_handle = tokio::task::spawn_blocking(move || {
Expand Down
5 changes: 3 additions & 2 deletions src/artifact/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Artifact for TarballArtifact {
// filesystem.
// This is sadly necessary because Rust's tar libraries don't allow for
// in-memory manipulation.
debug!("unpacking tarball to {:?}", self.path);
info!("unpacking {}", self.path.display());

let decompress_tmpdir = TempDir::new().await?;
let decompressed_tarball = decompress_tmpdir.path_view().join("decompressed.tar");
Expand Down Expand Up @@ -99,7 +99,7 @@ impl SelfValidation for TarballArtifact {
}

if !errors.is_empty() {
return Err(eyre!("Tarball artifact not valid:\n{}", errors.join("\n")));
return Err(eyre!("tarball artifact not valid:\n{}", errors.join("\n")));
}

Ok(())
Expand Down Expand Up @@ -159,6 +159,7 @@ impl ArtifactProducer for TarballProducer {
}

async fn produce_from(&self, previous: &dyn Artifact) -> Result<TarballArtifact> {
info!("producing {}", self.path.display());
let memfs = previous.extract().await?;
let memfs = self.inject(&memfs).await?;
let paths = traverse_memfs(memfs, &PathBuf::from("/"), Some(true)).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Pipeline {
let mut output_artifacts: Vec<Box<dyn Artifact>> = vec![];

for (i, producer) in config.output.iter().enumerate() {
info!("step {}: {}", i + 1, producer.name());
info!("* step {}: {}", i + 1, producer.name());
let next_artifact: Box<dyn Artifact> = match producer {
ConfiguredProducer::File(producer) => {
producer.validate().await?;
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Pipeline {
input_artifact = next_artifact.try_clone()?;
}

info!("created artifact: {}", next_artifact.name());
info!("* created artifact: {}", next_artifact.name());
output_artifacts.push(next_artifact);
}

Expand Down

0 comments on commit 7cf6f00

Please sign in to comment.