Skip to content

Commit

Permalink
Resolve image name to ID before fetching digest to resolve false drift
Browse files Browse the repository at this point in the history
EL9.5 ships podman v5 with skopeo 1.16 up from 1.14. The behaviour of how
image digests are reported has changed, causing `podman::container` to
consider needing to fetch a new image on every run and unwanted container
restarts.

`podman image inspect --format='{{.Digest}}'` now returns different hashes
depending on whether an image ID or a tag is given as argument.

Skopeo reports the image digest in the registry as if podman image inspect
were called with the image ID.

This code resolves the given image name (which might be an ID or a Tag)
into the ID before trying to fetch the digest. This prevents the false
drift.

Fixes #91
  • Loading branch information
optiz0r committed Dec 6, 2024
1 parent 394a7fe commit 578e036
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifests/container.pp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
if podman container exists ${container_name}
then
image_name=\$(podman container inspect ${container_name} --format '{{.ImageName}}')
running_digest=\$(podman image inspect \${image_name} --format '{{.Digest}}')
running_digest=\$(podman image inspect $(podman image inspect \${image_name} --format='{{.ID}}') --format '{{.Digest}}')
latest_digest=\$(skopeo inspect docker://${image} | \
${_ruby} -rjson -e 'puts (JSON.parse(STDIN.read))["Digest"]')
[[ $? -ne 0 ]] && latest_digest=\$(skopeo inspect --no-creds docker://${image} | \
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
|if podman container exists namevar
| then
| image_name=$(podman container inspect namevar --format '{{.ImageName}}')
| running_digest=$(podman image inspect ${image_name} --format '{{.Digest}}')
| running_digest=$(podman image inspect $(podman image inspect ${image_name} --format='{{.ID}}') --format '{{.Digest}}')
| latest_digest=$(skopeo inspect docker://registry:latest | /opt/puppetlabs/puppet/bin/ruby -rjson -e 'puts (JSON.parse(STDIN.read))["Digest"]')
| [[ $? -ne 0 ]] && latest_digest=$(skopeo inspect --no-creds docker://registry:latest | /opt/puppetlabs/puppet/bin/ruby -rjson -e 'puts (JSON.parse(STDIN.read))["Digest"]')
| test -z "${latest_digest}" && exit 0 # Do not update if unable to get latest digest
Expand All @@ -62,7 +62,7 @@
|if podman container exists namevar
| then
| image_name=$(podman container inspect namevar --format '{{.ImageName}}')
| running_digest=$(podman image inspect ${image_name} --format '{{.Digest}}')
| running_digest=$(podman image inspect $(podman image inspect ${image_name} --format='{{.ID}}') --format '{{.Digest}}')
| latest_digest=$(skopeo inspect docker://registry:latest | /usr/bin/ruby -rjson -e 'puts (JSON.parse(STDIN.read))["Digest"]')
| [[ $? -ne 0 ]] && latest_digest=$(skopeo inspect --no-creds docker://registry:latest | /usr/bin/ruby -rjson -e 'puts (JSON.parse(STDIN.read))["Digest"]')
| test -z "${latest_digest}" && exit 0 # Do not update if unable to get latest digest
Expand Down

0 comments on commit 578e036

Please sign in to comment.