@@ -17,6 +17,7 @@ import (
1717 "github.com/containers/image/types"
1818 "github.com/containers/storage"
1919 distreference "github.com/docker/distribution/reference"
20+ digest "github.com/opencontainers/go-digest"
2021)
2122
2223// ImageResult wraps a subset of information about an image: its ID, its names,
@@ -25,6 +26,10 @@ type ImageResult struct {
2526 ID string
2627 Names []string
2728 Size * uint64
29+ // TODO(runcom): this is an hack for https://github.com/kubernetes-incubator/cri-o/pull/1136
30+ // drop this when we have proper image IDs (as in, image IDs should be just
31+ // the config blog digest which is stable across same images).
32+ ConfigDigest digest.Digest
2833}
2934
3035type indexInfo struct {
@@ -47,6 +52,9 @@ type ImageServer interface {
4752 ListImages (systemContext * types.SystemContext , filter string ) ([]ImageResult , error )
4853 // ImageStatus returns status of an image which matches the filter.
4954 ImageStatus (systemContext * types.SystemContext , filter string ) (* ImageResult , error )
55+ // PrepareImage returns an Image where the config digest can be grabbed
56+ // for further analysis. Call Close() on the resulting image.
57+ PrepareImage (systemContext * types.SystemContext , imageName string , options * copy.Options ) (types.Image , error )
5058 // PullImage imports an image from the specified location.
5159 PullImage (systemContext * types.SystemContext , imageName string , options * copy.Options ) (types.ImageReference , error )
5260 // RemoveImage deletes the specified image.
@@ -146,14 +154,16 @@ func (svc *imageService) ImageStatus(systemContext *types.SystemContext, nameOrI
146154 if err != nil {
147155 return nil , err
148156 }
157+ defer img .Close ()
149158 size := imageSize (img )
150- img .Close ()
151159
152- return & ImageResult {
153- ID : image .ID ,
154- Names : image .Names ,
155- Size : size ,
156- }, nil
160+ res := & ImageResult {
161+ ID : image .ID ,
162+ Names : image .Names ,
163+ Size : size ,
164+ ConfigDigest : img .ConfigInfo ().Digest ,
165+ }
166+ return res , nil
157167}
158168
159169func imageSize (img types.Image ) * uint64 {
@@ -165,7 +175,7 @@ func imageSize(img types.Image) *uint64 {
165175}
166176
167177func (svc * imageService ) CanPull (imageName string , options * copy.Options ) (bool , error ) {
168- srcRef , err := svc .prepareImage (imageName , options )
178+ srcRef , err := svc .prepareReference (imageName , options )
169179 if err != nil {
170180 return false , err
171181 }
@@ -182,9 +192,9 @@ func (svc *imageService) CanPull(imageName string, options *copy.Options) (bool,
182192 return true , nil
183193}
184194
185- // prepareImage creates an image reference from an image string and set options
195+ // prepareReference creates an image reference from an image string and set options
186196// for the source context
187- func (svc * imageService ) prepareImage (imageName string , options * copy.Options ) (types.ImageReference , error ) {
197+ func (svc * imageService ) prepareReference (imageName string , options * copy.Options ) (types.ImageReference , error ) {
188198 if imageName == "" {
189199 return nil , storage .ErrNotAnImage
190200 }
@@ -212,6 +222,18 @@ func (svc *imageService) prepareImage(imageName string, options *copy.Options) (
212222 return srcRef , nil
213223}
214224
225+ func (svc * imageService ) PrepareImage (systemContext * types.SystemContext , imageName string , options * copy.Options ) (types.Image , error ) {
226+ if options == nil {
227+ options = & copy.Options {}
228+ }
229+
230+ srcRef , err := svc .prepareReference (imageName , options )
231+ if err != nil {
232+ return nil , err
233+ }
234+ return srcRef .NewImage (systemContext )
235+ }
236+
215237func (svc * imageService ) PullImage (systemContext * types.SystemContext , imageName string , options * copy.Options ) (types.ImageReference , error ) {
216238 policy , err := signature .DefaultPolicy (systemContext )
217239 if err != nil {
@@ -225,7 +247,7 @@ func (svc *imageService) PullImage(systemContext *types.SystemContext, imageName
225247 options = & copy.Options {}
226248 }
227249
228- srcRef , err := svc .prepareImage (imageName , options )
250+ srcRef , err := svc .prepareReference (imageName , options )
229251 if err != nil {
230252 return nil , err
231253 }
0 commit comments