From 684f0d38eee0a7cd303a2259c9d1e6d417bc965a Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Tue, 30 Sep 2025 19:23:01 +1000 Subject: [PATCH] feat(push): '--platform all' to push image to all machines in cluster --- cmd/uncloud/image/push.go | 15 ++++++++++++--- pkg/client/image.go | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/uncloud/image/push.go b/cmd/uncloud/image/push.go index ac255348..0a09d6e2 100644 --- a/cmd/uncloud/image/push.go +++ b/cmd/uncloud/image/push.go @@ -35,6 +35,9 @@ The image is uploaded to the machine which CLI is connected to (default) or the # Push image to multiple machines. uc image push myapp:latest -m machine1,machine2,machine3 + # Push image to all machines in the cluster. + uc image push myapp:latest -m all + # Push a specific platform of a multi-platform image. uc image push myapp:latest --platform linux/amd64`, Args: cobra.ExactArgs(1), @@ -48,7 +51,8 @@ The image is uploaded to the machine which CLI is connected to (default) or the cmd.Flags().StringSliceVarP(&opts.machines, "machine", "m", nil, "Machine names to push the image to. Can be specified multiple times or as a comma-separated "+ - "list of machine names. (default is connected machine)") + "list of machine names.\n"+ + "Use 'all' to push to all machines. (default is connected machine)") cmd.Flags().StringVar( &opts.platform, "platform", "", "Push a specific platform of a multi-platform image (e.g., linux/amd64, linux/arm64).\n"+ @@ -70,8 +74,13 @@ func push(ctx context.Context, uncli *cli.CLI, opts pushOptions) error { defer clusterClient.Close() machines := cli.ExpandCommaSeparatedValues(opts.machines) - pushOpts := client.PushImageOptions{ - Machines: machines, + pushOpts := client.PushImageOptions{} + + // Special handling for "all" keyword to push to all machines. + if len(machines) == 1 && machines[0] == "all" { + pushOpts.AllMachines = true + } else { + pushOpts.Machines = machines } if opts.platform != "" { diff --git a/pkg/client/image.go b/pkg/client/image.go index 77118c22..2be104f0 100644 --- a/pkg/client/image.go +++ b/pkg/client/image.go @@ -42,9 +42,11 @@ func (cli *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.Mac } type PushImageOptions struct { - // Machines is a list of machine names or IDs to push the image to. If empty, pushes to the machine - // the client is connected to. + // Machines is a list of machine names or IDs to push the image to. If empty and AllMachines is false, + // pushes to the machine the client is connected to. Machines []string + // AllMachines pushes the image to all machines in the cluster. Takes precedence over Machines field. + AllMachines bool // Platform to push for a multi-platform image. Local Docker must use containerd image store // to support multi-platform images. Platform *ocispec.Platform @@ -71,7 +73,15 @@ func (cli *Client) PushImage(ctx context.Context, image string, opts PushImageOp // Get the machine info for the specified machines or the connected machine if none are specified. var machines []*pb.MachineInfo - if len(opts.Machines) > 0 { + if opts.AllMachines { + machineMembers, err := cli.ListMachines(ctx, nil) + if err != nil { + return fmt.Errorf("list machines: %w", err) + } + for _, mm := range machineMembers { + machines = append(machines, mm.Machine) + } + } else if len(opts.Machines) > 0 { machineMembers, err := cli.ListMachines(ctx, &api.MachineFilter{ NamesOrIDs: opts.Machines, })