Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the image-tool work with -rc5 #144

Merged
merged 2 commits into from
Jun 21, 2017

Conversation

zhouhao3
Copy link

@zhouhao3 zhouhao3 commented May 8, 2017

This is a #121 follow-up PR, make the image-tool work with -rc5. Sorry so late update.

Signed-off-by: zhouhao [email protected]

@zhouhao3 zhouhao3 force-pushed the up-validate branch 4 times, most recently from ad644c4 to 29d31ee Compare May 8, 2017 05:28
@@ -48,19 +50,36 @@ func (d *descriptor) hash() string {
return pts[1]
}

// Index implementation
type Index v1.ImageIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really needed. Is there a particular reason to make a local type for this struct? I could end up complicating golang type assertions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this struct to carry the contents of index.json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why not just use v1.ImageIndex? You're not defining any methods so there should be no need to add this extra level of type indirection.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, updated, thanks.

return nil
}

var d descriptor
if err := json.NewDecoder(r).Decode(&d); err != nil {
buf, err := ioutil.ReadAll(r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing a .ReadAll is a bit more expensive, where the previous version is a streaming decoder. I'd prefer a streaming decoder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. PTAL.

return nil
}

if err := json.NewDecoder(r).Decode(&d); err != nil {
buf, err := ioutil.ReadAll(r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@zhouhao3 zhouhao3 force-pushed the up-validate branch 2 times, most recently from b8c8494 to ea52a59 Compare May 9, 2017 09:02
@runcom
Copy link
Member

runcom commented May 10, 2017

@cyphar PTAL (need this for skopeo tests in containers/skopeo#313)

runcom added a commit to runcom/skopeo-1 that referenced this pull request May 10, 2017
runcom added a commit to runcom/skopeo-1 that referenced this pull request May 10, 2017
runcom added a commit to runcom/skopeo-1 that referenced this pull request May 10, 2017
@zhouhao3
Copy link
Author

What do you think of this PR? Some of the improvements in image-tools need to be done on this basis. @vbatts @runcom @cyphar @stevvooe @coolljt0725 @xiekeyang PTAL

d.MediaType = index.Manifests[i].Descriptor.MediaType
d.Digest = string(index.Manifests[i].Descriptor.Digest)
d.Size = index.Manifests[i].Descriptor.Size
refs[index.Manifests[i].Descriptor.Annotations["org.opencontainers.ref.name"]] = &d
Copy link
Member

@cyphar cyphar May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will completely flatten the set of references (silently ignoring duplicates). I've spent quite a while trying to come up with a sane API for umoci and I think I've decided the only way to implement this is to remove the concept of a reference in the lower-level libraries and have it as a higher-level construct.

In umoci this split was quite easy to do with oci/cas vs oci/casext which adds implementation-agnostic extensions to oci/cas. Maybe that's something you can do so you can remove the old concepts of a reference being a simple mapping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making this so complicated? Just return a slice of descriptors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, and just append here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevvooe ... because first-class references aren't a property of the underlying storage anymore ...

Whatever, I'm not going to get into another argument over this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to use type descriptor v1.Descriptor instead of descriptor, but the following error occurs:

/tmp/go-build341304265/github.com/opencontainers/image-tools/image/_test/_obj_test/descriptor.go:47:cannot use d.Digest (type digest.Digest) as type string in argument to strings.SplitN
/tmp/go-build341304265/github.com/opencontainers/image-tools/image/_test/_obj_test/descriptor.go:81: cannot use &index.Manifests[i].Descriptor (type *v1.Descriptor) as type *descriptor in assignment

What I am using is what I can think of.As for the kind of ideas you say I want to do, but can not solve the problem after the amendment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever, I'm not going to get into another argument over this.

Please avoid the passive aggressive tone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@q384566678 You need to convert to string: dgst.String() should do the trick. However, it also looks like this local descriptor type is no longer needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevvooe Sorry to disturb, I have solved other problems, only the problem can not be resolved.

descriptor.go:64: cannot use index.Manifests[i].Descriptor (type v1.Descriptor) as type descriptor in assignment

Or is there a problem with my method. Can we discuss this question? If can't solve the problem I think I still use the method in ea52a59. ( I think this method is feasible.)
I hope to also try to promote the development of image-tool, but sometimes some technical problems need your help.Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@q384566678 The problem is that there is a local type descriptor and a common type, v1.Descriptor. You either need to convert the types or just use the v1.Descriptor type.

@zhouhao3 zhouhao3 force-pushed the up-validate branch 2 times, most recently from 4b1b706 to 06d86d2 Compare June 6, 2017 02:36
@zhouhao3
Copy link
Author

zhouhao3 commented Jun 6, 2017

@runcom @stevvooe @vbatts @cyphar updated.PTAL

@zhouhao3
Copy link
Author

zhouhao3 commented Jun 9, 2017

@opencontainers/image-tools-maintainers PTAL

@zhouhao3
Copy link
Author

@opencontainers/image-tools-maintainers I think this can be merged.PTAL, thanks.

Digest string `json:"digest"`
Size int64 `json:"size"`
}
type descriptor v1.Descriptor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this type definition? Just use the type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the type def please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated,I used to define this type because of this function,

func (d *descriptor) validate(w walker, mts []string) error {

and now I changed it to

func ValidateDescriptor(d *v1.Descriptor, w walker, mts []string) error {

PTAL

Digest string `json:"digest"`
Size int64 `json:"size"`
}
type descriptor v1.Descriptor

func (d *descriptor) algo() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost this code: this just go-digest to do this properly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@stevvooe
Copy link
Contributor

@q384566678 Rather than defining a new descriptor type, just use the existing one.

@zhouhao3
Copy link
Author

@stevvooe
If not, two descriptor cannot be assigned. (Type conversion is not ok. )

descriptor.go:67: cannot convert &index.Manifests[i].Descriptor (type *v1.Descriptor) to type *descriptor

If you want to use the original definition as you say, you can only assign each structure separately in the original way:

d.MediaType = index.Manifests[i].Descriptor.MediaType
d.Digest = string(index.Manifests[i].Descriptor.Digest)
d.Size = index.Manifests[i].Descriptor.Size

@stevvooe
Copy link
Contributor

@q384566678 The type definition is not needed. Remove the extra type and it will work. You may need to update a few to make it work.

@zhouhao3 zhouhao3 force-pushed the up-validate branch 2 times, most recently from fdb2505 to ba46dee Compare June 15, 2017 06:33
case errEOW:
return &d, nil
default:
return nil, err
}
}

func (d *descriptor) validate(w walker, mts []string) error {
//ValidateDescriptor validate descriptor type
func ValidateDescriptor(d *v1.Descriptor, w walker, mts []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export this. It is use unexported interfaces, so it is pointless, anyways.

@@ -105,7 +96,7 @@ func (d *descriptor) validate(w walker, mts []string) error {
return fmt.Errorf("invalid descriptor MediaType %q", d.MediaType)
}

parsed, err := digest.Parse(d.Digest)
parsed, err := digest.Parse(string(d.Digest))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to parse a digest that is already a digest. Just call d.Digest.Validate().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, PTAL, thanks.

}

parsed, err := digest.Parse(desc.Digest)
parsed, err := digest.Parse(string(desc.Digest))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc.Digest.Validate()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, PTAL.
ping @opencontainers/image-tools-maintainers

@stevvooe
Copy link
Contributor

stevvooe commented Jun 20, 2017

LGTM

Approved with PullApprove

@zhouhao3
Copy link
Author

@xiekeyang @coolljt0725 @vbatts PTAL.

@cyphar
Copy link
Member

cyphar commented Jun 21, 2017

Do we want to add explicit validation for index.json?

LGTM otherwise, we can do that in a follow-up.

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit 2d16afd into opencontainers:master Jun 21, 2017
@zhouhao3 zhouhao3 deleted the up-validate branch June 21, 2017 01:29
@cyphar
Copy link
Member

cyphar commented Jun 21, 2017

@q384566678 Can you answer this question please?

Do we want to add explicit validation for index.json?

@zhouhao3
Copy link
Author

@cyphar I wrote a validation that contained the existence of index.json in #84 and the validation of index.json content in #51 (I will convert the validation of the manifest list to index.json.).

@cyphar
Copy link
Member

cyphar commented Jun 21, 2017

👍

@xiekeyang xiekeyang mentioned this pull request Jun 29, 2017
@zhouhao3 zhouhao3 mentioned this pull request Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants