-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: set record status warnings in response
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
318 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package build | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/docker/buildx/util/confutil" | ||
"github.com/docker/buildx/util/progress" | ||
controlapi "github.com/moby/buildkit/api/services/control" | ||
"github.com/moby/buildkit/client" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func setRecordStatus(ctx context.Context, c *client.Client, sr *client.SolveResponse, ref string, pw progress.Writer) error { | ||
if !confutil.MetadataStatus() { | ||
return nil | ||
} | ||
pw = progress.ResetTime(pw) | ||
return progress.Wrap("resolving status for metadata file", pw.Write, func(l progress.SubLogger) error { | ||
status, err := fetchStatus(ctx, c, ref) | ||
if err != nil { | ||
return err | ||
} else if status == nil || len(status.Warnings) == 0 { | ||
return nil | ||
} | ||
|
||
// we just want warnings for now | ||
status.Vertexes = nil | ||
status.Statuses = nil | ||
status.Logs = nil | ||
|
||
dt, err := json.Marshal(status) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to marshal status") | ||
} | ||
sr.ExporterResponse["buildx.build.status"] = base64.StdEncoding.EncodeToString(dt) | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func fetchStatus(ctx context.Context, c *client.Client, ref string) (*client.SolveStatus, error) { | ||
cl, err := c.ControlClient().Status(ctx, &controlapi.StatusRequest{ | ||
Ref: ref, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := cl.Recv() | ||
if err != nil { | ||
if err == io.EOF { | ||
return nil, nil | ||
} | ||
return nil, errors.Wrap(err, "failed to receive status") | ||
} | ||
return client.NewSolveStatus(resp), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.