Skip to content

Commit cd90732

Browse files
committed
dockerui: allow passing sessionID for specific local source
This allows frontend to associate a specific local to specific session when it is assembling LLB. It can be used to create builds using files from multiple sessions or multiple builds to use the same session that is different from default session for the build request. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 5a91bd3 commit cd90732

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

frontend/dockerui/attr.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ func parseSourceDateEpoch(v string) (*time.Time, error) {
125125
return &tm, nil
126126
}
127127

128+
func parseLocalSessionIDs(opt map[string]string) map[string]string {
129+
m := map[string]string{}
130+
for k, v := range opt {
131+
if strings.HasPrefix(k, localSessionIDPrefix) {
132+
m[strings.TrimPrefix(k, localSessionIDPrefix)] = v
133+
}
134+
}
135+
return m
136+
}
137+
128138
func filter(opt map[string]string, key string) map[string]string {
129139
m := map[string]string{}
130140
for k, v := range opt {

frontend/dockerui/config.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import (
2626
)
2727

2828
const (
29-
buildArgPrefix = "build-arg:"
30-
labelPrefix = "label:"
29+
buildArgPrefix = "build-arg:"
30+
labelPrefix = "label:"
31+
localSessionIDPrefix = "local-sessionid:"
3132

3233
keyTarget = "target"
3334
keyCgroupParent = "cgroup-parent"
@@ -79,10 +80,11 @@ type Config struct {
7980

8081
type Client struct {
8182
Config
82-
client client.Client
83-
ignoreCache []string
84-
g flightcontrol.CachedGroup[*buildContext]
85-
bopts client.BuildOpts
83+
client client.Client
84+
ignoreCache []string
85+
g flightcontrol.CachedGroup[*buildContext]
86+
bopts client.BuildOpts
87+
localsSessionIDs map[string]string
8688

8789
dockerignore []byte
8890
dockerignoreName string
@@ -298,6 +300,9 @@ func (bc *Client) init() error {
298300
return errors.Wrapf(err, "failed to parse %s", keyCopyIgnoredCheckEnabled)
299301
}
300302
}
303+
304+
bc.localsSessionIDs = parseLocalSessionIDs(opts)
305+
301306
return nil
302307
}
303308

@@ -331,9 +336,14 @@ func (bc *Client) ReadEntrypoint(ctx context.Context, lang string, opts ...llb.L
331336
filenames = append(filenames, path.Join(path.Dir(bctx.filename), strings.ToLower(DefaultDockerfileName)))
332337
}
333338

339+
sessionID := bc.bopts.SessionID
340+
if v, ok := bc.localsSessionIDs[bctx.dockerfileLocalName]; ok {
341+
sessionID = v
342+
}
343+
334344
opts = append([]llb.LocalOption{
335345
llb.FollowPaths(filenames),
336-
llb.SessionID(bc.bopts.SessionID),
346+
llb.SessionID(sessionID),
337347
llb.SharedKeyHint(bctx.dockerfileLocalName),
338348
WithInternalName(name),
339349
llb.Differ(llb.DiffNone, false),
@@ -427,8 +437,13 @@ func (bc *Client) MainContext(ctx context.Context, opts ...llb.LocalOption) (*ll
427437
return nil, errors.Wrapf(err, "failed to read dockerignore patterns")
428438
}
429439

440+
sessionID := bc.bopts.SessionID
441+
if v, ok := bc.localsSessionIDs[bctx.contextLocalName]; ok {
442+
sessionID = v
443+
}
444+
430445
opts = append([]llb.LocalOption{
431-
llb.SessionID(bc.bopts.SessionID),
446+
llb.SessionID(sessionID),
432447
llb.ExcludePatterns(excludes),
433448
llb.SharedKeyHint(bctx.contextLocalName),
434449
WithInternalName("load build context"),
@@ -500,8 +515,12 @@ func WithInternalName(name string) llb.ConstraintsOpt {
500515

501516
func (bc *Client) dockerIgnorePatterns(ctx context.Context, bctx *buildContext) ([]string, error) {
502517
if bc.dockerignore == nil {
518+
sessionID := bc.bopts.SessionID
519+
if v, ok := bc.localsSessionIDs[bctx.contextLocalName]; ok {
520+
sessionID = v
521+
}
503522
st := llb.Local(bctx.contextLocalName,
504-
llb.SessionID(bc.bopts.SessionID),
523+
llb.SessionID(sessionID),
505524
llb.FollowPaths([]string{DefaultDockerignoreName}),
506525
llb.SharedKeyHint(bctx.contextLocalName+"-"+DefaultDockerignoreName),
507526
WithInternalName("load "+DefaultDockerignoreName),

frontend/dockerui/namedcontext.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
187187
}
188188
return &st, &img, nil
189189
case "local":
190+
sessionID := bc.bopts.SessionID
191+
if v, ok := bc.localsSessionIDs[vv[1]]; ok {
192+
sessionID = v
193+
}
190194
st := llb.Local(vv[1],
191-
llb.SessionID(bc.bopts.SessionID),
195+
llb.SessionID(sessionID),
192196
llb.FollowPaths([]string{DefaultDockerignoreName}),
193197
llb.SharedKeyHint("context:"+nameWithPlatform+"-"+DefaultDockerignoreName),
194198
llb.WithCustomName("[context "+nameWithPlatform+"] load "+DefaultDockerignoreName),
@@ -226,7 +230,7 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
226230
localOutput := &asyncLocalOutput{
227231
name: vv[1],
228232
nameWithPlatform: nameWithPlatform,
229-
sessionID: bc.bopts.SessionID,
233+
sessionID: sessionID,
230234
excludes: excludes,
231235
extraOpts: opt.AsyncLocalOpts,
232236
}

0 commit comments

Comments
 (0)