Browse code

Removing Custom Images support

Now that Windows base images can be loaded directly into docker via "docker load" of a specialized tar file (with docker pull support on the horizon) we no longer have need of the custom images code path that loads images from a shared central location. Removing that code and it's call points.

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>

Stefan J. Wernli authored on 2016/07/08 06:21:56
Showing 4 changed files
... ...
@@ -545,10 +545,6 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
545 545
 		return nil, fmt.Errorf("Couldn't create Tag store repositories: %s", err)
546 546
 	}
547 547
 
548
-	if err := restoreCustomImage(d.imageStore, d.layerStore, referenceStore); err != nil {
549
-		return nil, fmt.Errorf("Couldn't restore custom images: %s", err)
550
-	}
551
-
552 548
 	migrationStart := time.Now()
553 549
 	if err := v1.Migrate(config.Root, graphDriver, d.layerStore, d.imageStore, referenceStore, distributionMetadataStore); err != nil {
554 550
 		logrus.Errorf("Graph migration failed: %q. Your old graph data was found to be too inconsistent for upgrading to content-addressable storage. Some of the old data was probably not upgraded. We recommend starting over with a clean storage directory if possible.", err)
... ...
@@ -19,12 +19,10 @@ import (
19 19
 	"github.com/Sirupsen/logrus"
20 20
 	"github.com/docker/docker/container"
21 21
 	"github.com/docker/docker/image"
22
-	"github.com/docker/docker/layer"
23 22
 	"github.com/docker/docker/pkg/idtools"
24 23
 	"github.com/docker/docker/pkg/parsers"
25 24
 	"github.com/docker/docker/pkg/parsers/kernel"
26 25
 	"github.com/docker/docker/pkg/sysinfo"
27
-	"github.com/docker/docker/reference"
28 26
 	"github.com/docker/docker/runconfig"
29 27
 	runconfigopts "github.com/docker/docker/runconfig/opts"
30 28
 	"github.com/docker/engine-api/types"
... ...
@@ -1064,11 +1062,6 @@ func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container
1064 1064
 	return daemon.Unmount(container)
1065 1065
 }
1066 1066
 
1067
-func restoreCustomImage(is image.Store, ls layer.Store, rs reference.Store) error {
1068
-	// Unix has no custom images to register
1069
-	return nil
1070
-}
1071
-
1072 1067
 func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) {
1073 1068
 	if !c.IsRunning() {
1074 1069
 		return nil, errNotRunning{c.ID}
... ...
@@ -1,27 +1,18 @@
1 1
 package daemon
2 2
 
3 3
 import (
4
-	"encoding/json"
5
-	"errors"
6 4
 	"fmt"
7 5
 	"os"
8
-	"path/filepath"
9
-	"runtime"
10 6
 	"strings"
11 7
 
12 8
 	"github.com/Microsoft/hcsshim"
13 9
 	"github.com/Sirupsen/logrus"
14 10
 	"github.com/docker/docker/container"
15
-	"github.com/docker/docker/daemon/graphdriver"
16
-	"github.com/docker/docker/daemon/graphdriver/windows" // register the windows graph driver
17
-	"github.com/docker/docker/dockerversion"
18 11
 	"github.com/docker/docker/image"
19
-	"github.com/docker/docker/layer"
20 12
 	"github.com/docker/docker/pkg/idtools"
21 13
 	"github.com/docker/docker/pkg/parsers"
22 14
 	"github.com/docker/docker/pkg/sysinfo"
23 15
 	"github.com/docker/docker/pkg/system"
24
-	"github.com/docker/docker/reference"
25 16
 	"github.com/docker/docker/runconfig"
26 17
 	"github.com/docker/engine-api/types"
27 18
 	pblkiodev "github.com/docker/engine-api/types/blkiodev"
... ...
@@ -383,85 +374,6 @@ func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container
383 383
 	return nil
384 384
 }
385 385
 
386
-func restoreCustomImage(is image.Store, ls layer.Store, rs reference.Store) error {
387
-	type graphDriverStore interface {
388
-		GraphDriver() graphdriver.Driver
389
-	}
390
-
391
-	gds, ok := ls.(graphDriverStore)
392
-	if !ok {
393
-		return nil
394
-	}
395
-
396
-	driver := gds.GraphDriver()
397
-	wd, ok := driver.(*windows.Driver)
398
-	if !ok {
399
-		return nil
400
-	}
401
-
402
-	imageInfos, err := wd.GetCustomImageInfos()
403
-	if err != nil {
404
-		return err
405
-	}
406
-
407
-	// Convert imageData to valid image configuration
408
-	for _, info := range imageInfos {
409
-		name := strings.ToLower(info.Name)
410
-
411
-		type registrar interface {
412
-			RegisterDiffID(graphID string, size int64) (layer.Layer, error)
413
-		}
414
-		r, ok := ls.(registrar)
415
-		if !ok {
416
-			return errors.New("Layerstore doesn't support RegisterDiffID")
417
-		}
418
-		if _, err := r.RegisterDiffID(info.ID, info.Size); err != nil {
419
-			return err
420
-		}
421
-		// layer is intentionally not released
422
-
423
-		rootFS := image.NewRootFSWithBaseLayer(filepath.Base(info.Path))
424
-
425
-		// Create history for base layer
426
-		config, err := json.Marshal(&image.Image{
427
-			V1Image: image.V1Image{
428
-				DockerVersion: dockerversion.Version,
429
-				Architecture:  runtime.GOARCH,
430
-				OS:            runtime.GOOS,
431
-				Created:       info.CreatedTime,
432
-			},
433
-			RootFS:     rootFS,
434
-			History:    []image.History{},
435
-			OSVersion:  info.OSVersion,
436
-			OSFeatures: info.OSFeatures,
437
-		})
438
-
439
-		named, err := reference.ParseNamed(name)
440
-		if err != nil {
441
-			return err
442
-		}
443
-
444
-		ref, err := reference.WithTag(named, info.Version)
445
-		if err != nil {
446
-			return err
447
-		}
448
-
449
-		id, err := is.Create(config)
450
-		if err != nil {
451
-			logrus.Warnf("Failed to restore custom image %s with error: %s.", name, err)
452
-			logrus.Warnf("Skipping image %s...", name)
453
-			continue
454
-		}
455
-
456
-		if err := rs.AddTag(ref, id, true); err != nil {
457
-			return err
458
-		}
459
-
460
-		logrus.Debugf("Registered base layer %s as %s", ref, id)
461
-	}
462
-	return nil
463
-}
464
-
465 386
 func driverOptions(config *Config) []nwconfig.Option {
466 387
 	return []nwconfig.Option{}
467 388
 }
... ...
@@ -5,7 +5,6 @@ package windows
5 5
 import (
6 6
 	"bufio"
7 7
 	"bytes"
8
-	"crypto/sha512"
9 8
 	"encoding/json"
10 9
 	"fmt"
11 10
 	"io"
... ...
@@ -17,7 +16,6 @@ import (
17 17
 	"strings"
18 18
 	"sync"
19 19
 	"syscall"
20
-	"time"
21 20
 	"unsafe"
22 21
 
23 22
 	"github.com/Microsoft/go-winio"
... ...
@@ -448,78 +446,6 @@ func (d *Driver) DiffSize(id, parent string) (size int64, err error) {
448 448
 	return archive.ChangesSize(layerFs, changes), nil
449 449
 }
450 450
 
451
-// CustomImageInfo is the object returned by the driver describing the base
452
-// image.
453
-type CustomImageInfo struct {
454
-	ID          string
455
-	Name        string
456
-	Version     string
457
-	Path        string
458
-	Size        int64
459
-	CreatedTime time.Time
460
-	OSVersion   string   `json:"-"`
461
-	OSFeatures  []string `json:"-"`
462
-}
463
-
464
-// GetCustomImageInfos returns the image infos for window specific
465
-// base images which should always be present.
466
-func (d *Driver) GetCustomImageInfos() ([]CustomImageInfo, error) {
467
-	strData, err := hcsshim.GetSharedBaseImages()
468
-	if err != nil {
469
-		return nil, fmt.Errorf("Failed to restore base images: %s", err)
470
-	}
471
-
472
-	type customImageInfoList struct {
473
-		Images []CustomImageInfo
474
-	}
475
-
476
-	var infoData customImageInfoList
477
-
478
-	if err = json.Unmarshal([]byte(strData), &infoData); err != nil {
479
-		err = fmt.Errorf("JSON unmarshal returned error=%s", err)
480
-		logrus.Error(err)
481
-		return nil, err
482
-	}
483
-
484
-	var images []CustomImageInfo
485
-
486
-	for _, imageData := range infoData.Images {
487
-		folderName := filepath.Base(imageData.Path)
488
-
489
-		// Use crypto hash of the foldername to generate a docker style id.
490
-		h := sha512.Sum384([]byte(folderName))
491
-		id := fmt.Sprintf("%x", h[:32])
492
-
493
-		if err := d.Create(id, "", "", nil); err != nil {
494
-			return nil, err
495
-		}
496
-		// Create the alternate ID file.
497
-		if err := d.setID(id, folderName); err != nil {
498
-			return nil, err
499
-		}
500
-
501
-		imageData.ID = id
502
-
503
-		// For now, hard code that all base images except nanoserver depend on win32k support
504
-		if imageData.Name != "NanoServer" {
505
-			imageData.OSFeatures = append(imageData.OSFeatures, "win32k")
506
-		}
507
-
508
-		versionData := strings.Split(imageData.Version, ".")
509
-		if len(versionData) != 4 {
510
-			logrus.Warnf("Could not parse Windows version %s", imageData.Version)
511
-		} else {
512
-			// Include just major.minor.build, skip the fourth version field, which does not influence
513
-			// OS compatibility.
514
-			imageData.OSVersion = strings.Join(versionData[:3], ".")
515
-		}
516
-
517
-		images = append(images, imageData)
518
-	}
519
-
520
-	return images, nil
521
-}
522
-
523 451
 // GetMetadata returns custom driver information.
524 452
 func (d *Driver) GetMetadata(id string) (map[string]string, error) {
525 453
 	m := make(map[string]string)