mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #16709 from MHBauer/daemon-derepo2
continue daemon refactor of Repositories()
This commit is contained in:
commit
7787d6dc28
5 changed files with 20 additions and 18 deletions
|
@ -425,7 +425,7 @@ func (s *router) postBuild(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoName != "" {
|
if repoName != "" {
|
||||||
if err := s.daemon.Repositories().Tag(repoName, tag, string(imgID), true); err != nil {
|
if err := s.daemon.TagImage(repoName, tag, string(imgID), true); err != nil {
|
||||||
return errf(err)
|
return errf(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1011,11 +1011,6 @@ func (daemon *Daemon) Graph() *graph.Graph {
|
||||||
return daemon.graph
|
return daemon.graph
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repositories returns all repositories.
|
|
||||||
func (daemon *Daemon) Repositories() *graph.TagStore {
|
|
||||||
return daemon.repositories
|
|
||||||
}
|
|
||||||
|
|
||||||
// TagImage creates a tag in the repository reponame, pointing to the image named
|
// TagImage creates a tag in the repository reponame, pointing to the image named
|
||||||
// imageName. If force is true, an existing tag with the same name may be
|
// imageName. If force is true, an existing tag with the same name may be
|
||||||
// overwritten.
|
// overwritten.
|
||||||
|
@ -1079,6 +1074,13 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) {
|
||||||
return daemon.repositories.History(name)
|
return daemon.repositories.History(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetImage returns pointer to an Image struct corresponding to the given
|
||||||
|
// name. The name can include an optional tag; otherwise the default tag will
|
||||||
|
// be used.
|
||||||
|
func (daemon *Daemon) GetImage(name string) (*image.Image, error) {
|
||||||
|
return daemon.repositories.LookupImage(name)
|
||||||
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) config() *Config {
|
func (daemon *Daemon) config() *Config {
|
||||||
return daemon.configStore
|
return daemon.configStore
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ var _ builder.Docker = Docker{}
|
||||||
|
|
||||||
// LookupImage looks up a Docker image referenced by `name`.
|
// LookupImage looks up a Docker image referenced by `name`.
|
||||||
func (d Docker) LookupImage(name string) (*image.Image, error) {
|
func (d Docker) LookupImage(name string) (*image.Image, error) {
|
||||||
return d.Daemon.Repositories().LookupImage(name)
|
return d.Daemon.GetImage(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull tells Docker to pull image referenced by `name`.
|
// Pull tells Docker to pull image referenced by `name`.
|
||||||
|
@ -69,11 +69,11 @@ func (d Docker) Pull(name string) (*image.Image, error) {
|
||||||
OutStream: ioutils.NopWriteCloser(d.OutOld),
|
OutStream: ioutils.NopWriteCloser(d.OutOld),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.Daemon.Repositories().Pull(remote, tag, imagePullConfig); err != nil {
|
if err := d.Daemon.PullImage(remote, tag, imagePullConfig); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return d.Daemon.Repositories().LookupImage(name)
|
return d.Daemon.GetImage(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container looks up a Docker container referenced by `id`.
|
// Container looks up a Docker container referenced by `id`.
|
||||||
|
|
|
@ -53,7 +53,7 @@ import (
|
||||||
func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) {
|
func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) {
|
||||||
records := []types.ImageDelete{}
|
records := []types.ImageDelete{}
|
||||||
|
|
||||||
img, err := daemon.Repositories().LookupImage(imageRef)
|
img, err := daemon.repositories.LookupImage(imageRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
|
||||||
// repository reference to the image then we will want to
|
// repository reference to the image then we will want to
|
||||||
// remove that reference.
|
// remove that reference.
|
||||||
// FIXME: Is this the behavior we want?
|
// FIXME: Is this the behavior we want?
|
||||||
repoRefs := daemon.Repositories().ByID()[img.ID]
|
repoRefs := daemon.repositories.ByID()[img.ID]
|
||||||
if len(repoRefs) == 1 {
|
if len(repoRefs) == 1 {
|
||||||
parsedRef, err := daemon.removeImageRef(repoRefs[0])
|
parsedRef, err := daemon.removeImageRef(repoRefs[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -116,7 +116,7 @@ func isImageIDPrefix(imageID, possiblePrefix string) bool {
|
||||||
// imageHasMultipleRepositoryReferences returns whether there are multiple
|
// imageHasMultipleRepositoryReferences returns whether there are multiple
|
||||||
// repository references to the given imageID.
|
// repository references to the given imageID.
|
||||||
func (daemon *Daemon) imageHasMultipleRepositoryReferences(imageID string) bool {
|
func (daemon *Daemon) imageHasMultipleRepositoryReferences(imageID string) bool {
|
||||||
return len(daemon.Repositories().ByID()[imageID]) > 1
|
return len(daemon.repositories.ByID()[imageID]) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// getContainerUsingImage returns a container that was created using the given
|
// getContainerUsingImage returns a container that was created using the given
|
||||||
|
@ -145,7 +145,7 @@ func (daemon *Daemon) removeImageRef(repositoryRef string) (string, error) {
|
||||||
// Ignore the boolean value returned, as far as we're concerned, this
|
// Ignore the boolean value returned, as far as we're concerned, this
|
||||||
// is an idempotent operation and it's okay if the reference didn't
|
// is an idempotent operation and it's okay if the reference didn't
|
||||||
// exist in the first place.
|
// exist in the first place.
|
||||||
_, err := daemon.Repositories().Delete(repository, ref)
|
_, err := daemon.repositories.Delete(repository, ref)
|
||||||
|
|
||||||
return utils.ImageReference(repository, ref), err
|
return utils.ImageReference(repository, ref), err
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func (daemon *Daemon) removeImageRef(repositoryRef string) (string, error) {
|
||||||
// daemon's event service. An "Untagged" types.ImageDelete is added to the
|
// daemon's event service. An "Untagged" types.ImageDelete is added to the
|
||||||
// given list of records.
|
// given list of records.
|
||||||
func (daemon *Daemon) removeAllReferencesToImageID(imgID string, records *[]types.ImageDelete) error {
|
func (daemon *Daemon) removeAllReferencesToImageID(imgID string, records *[]types.ImageDelete) error {
|
||||||
imageRefs := daemon.Repositories().ByID()[imgID]
|
imageRefs := daemon.repositories.ByID()[imgID]
|
||||||
|
|
||||||
for _, imageRef := range imageRefs {
|
for _, imageRef := range imageRefs {
|
||||||
parsedRef, err := daemon.removeImageRef(imageRef)
|
parsedRef, err := daemon.removeImageRef(imageRef)
|
||||||
|
@ -308,7 +308,7 @@ func (daemon *Daemon) checkImageDeleteHardConflict(img *image.Image) *imageDelet
|
||||||
|
|
||||||
func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDeleteConflict {
|
func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDeleteConflict {
|
||||||
// Check if any repository tags/digest reference this image.
|
// Check if any repository tags/digest reference this image.
|
||||||
if daemon.Repositories().HasReferences(img) {
|
if daemon.repositories.HasReferences(img) {
|
||||||
return &imageDeleteConflict{
|
return &imageDeleteConflict{
|
||||||
imgID: img.ID,
|
imgID: img.ID,
|
||||||
message: "image is referenced in one or more repositories",
|
message: "image is referenced in one or more repositories",
|
||||||
|
@ -337,5 +337,5 @@ func (daemon *Daemon) checkImageDeleteSoftConflict(img *image.Image) *imageDelet
|
||||||
// that there are no repository references to the given image and it has no
|
// that there are no repository references to the given image and it has no
|
||||||
// child images.
|
// child images.
|
||||||
func (daemon *Daemon) imageIsDangling(img *image.Image) bool {
|
func (daemon *Daemon) imageIsDangling(img *image.Image) bool {
|
||||||
return !(daemon.Repositories().HasReferences(img) || daemon.Graph().HasChildren(img))
|
return !(daemon.repositories.HasReferences(img) || daemon.Graph().HasChildren(img))
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (daemon *Daemon) foldFilter(config *ContainersConfig) (*listContext, error)
|
||||||
// The idea is to walk the graph down the most "efficient" way.
|
// The idea is to walk the graph down the most "efficient" way.
|
||||||
for _, ancestor := range ancestors {
|
for _, ancestor := range ancestors {
|
||||||
// First, get the imageId of the ancestor filter (yay)
|
// First, get the imageId of the ancestor filter (yay)
|
||||||
image, err := daemon.Repositories().LookupImage(ancestor)
|
image, err := daemon.repositories.LookupImage(ancestor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Warnf("Error while looking up for image %v", ancestor)
|
logrus.Warnf("Error while looking up for image %v", ancestor)
|
||||||
continue
|
continue
|
||||||
|
@ -297,7 +297,7 @@ func (daemon *Daemon) transformContainer(container *Container, ctx *listContext)
|
||||||
newC.Names = []string{}
|
newC.Names = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
img, err := daemon.Repositories().LookupImage(container.Config.Image)
|
img, err := daemon.repositories.LookupImage(container.Config.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the image can no longer be found by its original reference,
|
// If the image can no longer be found by its original reference,
|
||||||
// it makes sense to show the ID instead of a stale reference.
|
// it makes sense to show the ID instead of a stale reference.
|
||||||
|
|
Loading…
Add table
Reference in a new issue