-
Notifications
You must be signed in to change notification settings - Fork 907
General image API cleanups #58
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
Changes from all commits
e3d257e
60e8d63
9766f72
7598aab
6a357b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,7 @@ var ( | |
|
|
||
| type dockerImage struct { | ||
| src *dockerImageSource | ||
| digest string | ||
| rawManifest []byte | ||
| cachedManifest []byte // Private cache for Manifest(); nil if not yet known. | ||
| cachedSignatures [][]byte // Private cache for Signatures(); nil if not yet known. | ||
| } | ||
|
|
||
|
|
@@ -44,10 +43,14 @@ func (i *dockerImage) IntendedDockerReference() string { | |
|
|
||
| // Manifest is like ImageSource.GetManifest, but the result is cached; it is OK to call this however often you need. | ||
| func (i *dockerImage) Manifest() ([]byte, error) { | ||
| if err := i.retrieveRawManifest(); err != nil { | ||
| return nil, err | ||
| if i.cachedManifest == nil { | ||
| m, err := i.src.GetManifest() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| i.cachedManifest = m | ||
| } | ||
| return i.rawManifest, nil | ||
| return i.cachedManifest, nil | ||
| } | ||
|
|
||
| // Signatures is like ImageSource.GetSignatures, but the result is cached; it is OK to call this however often you need. | ||
|
|
@@ -62,7 +65,7 @@ func (i *dockerImage) Signatures() ([][]byte, error) { | |
| return i.cachedSignatures, nil | ||
| } | ||
|
|
||
| func (i *dockerImage) Inspect() (types.ImageManifest, error) { | ||
| func (i *dockerImage) Inspect() (*types.ImageInspectInfo, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for pointer here since this is an interface
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aww gotcha sorry for the noise |
||
| // TODO(runcom): unused version param for now, default to docker v2-1 | ||
| m, err := i.getSchema1Manifest() | ||
| if err != nil { | ||
|
|
@@ -72,18 +75,24 @@ func (i *dockerImage) Inspect() (types.ImageManifest, error) { | |
| if !ok { | ||
| return nil, fmt.Errorf("error retrivieng manifest schema1") | ||
| } | ||
| tags, err := i.getTags() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| imgManifest, err := makeImageManifest(i.src.ref.FullName(), ms1, i.digest, tags) | ||
| if err != nil { | ||
| v1 := &v1Image{} | ||
| if err := json.Unmarshal([]byte(ms1.History[0].V1Compatibility), v1); err != nil { | ||
| return nil, err | ||
| } | ||
| return imgManifest, nil | ||
| return &types.ImageInspectInfo{ | ||
| Name: i.src.ref.FullName(), | ||
| Tag: ms1.Tag, | ||
| DockerVersion: v1.DockerVersion, | ||
| Created: v1.Created, | ||
| Labels: v1.Config.Labels, | ||
| Architecture: v1.Architecture, | ||
| Os: v1.OS, | ||
| Layers: ms1.GetLayers(), | ||
| }, nil | ||
| } | ||
|
|
||
| func (i *dockerImage) getTags() ([]string, error) { | ||
| // GetRepositoryTags list all tags available in the repository. Note that this has no connection with the tag(s) used for this specific image, if any. | ||
| func (i *dockerImage) GetRepositoryTags() ([]string, error) { | ||
| // FIXME? Breaking the abstraction. | ||
| url := fmt.Sprintf(tagsURL, i.src.ref.RemoteName()) | ||
| res, err := i.src.c.makeRequest("GET", url, nil, nil) | ||
|
|
@@ -122,25 +131,6 @@ type v1Image struct { | |
| OS string `json:"os,omitempty"` | ||
| } | ||
|
|
||
| func makeImageManifest(name string, m *manifestSchema1, dgst string, tagList []string) (types.ImageManifest, error) { | ||
| v1 := &v1Image{} | ||
| if err := json.Unmarshal([]byte(m.History[0].V1Compatibility), v1); err != nil { | ||
| return nil, err | ||
| } | ||
| return &types.DockerImageManifest{ | ||
| Name: name, | ||
| Tag: m.Tag, | ||
| Digest: dgst, | ||
| RepoTags: tagList, | ||
| DockerVersion: v1.DockerVersion, | ||
| Created: v1.Created, | ||
| Labels: v1.Config.Labels, | ||
| Architecture: v1.Architecture, | ||
| Os: v1.OS, | ||
| Layers: m.GetLayers(), | ||
| }, nil | ||
| } | ||
|
|
||
| // TODO(runcom) | ||
| func (i *dockerImage) DockerTar() ([]byte, error) { | ||
| return nil, nil | ||
|
|
@@ -181,25 +171,13 @@ func sanitize(s string) string { | |
| return strings.Replace(s, "/", "-", -1) | ||
| } | ||
|
|
||
| func (i *dockerImage) retrieveRawManifest() error { | ||
| if i.rawManifest != nil { | ||
| return nil | ||
| } | ||
| manblob, unverifiedCanonicalDigest, err := i.src.GetManifest() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| i.rawManifest = manblob | ||
| i.digest = unverifiedCanonicalDigest | ||
| return nil | ||
| } | ||
|
|
||
| func (i *dockerImage) getSchema1Manifest() (manifest, error) { | ||
| if err := i.retrieveRawManifest(); err != nil { | ||
| manblob, err := i.Manifest() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| mschema1 := &manifestSchema1{} | ||
| if err := json.Unmarshal(i.rawManifest, mschema1); err != nil { | ||
| if err := json.Unmarshal(manblob, mschema1); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := fixManifestLayers(mschema1); err != nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you this does smell here... (I mean this tag method on the generic image interface)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improves the interface at least a little. How to do it truly cleanly and in a generic way, without breaking existing users (if any?) is not clear to me yet; I was thinking
as another small step towards kicking this out of
types.Image. Eventually; this is not really hurting me :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That type assertion sounds fine to me and it's clean (tags can be omitemtpy when/if marshaling also)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will eventually need to generalize
dockerImageto work withopenshiftImageSource, at that point the type assertion will make sense, because we could test thetags = nilpath.Or do you want it done immediately so that the
GetRepositoryTagsmethod is never added totypes.Image?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine doing it later (hopefully we would freeze the API in the coming weeks so we are still more time to think more about this :)
We can leave a comment though just in case we forgot about doing this larer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment pointing to this thread, within the “Add comments on the use of the API and the general direction” commit.