dockerfile: add cache-from support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
11ada4c27b
commit
966d3f7b32
|
@ -20,6 +20,7 @@ const (
|
|||
LocalNameDockerfile = "dockerfile"
|
||||
keyTarget = "target"
|
||||
keyFilename = "filename"
|
||||
keyCacheFrom = "cache-from"
|
||||
exporterImageConfig = "containerimage.config"
|
||||
defaultDockerfileName = "Dockerfile"
|
||||
dockerignoreFilename = ".dockerignore"
|
||||
|
@ -57,7 +58,7 @@ func Build(ctx context.Context, c client.Client) error {
|
|||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
var dtDockerfile []byte
|
||||
eg.Go(func() error {
|
||||
ref, err := c.Solve(ctx2, def.ToPB(), "", "", nil, false)
|
||||
ref, err := c.Solve(ctx2, def.ToPB(), "", nil, nil, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ func Build(ctx context.Context, c client.Client) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ref, err := c.Solve(ctx2, def.ToPB(), "", "", nil, false)
|
||||
ref, err := c.Solve(ctx2, def.ToPB(), "", nil, nil, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -125,7 +126,12 @@ func Build(ctx context.Context, c client.Client) error {
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = c.Solve(ctx, def.ToPB(), "", opts["cache-from"], map[string][]byte{
|
||||
var cacheFrom []string
|
||||
if cacheFromStr := opts[keyCacheFrom]; cacheFromStr != "" {
|
||||
cacheFrom = strings.Split(cacheFromStr, ",")
|
||||
}
|
||||
|
||||
_, err = c.Solve(ctx, def.ToPB(), "", cacheFrom, map[string][]byte{
|
||||
exporterImageConfig: config,
|
||||
}, true)
|
||||
if err != nil {
|
||||
|
|
|
@ -26,11 +26,11 @@ type bridgeClient struct {
|
|||
refs []*ref
|
||||
}
|
||||
|
||||
func (c *bridgeClient) Solve(ctx context.Context, def *pb.Definition, f string, importRef string, exporterAttr map[string][]byte, final bool) (client.Reference, error) {
|
||||
func (c *bridgeClient) Solve(ctx context.Context, def *pb.Definition, f string, cacheImportRefs []string, exporterAttr map[string][]byte, final bool) (client.Reference, error) {
|
||||
r, exporterAttrRes, err := c.FrontendLLBBridge.Solve(ctx, frontend.SolveRequest{
|
||||
Definition: def,
|
||||
Frontend: f,
|
||||
ImportCacheRef: importRef,
|
||||
Definition: def,
|
||||
Frontend: f,
|
||||
ImportCacheRefs: cacheImportRefs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
// TODO: make this take same options as LLBBridge. Add Return()
|
||||
type Client interface {
|
||||
Solve(ctx context.Context, def *pb.Definition, frontend string, importRef string, exporterAttr map[string][]byte, final bool) (Reference, error)
|
||||
Solve(ctx context.Context, def *pb.Definition, frontend string, cacheImportRefs []string, exporterAttr map[string][]byte, final bool) (Reference, error)
|
||||
ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error)
|
||||
Opts() map[string]string
|
||||
SessionID() string
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/moby/buildkit/cache"
|
||||
"github.com/moby/buildkit/cache/cacheimport"
|
||||
"github.com/moby/buildkit/executor"
|
||||
|
@ -32,16 +33,23 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (res s
|
|||
b.cmsMu.Lock()
|
||||
var cm solver.CacheManager
|
||||
if prevCm, ok := b.cms[ref]; !ok {
|
||||
cm = newLazyCacheManager(ref, func() (solver.CacheManager, error) {
|
||||
var cmNew solver.CacheManager
|
||||
if err := b.builder.Call(ctx, "importing cache manifest from "+ref, func(ctx context.Context) error {
|
||||
cmNew, err = b.ci.Resolve(ctx, ref)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cmNew, nil
|
||||
})
|
||||
r, err := reference.ParseNormalizedNamed(ref)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
ref = reference.TagNameOnly(r).String()
|
||||
func(ref string) {
|
||||
cm = newLazyCacheManager(ref, func() (solver.CacheManager, error) {
|
||||
var cmNew solver.CacheManager
|
||||
if err := b.builder.Call(ctx, "importing cache manifest from "+ref, func(ctx context.Context) error {
|
||||
cmNew, err = b.ci.Resolve(ctx, ref)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cmNew, nil
|
||||
})
|
||||
}(ref)
|
||||
b.cms[ref] = cm
|
||||
} else {
|
||||
cm = prevCm
|
||||
|
|
Loading…
Reference in New Issue