Skip to content

Commit

Permalink
Address linter errors
Browse files Browse the repository at this point in the history
Also, validate sources recursively.

Signed-off-by: Peter Engelbert <[email protected]>
  • Loading branch information
pmengelbert committed Jan 12, 2024
1 parent 140a9a9 commit 1a864c1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (s *Source) processArgs(args map[string]string) error {
switch {
case s.DockerImage != nil:
for _, mnt := range s.DockerImage.Cmd.Mounts {
mnt.Spec.processArgs(args)
if err := mnt.Spec.processArgs(args); err != nil {
return err
}
}
sub = &s.DockerImage.Ref
case s.Git != nil:
Expand All @@ -53,7 +55,9 @@ func (s *Source) processArgs(args map[string]string) error {

sub = nil
case s.Build != nil:
s.Build.Source.processArgs(args)
if err := s.Build.Source.processArgs(args); err != nil {
return err
}

updated, err := lex.ProcessWordWithMap(s.Build.DockerFile, args)
if err != nil {
Expand Down Expand Up @@ -110,6 +114,12 @@ func (s *Source) validate() error {
var errs error

if s.DockerImage != nil {
for _, mnt := range s.DockerImage.Cmd.Mounts {
if err := mnt.Spec.validate(); err != nil {
errs = goerrors.Join(errs, err)
}
}

count++
}
if s.Git != nil {
Expand All @@ -122,12 +132,16 @@ func (s *Source) validate() error {
count++
}
if s.Build != nil {
if s.Build.Source.Build != nil {
errs = goerrors.Join(errs, fmt.Errorf("build sources cannot be recursive"))
}

if s.Build.DockerFile != "" && s.Build.Inline != "" {
errs = goerrors.Join(errs, fmt.Errorf("build sources may use either `dockerfile` or `inline`, but not both"))
}

if s.Build.Source.Build != nil {
errs = goerrors.Join(errs, fmt.Errorf("build sources cannot be recursive"))
if err := s.Build.Source.validate(); err != nil {
errs = goerrors.Join(errs, err)
}

count++
Expand Down

0 comments on commit 1a864c1

Please sign in to comment.