diff --git a/pkg/storage/image.go b/pkg/storage/image.go index 335c91eb..a67e8b11 100644 --- a/pkg/storage/image.go +++ b/pkg/storage/image.go @@ -43,7 +43,19 @@ type ImageServer interface { func (svc *imageService) ListImages(filter string) ([]ImageResult, error) { results := []ImageResult{} if filter != "" { - if image, err := svc.store.GetImage(filter); err == nil { + ref, err := alltransports.ParseImageName(filter) + if err != nil { + ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+filter) + if err2 != nil { + ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, filter) + if err3 != nil { + return nil, err + } + ref2 = ref3 + } + ref = ref2 + } + if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil { results = append(results, ImageResult{ ID: image.ID, Names: image.Names, @@ -136,6 +148,9 @@ func (svc *imageService) PullImage(systemContext *types.SystemContext, imageName if tagged, ok := srcRef.DockerReference().(reference.NamedTagged); ok { dest = dest + ":" + tagged.Tag() } + if canonical, ok := srcRef.DockerReference().(reference.Canonical); ok { + dest = dest + "@" + canonical.Digest().String() + } } destRef, err := istorage.Transport.ParseStoreReference(svc.store, dest) if err != nil { diff --git a/test/image.bats b/test/image.bats index f571ac3c..fb9ae641 100644 --- a/test/image.bats +++ b/test/image.bats @@ -32,6 +32,36 @@ function teardown() { stop_ocid } +@test "image pull and list by digest" { + start_ocid "" "" --no-pause-image + run ocic image pull nginx@sha256:4aacdcf186934dcb02f642579314075910f1855590fd3039d8fa4c9f96e48315 + echo "$output" + [ "$status" -eq 0 ] + + run ocic image list --quiet nginx@sha256:4aacdcf186934dcb02f642579314075910f1855590fd3039d8fa4c9f96e48315 + [ "$status" -eq 0 ] + echo "$output" + [ "$output" != "" ] + + run ocic image list --quiet nginx@4aacdcf186934dcb02f642579314075910f1855590fd3039d8fa4c9f96e48315 + [ "$status" -eq 0 ] + echo "$output" + [ "$output" != "" ] + + run ocic image list --quiet @4aacdcf186934dcb02f642579314075910f1855590fd3039d8fa4c9f96e48315 + [ "$status" -eq 0 ] + echo "$output" + [ "$output" != "" ] + + run ocic image list --quiet 4aacdcf186934dcb02f642579314075910f1855590fd3039d8fa4c9f96e48315 + [ "$status" -eq 0 ] + echo "$output" + [ "$output" != "" ] + + cleanup_images + stop_ocid +} + @test "image list with filter" { start_ocid "" "" --no-pause-image run ocic image pull "$IMAGE" @@ -64,6 +94,7 @@ function teardown() { run ocic image list --quiet echo "$output" [ "$status" -eq 0 ] + [ "$output" != "" ] printf '%s\n' "$output" | while IFS= read -r id; do run ocic image remove --id "$id" echo "$output" @@ -72,6 +103,7 @@ function teardown() { run ocic image list --quiet echo "$output" [ "$status" -eq 0 ] + [ "$output" = "" ] printf '%s\n' "$output" | while IFS= read -r id; do echo "$id" status=1 @@ -88,10 +120,12 @@ function teardown() { run ocic image list --quiet echo "$output" [ "$status" -eq 0 ] + [ "$output" != "" ] printf '%s\n' "$output" | while IFS= read -r id; do run ocic image status --id "$id" echo "$output" [ "$status" -eq 0 ] + [ "$output" != "" ] run ocic image remove --id "$id" echo "$output" [ "$status" -eq 0 ] @@ -99,6 +133,7 @@ function teardown() { run ocic image list --quiet echo "$output" [ "$status" -eq 0 ] + [ "$output" = "" ] printf '%s\n' "$output" | while IFS= read -r id; do echo "$id" status=1