build: add experimental support for print flag

Print flag can be used to make additional information
requests about the build and print their results.

Currently Dockerfile supports: outline, targets, subrequests.describe

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2022-05-04 18:48:50 -07:00
parent 17dc0e1108
commit eefa8188e1
98 changed files with 8536 additions and 3339 deletions

35
commands/print.go Normal file
View File

@ -0,0 +1,35 @@
package commands
import (
"fmt"
"log"
"os"
"github.com/moby/buildkit/frontend/subrequests"
"github.com/moby/buildkit/frontend/subrequests/outline"
"github.com/moby/buildkit/frontend/subrequests/targets"
)
func printResult(f string, res map[string]string) error {
switch f {
case "outline":
if err := outline.PrintOutline([]byte(res["result.json"]), os.Stdout); err != nil {
return err
}
case "targets":
if err := targets.PrintTargets([]byte(res["result.json"]), os.Stdout); err != nil {
return err
}
case "subrequests.describe":
if err := subrequests.PrintDescribe([]byte(res["result.json"]), os.Stdout); err != nil {
return err
}
default:
if dt, ok := res["result.txt"]; ok {
fmt.Print(dt)
} else {
log.Printf("%s %+v", f, res)
}
}
return nil
}