Browse code

daemon: access to distribution internals

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2018/04/18 03:56:28
Showing 4 changed files
... ...
@@ -922,6 +922,10 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
922 922
 	return d, nil
923 923
 }
924 924
 
925
+func (daemon *Daemon) DistributionServices() images.DistributionServices {
926
+	return daemon.imageService.DistributionServices()
927
+}
928
+
925 929
 func (daemon *Daemon) waitForStartupDone() {
926 930
 	<-daemon.startupDone
927 931
 }
... ...
@@ -3,9 +3,11 @@ package images // import "github.com/docker/docker/daemon/images"
3 3
 import (
4 4
 	"context"
5 5
 	"os"
6
+	"runtime"
6 7
 
7 8
 	"github.com/docker/docker/container"
8 9
 	daemonevents "github.com/docker/docker/daemon/events"
10
+	"github.com/docker/docker/distribution"
9 11
 	"github.com/docker/docker/distribution/metadata"
10 12
 	"github.com/docker/docker/distribution/xfer"
11 13
 	"github.com/docker/docker/image"
... ...
@@ -74,6 +76,24 @@ type ImageService struct {
74 74
 	uploadManager             *xfer.LayerUploadManager
75 75
 }
76 76
 
77
+type DistributionServices struct {
78
+	DownloadManager   distribution.RootFSDownloadManager
79
+	V2MetadataService metadata.V2MetadataService
80
+	LayerStore        layer.Store // TODO: lcow
81
+	ImageStore        image.Store
82
+	ReferenceStore    dockerreference.Store
83
+}
84
+
85
+func (i *ImageService) DistributionServices() DistributionServices {
86
+	return DistributionServices{
87
+		DownloadManager:   i.downloadManager,
88
+		V2MetadataService: metadata.NewV2MetadataService(i.distributionMetadataStore),
89
+		LayerStore:        i.layerStores[runtime.GOOS],
90
+		ImageStore:        i.imageStore,
91
+		ReferenceStore:    i.referenceStore,
92
+	}
93
+}
94
+
77 95
 // CountImages returns the number of images stored by ImageService
78 96
 // called from info.go
79 97
 func (i *ImageService) CountImages() int {
... ...
@@ -121,6 +121,10 @@ func newStoreFromGraphDriver(root string, driver graphdriver.Driver, os string)
121 121
 	return ls, nil
122 122
 }
123 123
 
124
+func (ls *layerStore) Driver() graphdriver.Driver {
125
+	return ls.driver
126
+}
127
+
124 128
 func (ls *layerStore) loadLayer(layer ChainID) (*roLayer, error) {
125 129
 	cl, ok := ls.layerMap[layer]
126 130
 	if ok {
... ...
@@ -54,6 +54,10 @@ func (rl *roLayer) TarStreamFrom(parent ChainID) (io.ReadCloser, error) {
54 54
 	return rl.layerStore.driver.Diff(rl.cacheID, parentCacheID)
55 55
 }
56 56
 
57
+func (rl *roLayer) CacheID() string {
58
+	return rl.cacheID
59
+}
60
+
57 61
 func (rl *roLayer) ChainID() ChainID {
58 62
 	return rl.chainID
59 63
 }