|
@@ -70,16 +70,19 @@ type ConvertOpt struct {
|
|
SourceMap *llb.SourceMap
|
|
SourceMap *llb.SourceMap
|
|
Hostname string
|
|
Hostname string
|
|
Warn func(short, url string, detail [][]byte, location *parser.Range)
|
|
Warn func(short, url string, detail [][]byte, location *parser.Range)
|
|
- ContextByName func(ctx context.Context, name, resolveMode string) (*llb.State, *Image, *binfotypes.BuildInfo, error)
|
|
|
|
|
|
+ ContextByName func(ctx context.Context, name, resolveMode string, p *ocispecs.Platform) (*llb.State, *Image, *binfotypes.BuildInfo, error)
|
|
}
|
|
}
|
|
|
|
|
|
func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
|
|
func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
|
|
buildInfo := &binfotypes.BuildInfo{}
|
|
buildInfo := &binfotypes.BuildInfo{}
|
|
contextByName := opt.ContextByName
|
|
contextByName := opt.ContextByName
|
|
- opt.ContextByName = func(ctx context.Context, name, resolveMode string) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
|
|
|
|
|
|
+ opt.ContextByName = func(ctx context.Context, name, resolveMode string, p *ocispecs.Platform) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
|
|
if !strings.EqualFold(name, "scratch") && !strings.EqualFold(name, "context") {
|
|
if !strings.EqualFold(name, "scratch") && !strings.EqualFold(name, "context") {
|
|
if contextByName != nil {
|
|
if contextByName != nil {
|
|
- st, img, bi, err := contextByName(ctx, name, resolveMode)
|
|
|
|
|
|
+ if p == nil {
|
|
|
|
+ p = opt.TargetPlatform
|
|
|
|
+ }
|
|
|
|
+ st, img, bi, err := contextByName(ctx, name, resolveMode, p)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
return nil, nil, nil, err
|
|
}
|
|
}
|
|
@@ -165,8 +168,21 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
|
|
prefixPlatform: opt.PrefixPlatform,
|
|
prefixPlatform: opt.PrefixPlatform,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if v := st.Platform; v != "" {
|
|
|
|
+ v, err := shlex.ProcessWordWithMap(v, metaArgsToMap(optMetaArgs))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, nil, nil, parser.WithLocation(errors.Wrapf(err, "failed to process arguments for platform %s", v), st.Location)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p, err := platforms.Parse(v)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, nil, nil, parser.WithLocation(errors.Wrapf(err, "failed to parse platform %s", v), st.Location)
|
|
|
|
+ }
|
|
|
|
+ ds.platform = &p
|
|
|
|
+ }
|
|
|
|
+
|
|
if st.Name != "" {
|
|
if st.Name != "" {
|
|
- s, img, bi, err := opt.ContextByName(ctx, st.Name, opt.ImageResolveMode.String())
|
|
|
|
|
|
+ s, img, bi, err := opt.ContextByName(ctx, st.Name, opt.ImageResolveMode.String(), ds.platform)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
return nil, nil, nil, err
|
|
}
|
|
}
|
|
@@ -195,18 +211,6 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
|
|
ds.stageName = fmt.Sprintf("stage-%d", i)
|
|
ds.stageName = fmt.Sprintf("stage-%d", i)
|
|
}
|
|
}
|
|
|
|
|
|
- if v := st.Platform; v != "" {
|
|
|
|
- v, err := shlex.ProcessWordWithMap(v, metaArgsToMap(optMetaArgs))
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, nil, nil, parser.WithLocation(errors.Wrapf(err, "failed to process arguments for platform %s", v), st.Location)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- p, err := platforms.Parse(v)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, nil, nil, parser.WithLocation(errors.Wrapf(err, "failed to parse platform %s", v), st.Location)
|
|
|
|
- }
|
|
|
|
- ds.platform = &p
|
|
|
|
- }
|
|
|
|
allDispatchStates.addState(ds)
|
|
allDispatchStates.addState(ds)
|
|
|
|
|
|
total := 0
|
|
total := 0
|
|
@@ -313,7 +317,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
|
|
d.stage.BaseName = reference.TagNameOnly(ref).String()
|
|
d.stage.BaseName = reference.TagNameOnly(ref).String()
|
|
|
|
|
|
var isScratch bool
|
|
var isScratch bool
|
|
- st, img, bi, err := opt.ContextByName(ctx, d.stage.BaseName, opt.ImageResolveMode.String())
|
|
|
|
|
|
+ st, img, bi, err := opt.ContextByName(ctx, d.stage.BaseName, opt.ImageResolveMode.String(), platform)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|