Skip to content

Commit

Permalink
Merge pull request #2408 from tonistiigi/print-statuscode
Browse files Browse the repository at this point in the history
build: support statuscode response for print requests
  • Loading branch information
tonistiigi authored Apr 15, 2024
2 parents b919574 + 46c44c5 commit 07c9b45
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 131 deletions.
5 changes: 3 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ type Options struct {
}

type PrintFunc struct {
Name string
Format string
Name string
Format string
IgnoreStatus bool
}

type Inputs struct {
Expand Down
5 changes: 5 additions & 0 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,11 @@ func printResult(f *controllerapi.PrintFunc, res map[string]string) error {
log.Printf("%s %+v", f, res)
}
}
if v, ok := res["result.statuscode"]; !f.IgnoreStatus && ok {
if n, err := strconv.Atoi(v); err == nil && n != 0 {
os.Exit(n)
}
}
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions controller/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build

if in.PrintFunc != nil {
opts.PrintFunc = &build.PrintFunc{
Name: in.PrintFunc.Name,
Format: in.PrintFunc.Format,
Name: in.PrintFunc.Name,
Format: in.PrintFunc.Format,
IgnoreStatus: in.PrintFunc.IgnoreStatus,
}
}

Expand Down
Loading

0 comments on commit 07c9b45

Please sign in to comment.