Skip to content

Commit

Permalink
buildkitapi: more debugging tools
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Jun 2, 2023
1 parent 541352d commit 11259c6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/buildkitapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net"
"os"
"path/filepath"

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
Expand All @@ -23,13 +24,15 @@ import (

var useCache bool
var useLegacyAPI bool
var contextDir string

// A small utility for running Buildkit on the dockerfile
// in the current directory printing out all the buildkit api
// response protobufs.
func main() {
flag.BoolVar(&useCache, "cache", false, "Enable docker caching")
flag.BoolVar(&useLegacyAPI, "legacy", false, "Print legacy build events")
flag.StringVar(&contextDir, "context", "", "Context directory")
flag.Parse()

err := run()
Expand Down Expand Up @@ -59,10 +62,16 @@ func run() error {
}

dir, _ := os.Getwd()
if contextDir == "" {
contextDir = dir
}
if !filepath.IsAbs(contextDir) {
contextDir = filepath.Join(dir, contextDir)
}
session.Allow(filesync.NewFSSyncProvider([]filesync.SyncedDir{
{
Name: "context",
Dir: dir,
Dir: contextDir,
Map: fileMap,
},
{
Expand Down Expand Up @@ -114,18 +123,14 @@ func readDockerOutput(ctx context.Context, reader io.Reader) error {
return errors.Wrap(err, "decoding docker output")
}

if message.Aux == nil {
continue
}

isFromBuildkit := messageIsFromBuildkit(message)
if isFromBuildkit && !useLegacyAPI {
err := writeBuildkitStatus(message.Aux)
if err != nil {
return err
}
} else if !isFromBuildkit && useLegacyAPI {
err := json.NewEncoder(os.Stdout).Encode(message.Aux)
err := json.NewEncoder(os.Stdout).Encode(message)
if err != nil {
return err
}
Expand Down

0 comments on commit 11259c6

Please sign in to comment.