Add sha256: to images history id for docker compatibility

Fixes: https://github.com/containers/podman/issues/17762

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2023-04-24 15:18:07 -04:00
parent 846e7aa21b
commit edaf3b4d5e
3 changed files with 16 additions and 4 deletions

View File

@ -33,13 +33,17 @@ func HistoryImage(w http.ResponseWriter, r *http.Request) {
allHistory := make([]handlers.HistoryResponse, 0, len(history))
for _, h := range history {
l := handlers.HistoryResponse{
ID: h.ID,
Created: h.Created.Unix(),
CreatedBy: h.CreatedBy,
Tags: h.Tags,
Size: h.Size,
Comment: h.Comment,
}
if utils.IsLibpodRequest(r) {
l.ID = h.ID
} else {
l.ID = "sha256:" + h.ID
}
allHistory = append(allHistory, l)
}
utils.WriteResponse(w, http.StatusOK, allHistory)

View File

@ -78,6 +78,15 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
.[0].Comment=
done
for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
t GET images/$i/history 200 \
.[0].Id="sha256:"$iid \
.[0].Created~[0-9]\\{10\\} \
.[0].Tags=null \
.[0].Size=0 \
.[0].Comment=
done
# Export an image on the local
t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500

View File

@ -70,12 +70,11 @@ class TestImages(common.DockerTestCase):
"""Image history"""
img = self.docker.images.get(constant.ALPINE)
history = img.history()
image_id = img.id[7:] if img.id.startswith("sha256:") else img.id
found = False
for change in history:
found |= image_id in change.values()
self.assertTrue(found, f"image id {image_id} not found in history")
found |= img.id in change.values()
self.assertTrue(found, f"image id {img.id} not found in history")
def test_get_image_exists_not(self):
"""Negative test for get image"""