mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
split GetRepository from ImageService
The GetRepository method interacts directly with the registry, and does
not depend on the snapshotter, but is used for two purposes;
For the GET /distribution/{name:.*}/json route;
dd3b71d17c/api/server/router/distribution/backend.go (L11-L15)
And to satisfy the "executor.ImageBackend" interface as used by Swarm;
58c027ac8b/daemon/cluster/executor/backend.go (L77)
This patch removes the method from the ImageService interface, and instead
implements it through an composite struct that satisfies both interfaces,
and an ImageBackend() method is added to the daemon.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
remove GetRepository from ImageService
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -522,7 +522,7 @@ func initRouter(opts routerOptions) {
|
||||
sessionrouter.NewRouter(opts.sessionManager),
|
||||
swarmrouter.NewRouter(opts.cluster),
|
||||
pluginrouter.NewRouter(opts.daemon.PluginManager()),
|
||||
distributionrouter.NewRouter(opts.daemon.ImageService()),
|
||||
distributionrouter.NewRouter(opts.daemon.ImageBackend()),
|
||||
}
|
||||
|
||||
if opts.buildBackend != nil {
|
||||
@@ -729,7 +729,7 @@ func createAndStartCluster(cli *DaemonCli, d *daemon.Daemon) (*cluster.Cluster,
|
||||
Name: name,
|
||||
Backend: d,
|
||||
VolumeBackend: d.VolumesService(),
|
||||
ImageBackend: d.ImageService(),
|
||||
ImageBackend: d.ImageBackend(),
|
||||
PluginBackend: d.PluginManager(),
|
||||
NetworkSubnetsProvider: d,
|
||||
DefaultAdvertiseAddr: cli.Config.SwarmDefaultAdvertiseAddr,
|
||||
|
||||
@@ -2,14 +2,12 @@ package containerd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/pkg/snapshotters"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/errdefs"
|
||||
@@ -73,8 +71,3 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
|
||||
_, err = i.client.Pull(ctx, ref.String(), opts...)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetRepository returns a repository from the registry.
|
||||
func (i *ImageService) GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error) {
|
||||
return nil, errdefs.NotImplemented(errors.New("not implemented"))
|
||||
}
|
||||
|
||||
@@ -23,12 +23,16 @@ import (
|
||||
"github.com/containerd/containerd/pkg/dialer"
|
||||
"github.com/containerd/containerd/pkg/userns"
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
dist "github.com/docker/distribution"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
registrytypes "github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/container"
|
||||
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
||||
"github.com/docker/docker/daemon/config"
|
||||
ctrd "github.com/docker/docker/daemon/containerd"
|
||||
"github.com/docker/docker/daemon/events"
|
||||
@@ -37,6 +41,7 @@ import (
|
||||
dlogger "github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/daemon/stats"
|
||||
"github.com/docker/docker/distribution"
|
||||
dmetadata "github.com/docker/docker/distribution/metadata"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/errdefs"
|
||||
@@ -1466,6 +1471,14 @@ func (daemon *Daemon) ImageService() ImageService {
|
||||
return daemon.imageService
|
||||
}
|
||||
|
||||
// ImageBackend returns an image-backend for Swarm and the distribution router.
|
||||
func (daemon *Daemon) ImageBackend() executorpkg.ImageBackend {
|
||||
return &imageBackend{
|
||||
ImageService: daemon.imageService,
|
||||
registryService: daemon.registryService,
|
||||
}
|
||||
}
|
||||
|
||||
// RegistryService returns the Daemon's RegistryService
|
||||
func (daemon *Daemon) RegistryService() *registry.Service {
|
||||
return daemon.registryService
|
||||
@@ -1491,3 +1504,21 @@ func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo {
|
||||
|
||||
return daemon.sysInfo
|
||||
}
|
||||
|
||||
// imageBackend is used to satisfy the [executorpkg.ImageBackend] and
|
||||
// [github.com/docker/docker/api/server/router/distribution.Backend]
|
||||
// interfaces.
|
||||
type imageBackend struct {
|
||||
ImageService
|
||||
registryService *registry.Service
|
||||
}
|
||||
|
||||
// GetRepository returns a repository from the registry.
|
||||
func (i *imageBackend) GetRepository(ctx context.Context, ref reference.Named, authConfig *registrytypes.AuthConfig) (dist.Repository, error) {
|
||||
return distribution.GetRepository(ctx, ref, &distribution.ImagePullConfig{
|
||||
Config: distribution.Config{
|
||||
AuthConfig: authConfig,
|
||||
RegistryService: i.registryService,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
@@ -73,7 +72,6 @@ type ImageService interface {
|
||||
|
||||
// Other
|
||||
|
||||
GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error)
|
||||
DistributionServices() images.DistributionServices
|
||||
Children(id image.ID) []image.ID
|
||||
Cleanup() error
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/leases"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
dist "github.com/docker/distribution"
|
||||
"github.com/docker/distribution/reference"
|
||||
imagetypes "github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
@@ -134,16 +133,6 @@ func (i *ImageService) pullImageWithReference(ctx context.Context, ref reference
|
||||
return err
|
||||
}
|
||||
|
||||
// GetRepository returns a repository from the registry.
|
||||
func (i *ImageService) GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (dist.Repository, error) {
|
||||
return distribution.GetRepository(ctx, ref, &distribution.ImagePullConfig{
|
||||
Config: distribution.Config{
|
||||
AuthConfig: authConfig,
|
||||
RegistryService: i.registryService,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func tempLease(ctx context.Context, mgr leases.Manager) (context.Context, func(context.Context) error, error) {
|
||||
nop := func(context.Context) error { return nil }
|
||||
_, ok := leases.FromContext(ctx)
|
||||
|
||||
Reference in New Issue
Block a user