diff --git a/docs/spec.schema.json b/docs/spec.schema.json index a5a02bd29..feaf930f6 100644 --- a/docs/spec.schema.json +++ b/docs/spec.schema.json @@ -483,14 +483,13 @@ "SourceContext": { "properties": { "name": { - "type": "string" - }, - "path": { - "type": "string" + "type": "string", + "description": "Name is the name of the build context. By default, it is the magic name\n`context`, recognized by Docker as the default context." } }, "additionalProperties": false, - "type": "object" + "type": "object", + "description": "SourceContext is used to generate a source from a build context." }, "SourceDockerImage": { "properties": { diff --git a/load.go b/load.go index a48b4be37..1e66c03a7 100644 --- a/load.go +++ b/load.go @@ -27,7 +27,15 @@ const DefaultPatchStrip int = 1 func (s *Source) processArgs(args map[string]string) error { lex := shell.NewLex('\\') - var sub *string + sub := func(s *string) error { + updated, err := lex.ProcessWordWithMap(*s, args) + if err != nil { + return err + } + *s = updated + return nil + } + switch { case s.DockerImage != nil: for _, mnt := range s.DockerImage.Cmd.Mounts { @@ -35,56 +43,40 @@ func (s *Source) processArgs(args map[string]string) error { return err } } - sub = &s.DockerImage.Ref + sub(&s.DockerImage.Ref) case s.Git != nil: - sub = &s.Git.URL + fields := []*string{ + &s.Git.URL, + &s.Git.Commit, + } + for _, f := range fields { + if err := sub(f); err != nil { + return err + } + } case s.HTTPS != nil: - sub = &s.HTTPS.URL + sub(&s.HTTPS.URL) case s.Context != nil: - updated, err := lex.ProcessWordWithMap(s.Context.Name, args) - if err != nil { - return err - } - s.Context.Name = updated - - updated, err = lex.ProcessWordWithMap(s.Context.Path, args) - if err != nil { + if err := sub(&s.Context.Name); err != nil { return err } - s.Context.Path = updated - - sub = nil case s.Build != nil: if err := s.Build.Source.processArgs(args); err != nil { return err } - updated, err := lex.ProcessWordWithMap(s.Build.DockerFile, args) - if err != nil { - return err + fields := []*string{ + &s.Build.DockerFile, + &s.Build.Target, } - s.Build.DockerFile = updated - - updated, err = lex.ProcessWordWithMap(s.Build.Target, args) - if err != nil { - return err + for _, f := range fields { + if err := sub(f); err != nil { + return err + } } - s.Build.Target = updated - - sub = nil default: } - if sub == nil { - return nil - } - - updated, err := lex.ProcessWordWithMap(*sub, args) - if err != nil { - return err - } - - *sub = updated return nil } @@ -100,8 +92,8 @@ func fillDefaults(s *Source) { if s.Context.Name == "" { s.Context.Name = dockerui.DefaultLocalNameContext } - if s.Context.Path == "" { - s.Context.Path = "." + if s.Path == "" { + s.Path = "." } case s.Build != nil: fillDefaults(&s.Build.Source) diff --git a/source.go b/source.go index 71cf3b00d..fec59305c 100644 --- a/source.go +++ b/source.go @@ -186,18 +186,12 @@ func source2LLBGetter(s *Spec, src Source, name string, forMount bool) LLBGetter opts = append(opts, llb.Filename(name)) return llb.HTTP(https.URL, opts...), nil case src.Context != nil: - srcCtx := src.Context - st, err := sOpt.GetContext(dockerui.DefaultLocalNameContext, localIncludeExcludeMerge(&src)) if err != nil { return llb.Scratch(), err } includeExcludeHandled = true - if src.Path == "" && srcCtx.Path != "" { - src.Path = srcCtx.Path - } - return *st, nil case src.Build != nil: build := src.Build diff --git a/spec.go b/spec.go index 698b8c40d..349690ea1 100644 --- a/spec.go +++ b/spec.go @@ -194,9 +194,12 @@ type SourceHTTPS struct { URL string `yaml:"url" json:"url"` } +// SourceContext is used to generate a source from a build context. The path to +// the build context is provided to the `Path` field of the owning `Source`. type SourceContext struct { + // Name is the name of the build context. By default, it is the magic name + // `context`, recognized by Docker as the default context. Name string `yaml:"name,omitempty" json:"name,omitempty"` - Path string `yaml:"path,omitempty" json:"path,omitempty"` } // SourceBuild is used to generate source from a DockerFile build, either