mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00

Tested with `kind` and GKE. Note: "nodes" shown in `docker buildx ls` are unrelated to Kubernetes "nodes". Probably buildx should come up with an alternative term. Usage: $ kind create cluster $ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" $ docker buildx create --driver kubernetes --driver-opt replicas=3 --use $ docker buildx build -t foo --load . `--load` loads the image into the local Docker. Driver opts: - `image=IMAGE` - Sets the container image to be used for running buildkit. - `namespace=NS` - Sets the Kubernetes namespace. Defaults to the current namespace. - `replicas=N` - Sets the number of `Pod` replicas. Defaults to 1. - `rootless=(true|false)` - Run the container as a non-root user without `securityContext.privileged`. Defaults to false. - `loadbalance=(sticky|random)` - Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
112 lines
2.1 KiB
Go
112 lines
2.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/docker/buildx/store"
|
|
"github.com/docker/cli/cli"
|
|
"github.com/docker/cli/cli/command"
|
|
"github.com/moby/buildkit/util/appcontext"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type rmOptions struct {
|
|
}
|
|
|
|
func runRm(dockerCli command.Cli, in rmOptions, args []string) error {
|
|
ctx := appcontext.Context()
|
|
|
|
txn, release, err := getStore(dockerCli)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer release()
|
|
|
|
if len(args) > 0 {
|
|
ng, err := getNodeGroup(txn, dockerCli, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err1 := stop(ctx, dockerCli, ng, true)
|
|
if err := txn.Remove(ng.Name); err != nil {
|
|
return err
|
|
}
|
|
return err1
|
|
}
|
|
|
|
ng, err := getCurrentInstance(txn, dockerCli)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if ng != nil {
|
|
err1 := stop(ctx, dockerCli, ng, true)
|
|
if err := txn.Remove(ng.Name); err != nil {
|
|
return err
|
|
}
|
|
return err1
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func rmCmd(dockerCli command.Cli) *cobra.Command {
|
|
var options rmOptions
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "rm [NAME]",
|
|
Short: "Remove a builder instance",
|
|
Args: cli.RequiresMaxArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runRm(dockerCli, options, args)
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func stop(ctx context.Context, dockerCli command.Cli, ng *store.NodeGroup, rm bool) error {
|
|
dis, err := driversForNodeGroup(ctx, dockerCli, ng, "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, di := range dis {
|
|
if di.Driver != nil {
|
|
if err := di.Driver.Stop(ctx, true); err != nil {
|
|
return err
|
|
}
|
|
if rm {
|
|
if err := di.Driver.Rm(ctx, true); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
if di.Err != nil {
|
|
err = di.Err
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func stopCurrent(ctx context.Context, dockerCli command.Cli, rm bool) error {
|
|
dis, err := getDefaultDrivers(ctx, dockerCli, "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, di := range dis {
|
|
if di.Driver != nil {
|
|
if err := di.Driver.Stop(ctx, true); err != nil {
|
|
return err
|
|
}
|
|
if rm {
|
|
if err := di.Driver.Rm(ctx, true); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
if di.Err != nil {
|
|
err = di.Err
|
|
}
|
|
}
|
|
return err
|
|
}
|