mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 18:08:51 +08:00 
			
		
		
		
	 0f7d54b026
			
		
	
	0f7d54b026
	
	
	
		
			
			Migrate the Podman code base over to `common/libimage` which replaces `libpod/image` and a lot of glue code entirely. Note that I tried to leave bread crumbs for changed tests. Miscellaneous changes: * Some errors yield different messages which required to alter some tests. * I fixed some pre-existing issues in the code. Others were marked as `//TODO`s to prevent the PR from exploding. * The `NamesHistory` of an image is returned as is from the storage. Previously, we did some filtering which I think is undesirable. Instead we should return the data as stored in the storage. * Touched handlers use the ABI interfaces where possible. * Local image resolution: previously Podman would match "foo" on "myfoo". This behaviour has been changed and Podman will now only match on repository boundaries such that "foo" would match "my/foo" but not "myfoo". I consider the old behaviour to be a bug, at the very least an exotic corner case. * Futhermore, "foo:none" does *not* resolve to a local image "foo" without tag anymore. It's a hill I am (almost) willing to die on. * `image prune` prints the IDs of pruned images. Previously, in some cases, the names were printed instead. The API clearly states ID, so we should stick to it. * Compat endpoint image removal with _force_ deletes the entire not only the specified tag. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package libimage
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/containers/storage"
 | |
| )
 | |
| 
 | |
| // ImageHistory contains the history information of an image.
 | |
| type ImageHistory struct {
 | |
| 	ID        string     `json:"id"`
 | |
| 	Created   *time.Time `json:"created"`
 | |
| 	CreatedBy string     `json:"createdBy"`
 | |
| 	Size      int64      `json:"size"`
 | |
| 	Comment   string     `json:"comment"`
 | |
| 	Tags      []string   `json:"tags"`
 | |
| }
 | |
| 
 | |
| // History computes the image history of the image including all of its parents.
 | |
| func (i *Image) History(ctx context.Context) ([]ImageHistory, error) {
 | |
| 	ociImage, err := i.toOCI(ctx)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	layerTree, err := i.runtime.layerTree()
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	var allHistory []ImageHistory
 | |
| 	var layer *storage.Layer
 | |
| 	if i.TopLayer() != "" {
 | |
| 		layer, err = i.runtime.store.Layer(i.TopLayer())
 | |
| 		if err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	// Iterate in reverse order over the history entries, and lookup the
 | |
| 	// corresponding image ID, size and get the next later if needed.
 | |
| 	numHistories := len(ociImage.History) - 1
 | |
| 	usedIDs := make(map[string]bool) // prevents assigning images IDs more than once
 | |
| 	for x := numHistories; x >= 0; x-- {
 | |
| 		history := ImageHistory{
 | |
| 			ID:        "<missing>", // may be overridden below
 | |
| 			Created:   ociImage.History[x].Created,
 | |
| 			CreatedBy: ociImage.History[x].CreatedBy,
 | |
| 			Comment:   ociImage.History[x].Comment,
 | |
| 		}
 | |
| 
 | |
| 		if layer != nil {
 | |
| 			history.Tags = layer.Names
 | |
| 			if !ociImage.History[x].EmptyLayer {
 | |
| 				history.Size = layer.UncompressedSize
 | |
| 			}
 | |
| 			// Query the layer tree if it's the top layer of an
 | |
| 			// image.
 | |
| 			node := layerTree.node(layer.ID)
 | |
| 			if len(node.images) > 0 {
 | |
| 				id := node.images[0].ID() // always use the first one
 | |
| 				if _, used := usedIDs[id]; !used {
 | |
| 					history.ID = id
 | |
| 					usedIDs[id] = true
 | |
| 				}
 | |
| 			}
 | |
| 			if layer.Parent != "" && !ociImage.History[x].EmptyLayer {
 | |
| 				layer, err = i.runtime.store.Layer(layer.Parent)
 | |
| 				if err != nil {
 | |
| 					return nil, err
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		allHistory = append(allHistory, history)
 | |
| 	}
 | |
| 
 | |
| 	return allHistory, nil
 | |
| }
 |