|
| 1 | +package cmds |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/spf13/cobra" |
| 5 | + cmdutil "k8s.io/kubectl/pkg/cmd/util" |
| 6 | + |
| 7 | + "github.com/wencaiwulue/kubevpn/v2/pkg/util" |
| 8 | + "github.com/wencaiwulue/kubevpn/v2/pkg/util/regctl" |
| 9 | +) |
| 10 | + |
| 11 | +func CmdImageCopy(_ cmdutil.Factory) *cobra.Command { |
| 12 | + var imageCmd = &cobra.Command{ |
| 13 | + Use: "image <cmd>", |
| 14 | + Short: "copy images", |
| 15 | + } |
| 16 | + |
| 17 | + copyCmd := &cobra.Command{ |
| 18 | + Use: "copy <src_image_ref> <dst_image_ref>", |
| 19 | + Aliases: []string{"cp"}, |
| 20 | + Short: "copy or re-tag image", |
| 21 | + Long: `Copy or re-tag an image. This works between registries and only pulls layers |
| 22 | +that do not exist at the target. In the same registry it attempts to mount |
| 23 | +the layers between repositories. And within the same repository it only |
| 24 | +sends the manifest with the new tag.`, |
| 25 | + Example: ` |
| 26 | +# copy an image |
| 27 | +regctl image copy ghcr.io/kubenetworks/kubevpn:latest docker.io/naison/kubevpn:latest |
| 28 | +
|
| 29 | +# re-tag an image |
| 30 | +regctl image copy registry.example.org/repo:v1.2.3 registry.example.org/repo:v1`, |
| 31 | + Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs), |
| 32 | + PreRunE: func(cmd *cobra.Command, args []string) error { |
| 33 | + util.InitLoggerForClient(false) |
| 34 | + return nil |
| 35 | + }, |
| 36 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 37 | + err := regctl.TransferImageWithRegctl(cmd.Context(), args[0], args[1]) |
| 38 | + return err |
| 39 | + }, |
| 40 | + } |
| 41 | + imageCmd.AddCommand(copyCmd) |
| 42 | + return imageCmd |
| 43 | +} |
0 commit comments