2017-06-08 18:17:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2019-04-14 12:14:40 +00:00
|
|
|
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
|
2019-03-05 09:33:15 +00:00
|
|
|
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
|
2018-07-09 22:02:52 +00:00
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
2017-07-12 05:08:53 +00:00
|
|
|
"github.com/moby/buildkit/util/appdefaults"
|
2017-07-12 22:17:23 +00:00
|
|
|
"github.com/moby/buildkit/util/profiler"
|
2018-05-21 10:42:59 +00:00
|
|
|
"github.com/moby/buildkit/version"
|
2017-07-19 01:05:19 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-08 18:17:44 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-07-09 22:02:52 +00:00
|
|
|
func init() {
|
|
|
|
apicaps.ExportedProduct = "buildkit"
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:17:44 +00:00
|
|
|
func main() {
|
2018-05-21 10:42:59 +00:00
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
|
|
|
|
}
|
2017-06-08 18:17:44 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "buildctl"
|
|
|
|
app.Usage = "build utility"
|
2018-10-11 20:46:16 +00:00
|
|
|
app.Version = version.Version
|
2017-06-08 18:17:44 +00:00
|
|
|
|
2017-10-15 19:13:47 +00:00
|
|
|
defaultAddress := os.Getenv("BUILDKIT_HOST")
|
|
|
|
if defaultAddress == "" {
|
|
|
|
defaultAddress = appdefaults.Address
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:17:44 +00:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "enable debug output in logs",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-09-21 15:49:26 +00:00
|
|
|
Name: "addr",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "buildkitd address",
|
2017-10-15 19:13:47 +00:00
|
|
|
Value: defaultAddress,
|
2017-06-08 18:17:44 +00:00
|
|
|
},
|
2017-12-20 10:45:06 +00:00
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlsservername",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "buildkitd server name for certificate validation",
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlscacert",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "CA certificate for validation",
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlscert",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "client certificate",
|
|
|
|
Value: "",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlskey",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "client key",
|
|
|
|
Value: "",
|
|
|
|
},
|
2018-06-06 10:52:53 +00:00
|
|
|
cli.IntFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Usage: "timeout backend connection after value seconds",
|
|
|
|
Value: 5,
|
|
|
|
},
|
2017-06-08 18:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
diskUsageCommand,
|
2017-12-27 01:22:50 +00:00
|
|
|
pruneCommand,
|
2017-06-09 01:16:19 +00:00
|
|
|
buildCommand,
|
2017-06-13 08:09:14 +00:00
|
|
|
debugCommand,
|
2019-03-25 07:14:29 +00:00
|
|
|
dialStdioCommand,
|
2017-06-08 18:17:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 07:08:13 +00:00
|
|
|
var debugEnabled bool
|
|
|
|
|
2017-06-08 18:17:44 +00:00
|
|
|
app.Before = func(context *cli.Context) error {
|
2017-12-02 07:08:13 +00:00
|
|
|
debugEnabled = context.GlobalBool("debug")
|
|
|
|
if debugEnabled {
|
2017-06-08 18:17:44 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-07-12 22:17:23 +00:00
|
|
|
|
2019-03-05 09:33:15 +00:00
|
|
|
bccommon.AttachAppContext(app)
|
2018-01-05 23:17:35 +00:00
|
|
|
|
2017-07-12 22:17:23 +00:00
|
|
|
profiler.Attach(app)
|
|
|
|
|
2017-06-08 18:17:44 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
2017-12-02 07:08:13 +00:00
|
|
|
if debugEnabled {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %+v\n", err)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
}
|
2017-06-08 18:17:44 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|