Skip to content

Commit

Permalink
Merge pull request #18327 from rhatdan/docker
Browse files Browse the repository at this point in the history
Add sha256: to images history id for docker compatibility
  • Loading branch information
openshift-merge-robot authored Apr 27, 2023
2 parents af185b2 + edaf3b4 commit c50d223
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/api/handlers/compat/images_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/python/docker/compat/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ def test_image_history(self):
"""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"""
Expand Down

0 comments on commit c50d223

Please sign in to comment.