Skip to content

Commit

Permalink
Merge pull request #273 from depot/feat/log-git-checks
Browse files Browse the repository at this point in the history
feat: log when getting git provenance
  • Loading branch information
goller authored Apr 22, 2024
2 parents 4339676 + 9f508b8 commit 7402689
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/buildx/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
depotbuild "github.com/depot/cli/pkg/build"
"github.com/depot/cli/pkg/buildx/imagetools"
"github.com/depot/cli/pkg/debuglog"
depotprogress "github.com/depot/cli/pkg/progress"
"github.com/distribution/reference"
"github.com/docker/buildx/builder"
"github.com/docker/buildx/driver"
Expand Down Expand Up @@ -819,7 +820,9 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
multiDriver := len(m[k]) > 1
hasMobyDriver := false
debuglog.Log("Fetching git attributes")
finishLog := depotprogress.StartLog(w, "[internal] fetching git attributes")
gitattrs, err := getGitAttributes(ctx, opt.Inputs.ContextPath, opt.Inputs.DockerfilePath)
finishLog(err)
if err != nil {
logrus.Warn(err)
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/progress/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package progress

import (
"time"

"github.com/docker/buildx/util/progress"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/identity"
"github.com/opencontainers/go-digest"
)

// Log is a helper to log a message with a progress.Writer.
// progress.Writer is pretty intricate and thus can be a lot of boilerplate.

func StartLog(w progress.Writer, message string) func(err error) {
dgst := digest.FromBytes([]byte(identity.NewID()))
tm := time.Now()
w.Write(&client.SolveStatus{
Vertexes: []*client.Vertex{{
Digest: dgst,
Name: message,
Started: &tm,
}},
})

return func(err error) {
tm2 := time.Now()
errMsg := ""
if err != nil {
errMsg = err.Error()
}
w.Write(&client.SolveStatus{
Vertexes: []*client.Vertex{{
Digest: dgst,
Name: message,
Started: &tm,
Completed: &tm2,
Error: errMsg,
}},
})
}
}

0 comments on commit 7402689

Please sign in to comment.