Skip to content

Commit

Permalink
dockerfile: set current platform on image based named context
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Dec 16, 2021
1 parent 20285bb commit 23709ef
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions frontend/dockerfile/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,19 +814,19 @@ func contextByNameFunc(c client.Client, p *ocispecs.Platform) func(context.Conte

if p != nil {
name := name + "::" + platforms.Format(platforms.Normalize(*p))
st, img, err := contextByName(ctx, c, name)
st, img, err := contextByName(ctx, c, name, p)
if err != nil {
return nil, nil, err
}
if st != nil {
return st, img, nil
}
}
return contextByName(ctx, c, name)
return contextByName(ctx, c, name, p)
}
}

func contextByName(ctx context.Context, c client.Client, name string) (*llb.State, *dockerfile2llb.Image, error) {
func contextByName(ctx context.Context, c client.Client, name string, platform *ocispecs.Platform) (*llb.State, *dockerfile2llb.Image, error) {
opts := c.BuildOpts().Opts
v, ok := opts["context:"+name]
if !ok {
Expand All @@ -839,7 +839,14 @@ func contextByName(ctx context.Context, c client.Client, name string) (*llb.Stat
}
switch vv[0] {
case "docker-image":
st := llb.Image(strings.TrimPrefix(vv[1], "//"), llb.WithCustomName("[context "+name+"] "+vv[1]), llb.WithMetaResolver(c))
imgOpt := []llb.ImageOption{
llb.WithCustomName("[context " + name + "] " + vv[1]),
llb.WithMetaResolver(c),
}
if platform != nil {
imgOpt = append(imgOpt, llb.Platform(*platform))
}
st := llb.Image(strings.TrimPrefix(vv[1], "//"), imgOpt...)
return &st, nil, nil
case "git":
st, ok := detectGitContext(v, "1")
Expand Down

0 comments on commit 23709ef

Please sign in to comment.