Skip to content

Commit

Permalink
Merge pull request #879 from vrothberg/path-pull
Browse files Browse the repository at this point in the history
pull: fix pulling from dir transport
  • Loading branch information
openshift-merge-robot authored Jan 10, 2022
2 parents d0895d2 + 134e83f commit 5476e2b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
19 changes: 9 additions & 10 deletions libimage/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
}

filters := map[string][]filterFunc{}
duplicate := map[string]bool{}
duplicate := map[string]string{}
for _, f := range options.Filters {
var key, value string
var filter filterFunc
Expand Down Expand Up @@ -167,7 +167,6 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
if err != nil {
return nil, err
}
duplicate[key] = true
filter = filterManifest(ctx, manifest)

case "reference":
Expand All @@ -189,11 +188,11 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
return filters, nil
}

func (r *Runtime) containers(duplicate map[string]bool, key, value string, externalFunc IsExternalContainerFunc) error {
if duplicate[key] {
return errors.Errorf("specifying %q filter more then once is not supported", key)
func (r *Runtime) containers(duplicate map[string]string, key, value string, externalFunc IsExternalContainerFunc) error {
if exists, ok := duplicate[key]; ok && exists != value {
return errors.Errorf("specifying %q filter more than once with different values is not supported", key)
}
duplicate[key] = true
duplicate[key] = value
switch value {
case "false", "true":
case "external":
Expand Down Expand Up @@ -227,11 +226,11 @@ func (r *Runtime) time(key, value string) (*Image, error) {
return img, nil
}

func (r *Runtime) bool(duplicate map[string]bool, key, value string) (bool, error) {
if duplicate[key] {
return false, errors.Errorf("specifying %q filter more then once is not supported", key)
func (r *Runtime) bool(duplicate map[string]string, key, value string) (bool, error) {
if exists, ok := duplicate[key]; ok && exists != value {
return false, errors.Errorf("specifying %q filter more than once with different values is not supported", key)
}
duplicate[key] = true
duplicate[key] = value
set, err := strconv.ParseBool(value)
if err != nil {
return false, errors.Wrapf(err, "non-boolean value %q for %s filter", key, value)
Expand Down
10 changes: 8 additions & 2 deletions libimage/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,14 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
imageName = named.String()

default:
storageName = toLocalImageName(ref.StringWithinTransport())
imageName = storageName
// Path-based transports (e.g., dir) may include invalid
// characters, so we should pessimistically generate an ID
// instead of looking at the StringWithinTransport().
storageName, err = getImageID(ctx, ref, nil)
if err != nil {
return nil, err
}
imageName = "sha256:" + storageName[1:]
}

// Create a storage reference.
Expand Down
3 changes: 3 additions & 0 deletions libimage/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func TestPull(t *testing.T) {
{"docker://docker.io/library/alpine", false, 1, []string{"docker.io/library/alpine:latest"}},
{"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00", false, 1, []string{"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00"}},
{"quay.io/libpod/alpine:pleaseignorethistag@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00", false, 1, []string{"quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00"}},

// DIR
{"dir:testdata/scratch-dir-5pec!@L", false, 1, []string{"61e17f84d763cc086d43c67dcf4cdbd69f9224c74e961c53b589b70499eac443"}},
} {
pulledImages, err := runtime.Pull(ctx, test.input, config.PullPolicyAlways, pullOptions)
if test.expectError {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"created":"2021-12-20T13:03:01.601633431Z","architecture":"amd64","os":"linux","config":{"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Labels":{"io.buildah.version":"1.23.1"}},"rootfs":{"type":"layers","diff_ids":["sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"]},"history":[{"created":"2021-12-20T13:03:01.602339865Z","created_by":"/bin/sh"}]}
1 change: 1 addition & 0 deletions libimage/testdata/scratch-dir-5pec!@L/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schemaVersion":2,"config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:61e17f84d763cc086d43c67dcf4cdbd69f9224c74e961c53b589b70499eac443","size":402},"layers":[{"mediaType":"application/vnd.oci.image.layer.v1.tar","digest":"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef","size":1024}],"annotations":{"org.opencontainers.image.base.digest":"","org.opencontainers.image.base.name":""}}
1 change: 1 addition & 0 deletions libimage/testdata/scratch-dir-5pec!@L/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory Transport Version: 1.1

0 comments on commit 5476e2b

Please sign in to comment.