Skip to content
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
5 changes: 3 additions & 2 deletions integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
40 changes: 23 additions & 17 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -143,11 +144,25 @@ fn parent_id(state: &State, image_id: &str) -> io::Result<Option<String>> {
// 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(),
Expand All @@ -159,7 +174,7 @@ fn parent_id(state: &State, image_id: &str) -> io::Result<Option<String>> {
.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 {
Expand Down Expand Up @@ -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;
Expand Down