Browse code

Add support for schema 1 pull

Signed-off-by: Derek McGowan <derek@mcgstyle.net>

Derek McGowan authored on 2018/06/07 02:40:11
Showing 1 changed files
... ...
@@ -234,7 +234,12 @@ func (p *puller) resolve(ctx context.Context) error {
234 234
 			p.ref = origRef
235 235
 		}
236 236
 
237
-		if p.config == nil {
237
+		// Schema 1 manifests cannot be resolved to an image config
238
+		// since the conversion must take place after all the content
239
+		// has been read.
240
+		// It may be possible to have a mapping between schema 1 manifests
241
+		// and the schema 2 manifests they are converted to.
242
+		if p.config == nil && p.desc.MediaType != images.MediaTypeDockerSchema1Manifest {
238 243
 			ref, err := distreference.WithDigest(ref, p.desc.Digest)
239 244
 			if err != nil {
240 245
 				p.resolveErr = err
... ...
@@ -328,11 +333,22 @@ func (p *puller) Snapshot(ctx context.Context) (cache.ImmutableRef, error) {
328 328
 		return nil, err
329 329
 	}
330 330
 
331
-	// TODO: need a wrapper snapshot interface that combines content
332
-	// and snapshots as 1) buildkit shouldn't have a dependency on contentstore
333
-	// or 2) cachemanager should manage the contentstore
334
-	handlers := []images.Handler{
335
-		images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
331
+	var (
332
+		schema1Converter *schema1.Converter
333
+		handlers         []images.Handler
334
+	)
335
+	if p.desc.MediaType == images.MediaTypeDockerSchema1Manifest {
336
+		schema1Converter = schema1.NewConverter(p.is.ContentStore, fetcher)
337
+		handlers = append(handlers, schema1Converter)
338
+
339
+		// TODO: Optimize to do dispatch and integrate pulling with download manager,
340
+		// leverage existing blob mapping and layer storage
341
+	} else {
342
+
343
+		// TODO: need a wrapper snapshot interface that combines content
344
+		// and snapshots as 1) buildkit shouldn't have a dependency on contentstore
345
+		// or 2) cachemanager should manage the contentstore
346
+		handlers = append(handlers, images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
336 347
 			switch desc.MediaType {
337 348
 			case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest,
338 349
 				images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex,
... ...
@@ -342,25 +358,8 @@ func (p *puller) Snapshot(ctx context.Context) (cache.ImmutableRef, error) {
342 342
 			}
343 343
 			ongoing.add(desc)
344 344
 			return nil, nil
345
-		}),
346
-	}
347
-	// var schema1Converter *schema1.Converter
348
-	// if p.desc.MediaType == images.MediaTypeDockerSchema1Manifest {
349
-	// 	schema1Converter = schema1.NewConverter(p.is.ContentStore, fetcher)
350
-	// 	handlers = append(handlers, schema1Converter)
351
-	// } else {
352
-	// 	handlers = append(handlers,
353
-	// 		remotes.FetchHandler(p.is.ContentStore, fetcher),
354
-	//
355
-	// 		images.ChildrenHandler(p.is.ContentStore),
356
-	// 	)
357
-	// }
358
-	//
359
-	var schema1Converter *schema1.Converter
360
-	if p.desc.MediaType == images.MediaTypeDockerSchema1Manifest {
361
-		schema1Converter = schema1.NewConverter(p.is.ContentStore, fetcher)
362
-		handlers = append(handlers, schema1Converter)
363
-	} else {
345
+		}))
346
+
364 347
 		// Get all the children for a descriptor
365 348
 		childrenHandler := images.ChildrenHandler(p.is.ContentStore)
366 349
 		// Set any children labels for that content
... ...
@@ -380,6 +379,13 @@ func (p *puller) Snapshot(ctx context.Context) (cache.ImmutableRef, error) {
380 380
 	}
381 381
 	defer stopProgress()
382 382
 
383
+	if schema1Converter != nil {
384
+		p.desc, err = schema1Converter.Convert(ctx)
385
+		if err != nil {
386
+			return nil, err
387
+		}
388
+	}
389
+
383 390
 	mfst, err := images.Manifest(ctx, p.is.ContentStore, p.desc, platforms.Default())
384 391
 	if err != nil {
385 392
 		return nil, err