mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-04 18:48:45 +08:00

This patch completes the work started in creating a remote driver: - Renames the env driver to the remote driver (an alternative suggestion that should be more user-friendly) - Adds support for TLS to encrypt connections with buildkitd - Fixes outstanding review comments - Reworks the buildx create command endpoint construction to be clearer and include better support for this new driver. Signed-off-by: Justin Chadwell <me@jedevc.com>
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/containerd/containerd/pkg/seed"
|
|
"github.com/docker/buildx/commands"
|
|
"github.com/docker/buildx/version"
|
|
"github.com/docker/cli/cli"
|
|
"github.com/docker/cli/cli-plugins/manager"
|
|
"github.com/docker/cli/cli-plugins/plugin"
|
|
"github.com/docker/cli/cli/command"
|
|
"github.com/docker/cli/cli/debug"
|
|
cliflags "github.com/docker/cli/cli/flags"
|
|
"github.com/moby/buildkit/solver/errdefs"
|
|
"github.com/moby/buildkit/util/stack"
|
|
|
|
// FIXME: "k8s.io/client-go/plugin/pkg/client/auth/azure" is excluded because of compilation error
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
|
|
|
|
_ "github.com/docker/buildx/driver/docker"
|
|
_ "github.com/docker/buildx/driver/docker-container"
|
|
_ "github.com/docker/buildx/driver/kubernetes"
|
|
_ "github.com/docker/buildx/driver/remote"
|
|
)
|
|
|
|
func init() {
|
|
seed.WithTimeAndRand()
|
|
stack.SetVersionInfo(version.Version, version.Revision)
|
|
}
|
|
|
|
func runStandalone(cmd *command.DockerCli) error {
|
|
if err := cmd.Initialize(cliflags.NewClientOptions()); err != nil {
|
|
return err
|
|
}
|
|
rootCmd := commands.NewRootCmd(os.Args[0], false, cmd)
|
|
return rootCmd.Execute()
|
|
}
|
|
|
|
func runPlugin(cmd *command.DockerCli) error {
|
|
rootCmd := commands.NewRootCmd("buildx", true, cmd)
|
|
return plugin.RunPlugin(cmd, rootCmd, manager.Metadata{
|
|
SchemaVersion: "0.1.0",
|
|
Vendor: "Docker Inc.",
|
|
Version: version.Version,
|
|
})
|
|
}
|
|
|
|
func main() {
|
|
cmd, err := command.NewDockerCli()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if plugin.RunningStandalone() {
|
|
err = runStandalone(cmd)
|
|
} else {
|
|
err = runPlugin(cmd)
|
|
}
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
if sterr, ok := err.(cli.StatusError); ok {
|
|
if sterr.Status != "" {
|
|
fmt.Fprintln(cmd.Err(), sterr.Status)
|
|
}
|
|
// StatusError should only be used for errors, and all errors should
|
|
// have a non-zero exit status, so never exit with 0
|
|
if sterr.StatusCode == 0 {
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(sterr.StatusCode)
|
|
}
|
|
|
|
for _, s := range errdefs.Sources(err) {
|
|
s.Print(cmd.Err())
|
|
}
|
|
if debug.IsEnabled() {
|
|
fmt.Fprintf(cmd.Err(), "error: %+v", stack.Formatter(err))
|
|
} else {
|
|
fmt.Fprintf(cmd.Err(), "error: %v\n", err)
|
|
}
|
|
|
|
os.Exit(1)
|
|
}
|