Skip to content

Commit

Permalink
build: support statuscode response for print requests
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Apr 15, 2024
1 parent df7a3db commit 46c44c5
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 @@ -88,8 +88,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 46c44c5

Please sign in to comment.