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

image: Port to go-digest #104

Merged
merged 2 commits into from
Feb 9, 2017
Merged

Conversation

wking
Copy link
Contributor

@wking wking commented Jan 20, 2017

This is the smallest pivot I could think up (replacing old sha256 imports with go-digest). But I want the go-digest vendoring to land so I can rebase #5 and #40 on top of it. And I expect folks who currently prefer other methods for cleaning up the internal image/* code are also interested in go-digest, so I'm filing this PR to get a base that we hopefully all agree on ;).

@Mashimiao
Copy link

Except need reabase, looks good to me

@wking
Copy link
Contributor Author

wking commented Jan 20, 2017 via email

@coolljt0725
Copy link
Member

coolljt0725 commented Jan 22, 2017

@wking should we also use digest type in descriptor ?

diff --git a/image/descriptor.go b/image/descriptor.go
index 341b65c..eac9279 100644
--- a/image/descriptor.go
+++ b/image/descriptor.go
@@ -24,13 +24,14 @@ import (
        "path/filepath"
        "strings"

+       digest "github.com/opencontainers/go-digest"
        "github.com/pkg/errors"
 )

 type descriptor struct {
-       MediaType string `json:"mediaType"`
-       Digest    string `json:"digest"`
-       Size      int64  `json:"size"`
+       MediaType string        `json:"mediaType"`
+       Digest    digest.Digest `json:"digest"`
+       Size      int64         `json:"size"`
 }

@wking
Copy link
Contributor Author

wking commented Jan 22, 2017

should we also use digest type in descriptor ?

I think we should be using the image-spec type directly (and opencontainers/image-spec#514 is in flight to make that change there). But either way, that sounds like something we can do in a follow-up PR.

@xiekeyang
Copy link
Contributor

xiekeyang commented Jan 22, 2017

@wking you might had better to adjust the commits order, and squash ad0de71, 6cdd607 and c94e7cb to one. That make sure the building passed after resetting to each commit.

@wking
Copy link
Contributor Author

wking commented Jan 22, 2017

you might had better to adjust the commits order, and squash ad0de71, 6cdd607 and c94e7cb to one.

I can't get the go-digest vendor to stick before I add the consuming code, even with the entry in glide.yaml. Is there a glide invocation I'm missing? I'd rather not mix hand-written and auto-generated changes in a single commit.

@xiekeyang
Copy link
Contributor

It should be compile-able after reset to 37624b0.

@wking
Copy link
Contributor Author

wking commented Jan 23, 2017 via email

@xiekeyang
Copy link
Contributor

@wking Please take account my proposal, to squash glide and dependency code to one commit, and keep your writing code as one. That may be better for rolling back. Anyway it is just an alternative.

I debug the PR, it works correctly. The PR mostly looks good to me.

wking added a commit to wking/image-tools that referenced this pull request Jan 23, 2017
I haven't been able to find a glide invocation to add an unused
dependency, so I generated this commit by committing the consuming
code (image: Port to go-digest), running update-deps, and then using
rebase to swap the order of the two commits:

  ...add go-digest conumers...
  $ git commit -sm 'image: Port to go-digest...'
  $ make update-deps
  $ git add vendor/github.com/opencontainers/go-digest
  $ git commit -sm 'vendor/github.com/opencontainers/go-digest: Add dependency...'
  $ git rebase -i HEAD^^
  ...swap the order of the two commits...

That way we have the vendored library if someone checks out the
consuming commit directly [1].

[1]: opencontainers#104 (comment)

Signed-off-by: W. Trevor King <wking@tremily.us>
@wking
Copy link
Contributor Author

wking commented Jan 23, 2017 via email

@xiekeyang
Copy link
Contributor

xiekeyang commented Jan 24, 2017

LGTM

cc @opencontainers/image-tools-maintainers

Approved with PullApprove

@xiekeyang
Copy link
Contributor

@vbatts @philips @stevvooe Is this PR OK?

@coolljt0725
Copy link
Member

@wking let's wait #107 to bump the image-spec and then rebase this pr?

@@ -116,15 +115,18 @@ func (d *descriptor) validate(w walker, mts []string) error {
}

func (d *descriptor) validateContent(r io.Reader) error {
h := sha256.New()
n, err := io.Copy(h, r)
parsed, err := digest.Parse(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.

Just use the OCI descriptor type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love to (and I do that in #5). However, as I pointed out earlier, that would require making this PR larger (and therefore harder to review). I'll gladly file a follow up PR with that change if we can land this initial go-digest consuming code first.

@wking
Copy link
Contributor Author

wking commented Feb 7, 2017 via email

@zhouhao3
Copy link

zhouhao3 commented Feb 7, 2017

do you remember how you accomplished it?

@wking I thought maybe because #537 of merged, then I modified version: v1.0.0-rc4.
Then I executed the make update-deps command

@vbatts
Copy link
Member

vbatts commented Feb 8, 2017

LGTM

Approved with PullApprove

1 similar comment
@stevvooe
Copy link
Contributor

stevvooe commented Feb 8, 2017

LGTM

Approved with PullApprove

@vbatts
Copy link
Member

vbatts commented Feb 8, 2017

bugger. Needs a rebase.

@wking
Copy link
Contributor Author

wking commented Feb 8, 2017 via email

@coolljt0725
Copy link
Member

ping @wking CI failed

wking added 2 commits February 8, 2017 21:50
Outsource this stuff to avoid duplication of effort.

newDescriptor was returning just the hex and createHashedBlob (its
only consumer) was fixing that (by the "Normalize the hashed digest"
comment) so it didn't have to split the hash (Hex) back off.  But that
seems confusing to me, so I've fixed newDescriptor to create a
non-busted digest which we split back apart in createHashedBlob.

Signed-off-by: W. Trevor King <wking@tremily.us>
By editing glide.yaml and then running:

  $ make update-deps

to update the hash.  This way we can bump go-digest intentionally when
we feel so inclined.

Signed-off-by: W. Trevor King <wking@tremily.us>
@wking
Copy link
Contributor Author

wking commented Feb 9, 2017 via email

@xiekeyang
Copy link
Contributor

xiekeyang commented Feb 9, 2017

LGTM

Approved with PullApprove

1 similar comment
@coolljt0725
Copy link
Member

coolljt0725 commented Feb 9, 2017

LGTM

Approved with PullApprove

@coolljt0725 coolljt0725 merged commit 9386a7f into opencontainers:master Feb 9, 2017
@wking wking deleted the go-digest branch February 16, 2017 11:40
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.

7 participants