diff --git a/integration-test.sh b/integration-test.sh index 3fd2d1f..bc3ab1a 100755 --- a/integration-test.sh +++ b/integration-test.sh @@ -11,7 +11,7 @@ done # Start Docuum in the background. echo 'Starting Docuum…' -LOG_LEVEL=debug /docuum-x86_64-unknown-linux-musl --threshold '14 MB' --keep 'alpine:keep' & +LOG_LEVEL=debug /docuum-x86_64-unknown-linux-musl --threshold '20 MB' --keep 'alpine:keep' & DOCUUM_PID="$!" # This function waits for Docuum to start sleeping by checking the process state. The process could @@ -45,7 +45,8 @@ docker run --rm alpine@sha256:4716d67546215299bf023fd80cc9d7e67f4bdc006a360727fd wait_for_docuum -# This image also uses ~5.5 MB. Now we should be above the 14 MB threshold. +# This image also uses ~5.5 MB. For some reason, this pushes us over the 20 MB +# threshold, even though we've only downloaded ~5.5 MB * 3 = ~16.5 MB. echo 'Using another image…' docker run --rm alpine@sha256:fef20cf0221c5c0eaae2d8f59081b07cd351a94ac83cdc74109b17ec90ce0a82 true diff --git a/src/run.rs b/src/run.rs index dad32af..b52cb79 100644 --- a/src/run.rs +++ b/src/run.rs @@ -56,13 +56,14 @@ struct Event { #[serde(rename = "Actor")] actor: EventActor, - - id: String, } // A Docker event actor #[derive(Deserialize, Serialize, Debug)] struct EventActor { + #[serde(rename = "ID")] + id: String, + #[serde(rename = "Attributes")] attributes: EventActorAttributes, } @@ -143,11 +144,25 @@ fn parent_id(state: &State, image_id: &str) -> io::Result> { // Query Docker for the parent image ID. let output = Command::new("docker") .args(["image", "inspect", "--format", "{{.Parent}}", image_id]) - .stderr(Stdio::inherit()) .output()?; // Ensure the command succeeded. if !output.status.success() { + // [tag:missing_parent_behavior] When the image doesn't have a + // `Parent`, Docker Engine API v1.52 (which ships with Docker Engine + // v29.0) and higher omit it. Previous versions return empty string. + if let Ok(output_err) = String::from_utf8(output.stderr) { + if output_err.contains("map has no entry for key \"Parent\"") { + return Ok(None); + } + + return Err(io::Error::other(format!( + "{}Unable to determine ID of the parent of image {}.", + output_err, + image_id.code_str(), + ))); + } + return Err(io::Error::other(format!( "Unable to determine ID of the parent of image {}.", image_id.code_str(), @@ -159,7 +174,7 @@ fn parent_id(state: &State, image_id: &str) -> io::Result> { .map(|output| { let trimmed_output = output.trim(); - // Does the image even have a parent? + // [ref:missing_parent_behavior] Does the image even have a parent? if trimmed_output.is_empty() { None } else { @@ -833,24 +848,15 @@ pub fn run( }; // Get the ID of the image. - let image_id = image_id(&if event.r#type == "container" - && (event.action == "create" || event.action == "destroy") - { + let image_id = image_id(&if event.r#type == "container" { if let Some(image_name) = event.actor.attributes.image { image_name } else { - trace!("Invalid Docker event."); + trace!("Skipping due to irrelevance."); continue; } - } else if event.r#type == "image" - && (event.action == "import" - || event.action == "load" - || event.action == "pull" - || event.action == "push" - || event.action == "save" - || event.action == "tag") - { - event.id + } else if event.r#type == "image" { + event.actor.id } else { trace!("Skipping due to irrelevance."); continue;