daemon/imageStore: Mark images built locally
Store additional image property which makes it possible to distinguish
if image was built locally.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit c6156dc51b
)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
6d05b9b65b
commit
be7b60ef05
3 changed files with 26 additions and 0 deletions
|
@ -255,6 +255,9 @@ func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent st
|
|||
return nil, errors.Wrapf(err, "failed to set parent %s", parent)
|
||||
}
|
||||
}
|
||||
if err := i.imageStore.SetBuiltLocally(id); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to mark image %s as built locally", id)
|
||||
}
|
||||
|
||||
return i.imageStore.Get(id)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,9 @@ func (i *ImageService) CommitImage(ctx context.Context, c backend.CommitConfig)
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := i.imageStore.SetBuiltLocally(id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if c.ParentImageID != "" {
|
||||
if err := i.imageStore.SetParent(id, image.ID(c.ParentImageID)); err != nil {
|
||||
|
|
|
@ -3,6 +3,7 @@ package image // import "github.com/docker/docker/image"
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -24,6 +25,8 @@ type Store interface {
|
|||
GetParent(id ID) (ID, error)
|
||||
SetLastUpdated(id ID) error
|
||||
GetLastUpdated(id ID) (time.Time, error)
|
||||
SetBuiltLocally(id ID) error
|
||||
IsBuiltLocally(id ID) (bool, error)
|
||||
Children(id ID) []ID
|
||||
Map() map[ID]*Image
|
||||
Heads() map[ID]*Image
|
||||
|
@ -295,6 +298,23 @@ func (is *store) GetLastUpdated(id ID) (time.Time, error) {
|
|||
return time.Parse(time.RFC3339Nano, string(bytes))
|
||||
}
|
||||
|
||||
// SetBuiltLocally sets whether image can be used as a builder cache
|
||||
func (is *store) SetBuiltLocally(id ID) error {
|
||||
return is.fs.SetMetadata(id.Digest(), "builtLocally", []byte{1})
|
||||
}
|
||||
|
||||
// IsBuiltLocally returns whether image can be used as a builder cache
|
||||
func (is *store) IsBuiltLocally(id ID) (bool, error) {
|
||||
bytes, err := is.fs.GetMetadata(id.Digest(), "builtLocally")
|
||||
if err != nil || len(bytes) == 0 {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return bytes[0] == 1, nil
|
||||
}
|
||||
|
||||
func (is *store) Children(id ID) []ID {
|
||||
is.RLock()
|
||||
defer is.RUnlock()
|
||||
|
|
Loading…
Reference in a new issue