source: add sharedkeyhint to local source

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2017-12-13 21:01:01 -08:00
parent 08e1c2990c
commit 2d3f36d359
7 changed files with 28 additions and 9 deletions

View File

@@ -196,6 +196,9 @@ func Local(name string, opts ...LocalOption) State {
if gi.ExcludePatterns != "" {
attrs[pb.AttrExcludePatterns] = gi.ExcludePatterns
}
if gi.SharedKeyHint != "" {
attrs[pb.AttrSharedKeyHint] = gi.SharedKeyHint
}
source := NewSource("local://"+name, attrs, gi.Metadata())
return NewState(source.Output())
@@ -239,11 +242,18 @@ func ExcludePatterns(p []string) LocalOption {
})
}
func SharedKeyHint(h string) LocalOption {
return localOptionFunc(func(li *LocalInfo) {
li.SharedKeyHint = h
})
}
type LocalInfo struct {
opMetaWrapper
SessionID string
IncludePatterns string
ExcludePatterns string
SharedKeyHint string
}
func HTTP(url string, opts ...HTTPOption) State {

View File

@@ -1,5 +0,0 @@
package client
func getSharedKey(dir string) (string, error) {
return dir, nil // not implemented
}

View File

@@ -41,6 +41,7 @@ func Build(ctx context.Context, c client.Client) error {
src := llb.Local(LocalNameDockerfile,
llb.IncludePatterns([]string{filename}),
llb.SessionID(c.SessionID()),
llb.SharedKeyHint(defaultDockerfileName),
)
var buildContext *llb.State
if strings.HasPrefix(opts[LocalNameContext], gitPrefix) {
@@ -70,7 +71,11 @@ func Build(ctx context.Context, c client.Client) error {
eg.Go(func() error {
dockerignoreState := buildContext
if dockerignoreState == nil {
st := llb.Local(LocalNameContext, llb.SessionID(c.SessionID()), llb.IncludePatterns([]string{dockerignoreFilename}))
st := llb.Local(LocalNameContext,
llb.SessionID(c.SessionID()),
llb.IncludePatterns([]string{dockerignoreFilename}),
llb.SharedKeyHint(dockerignoreFilename),
)
dockerignoreState = &st
}
def, err := dockerignoreState.Marshal()

View File

@@ -167,7 +167,11 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
if err := eg.Wait(); err != nil {
return nil, nil, err
}
buildContext := llb.Local(localNameContext, llb.SessionID(opt.SessionID), llb.ExcludePatterns(opt.Excludes))
buildContext := llb.Local(localNameContext,
llb.SessionID(opt.SessionID),
llb.ExcludePatterns(opt.Excludes),
llb.SharedKeyHint(localNameContext),
)
if opt.BuildContext != nil {
buildContext = *opt.BuildContext
}

View File

@@ -4,6 +4,7 @@ const AttrKeepGitDir = "git.keepgitdir"
const AttrLocalSessionID = "local.session"
const AttrIncludePatterns = "local.includepattern"
const AttrExcludePatterns = "local.excludepatterns"
const AttrSharedKeyHint = "local.sharedkeyhint"
const AttrLLBDefinitionFilename = "llbbuild.filename"
const AttrHTTPChecksum = "http.checksum"

View File

@@ -86,6 +86,8 @@ func FromLLB(op *pb.Op_Source) (Identifier, error) {
return nil, err
}
id.ExcludePatterns = patterns
case pb.AttrSharedKeyHint:
id.SharedKeyHint = v
}
}
}
@@ -149,6 +151,7 @@ type LocalIdentifier struct {
SessionID string
IncludePatterns []string
ExcludePatterns []string
SharedKeyHint string
}
func NewLocalIdentifier(str string) (*LocalIdentifier, error) {

View File

@@ -79,7 +79,8 @@ func (ls *localSourceHandler) CacheKey(ctx context.Context) (string, error) {
dt, err := json.Marshal(struct {
SessionID string
IncludePatterns []string
}{SessionID: sessionID, IncludePatterns: ls.src.IncludePatterns})
ExcludePatterns []string
}{SessionID: sessionID, IncludePatterns: ls.src.IncludePatterns, ExcludePatterns: ls.src.ExcludePatterns})
if err != nil {
return "", err
}
@@ -101,7 +102,7 @@ func (ls *localSourceHandler) Snapshot(ctx context.Context) (out cache.Immutable
return nil, err
}
sharedKey := keySharedKey + ":" + ls.src.Name + ":" + caller.SharedKey()
sharedKey := keySharedKey + ":" + ls.src.Name + ":" + ls.src.SharedKeyHint + ":" + caller.SharedKey() // TODO: replace caller.SharedKey() with source based hint from client(absolute-path+nodeid)
var mutable cache.MutableRef
sis, err := ls.md.Search(sharedKey)