-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
main.go
143 lines (125 loc) · 3.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"os"
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
_ "github.com/moby/buildkit/client/connhelper/kubepod"
_ "github.com/moby/buildkit/client/connhelper/nerdctlcontainer"
_ "github.com/moby/buildkit/client/connhelper/podmancontainer"
_ "github.com/moby/buildkit/client/connhelper/ssh"
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/util/apicaps"
"github.com/moby/buildkit/util/appdefaults"
"github.com/moby/buildkit/util/profiler"
"github.com/moby/buildkit/util/stack"
_ "github.com/moby/buildkit/util/tracing/detect/delegated"
_ "github.com/moby/buildkit/util/tracing/detect/jaeger"
_ "github.com/moby/buildkit/util/tracing/env"
"github.com/moby/buildkit/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"go.opentelemetry.io/otel"
)
func init() {
apicaps.ExportedProduct = "buildkit"
stack.SetVersionInfo(version.Version, version.Revision)
// do not log tracing errors to stdio
otel.SetErrorHandler(skipErrors{})
}
func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
}
app := cli.NewApp()
app.Name = "buildctl"
app.Usage = "build utility"
app.Version = version.Version
defaultAddress := os.Getenv("BUILDKIT_HOST")
if defaultAddress == "" {
defaultAddress = appdefaults.Address
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "enable debug output in logs",
},
cli.StringFlag{
Name: "addr",
Usage: "buildkitd address",
Value: defaultAddress,
},
cli.StringFlag{
Name: "tlsservername",
Usage: "buildkitd server name for certificate validation",
Value: "",
},
cli.StringFlag{
Name: "tlscacert",
Usage: "CA certificate for validation",
Value: "",
},
cli.StringFlag{
Name: "tlscert",
Usage: "client certificate",
Value: "",
},
cli.StringFlag{
Name: "tlskey",
Usage: "client key",
Value: "",
},
cli.StringFlag{
Name: "tlsdir",
Usage: "directory containing CA certificate, client certificate, and client key",
Value: "",
},
cli.IntFlag{
Name: "timeout",
Usage: "timeout backend connection after value seconds",
Value: 5,
},
cli.BoolFlag{
Name: "wait",
Usage: "block RPCs until the connection becomes available",
},
}
app.Commands = []cli.Command{
diskUsageCommand,
pruneCommand,
pruneHistoriesCommand,
buildCommand,
debugCommand,
dialStdioCommand,
}
var debugEnabled bool
app.Before = func(context *cli.Context) error {
debugEnabled = context.GlobalBool("debug")
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
if debugEnabled {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
if err := bccommon.AttachAppContext(app); err != nil {
handleErr(debugEnabled, err)
}
profiler.Attach(app)
handleErr(debugEnabled, app.Run(os.Args))
}
func handleErr(debug bool, err error) {
if err == nil {
return
}
for _, s := range errdefs.Sources(err) {
s.Print(os.Stderr)
}
if debug {
fmt.Fprintf(os.Stderr, "error: %+v", stack.Formatter(err))
} else {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
os.Exit(1)
}
type skipErrors struct{}
func (skipErrors) Handle(err error) {}