Skip to content

Commit

Permalink
Merge pull request #286 from depot/load-logs
Browse files Browse the repository at this point in the history
Report `--load` progress to UI
  • Loading branch information
jacobwgillespie authored May 21, 2024
2 parents 0c8ce5f + de5508d commit 872736a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/buildx/commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/depot/cli/pkg/compose"
"github.com/depot/cli/pkg/helpers"
"github.com/depot/cli/pkg/load"
"github.com/depot/cli/pkg/progresshelper"
"github.com/depot/cli/pkg/registry"
"github.com/depot/cli/pkg/sbom"
buildx "github.com/docker/buildx/build"
Expand Down Expand Up @@ -187,7 +188,8 @@ func RunBake(dockerCli command.Cli, in BakeOptions, validator BakeValidator) (er
var err error
// Only load images from requested targets to avoid pulling unnecessary images.
if slices.Contains(requestedTargets, resp[i].Name) {
err = load.DepotFastLoad(ctx2, dockerCli.Client(), depotResponses, pullOpts, printer)
reportingPrinter := progresshelper.NewReportingWriter(printer, in.buildID, in.token)
err = load.DepotFastLoad(ctx2, dockerCli.Client(), depotResponses, pullOpts, reportingPrinter)
}
load.DeleteExportLeases(ctx2, depotResponses)
return err
Expand Down
6 changes: 4 additions & 2 deletions pkg/buildx/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/depot/cli/pkg/debuglog"
"github.com/depot/cli/pkg/helpers"
"github.com/depot/cli/pkg/load"
"github.com/depot/cli/pkg/progresshelper"
"github.com/depot/cli/pkg/registry"
"github.com/depot/cli/pkg/sbom"
"github.com/distribution/reference"
Expand Down Expand Up @@ -320,7 +321,8 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
}

// NOTE: the err is returned at the end of this function after the final prints.
err = load.DepotFastLoad(ctx, dockerCli.Client(), resp, pullOpts, printer)
reportingPrinter := progresshelper.NewReportingWriter(printer, depotOpts.buildID, depotOpts.token)
err = load.DepotFastLoad(ctx, dockerCli.Client(), resp, pullOpts, reportingPrinter)
if err != nil && !errors.Is(err, context.Canceled) {
// For now, we will fallback by rebuilding with load.
if exportLoad {
Expand All @@ -334,7 +336,7 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
}

if retryable {
progress.Write(printer, "[load] fast load failed; retrying", func() error { return err })
progress.Write(reportingPrinter, "[load] fast load failed; retrying", func() error { return err })
opts = load.WithDockerLoad(fallbackOpts)
_, err = depotbuildxbuild.DepotBuildWithResultHandler(ctx, buildxNodes, opts, dockerClient, dockerConfigDir, printer, nil, nil, allowNoOutput, depotOpts.build)
}
Expand Down

0 comments on commit 872736a

Please sign in to comment.