Skip to content

Commit

Permalink
split GetRepository from ImageService
Browse files Browse the repository at this point in the history
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;
https://github.com/moby/moby/blob/dd3b71d17c614f837c4bba18baed9fa2cb31f1a4/api/server/router/distribution/backend.go#L11-L15

And to satisfy the "executor.ImageBackend" interface as used by Swarm;
https://github.com/moby/moby/blob/58c027ac8ba19a3fa339c65274ea6704ccbec977/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>
  • Loading branch information
thaJeztah committed Apr 9, 2023
1 parent dd3b71d commit a5d46a1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions daemon/containerd/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
}
31 changes: 31 additions & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
})
}
2 changes: 0 additions & 2 deletions daemon/image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions daemon/images/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a5d46a1

Please sign in to comment.