MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / pkgRemoteTagCmd

Function pkgRemoteTagCmd

src/cmd/linuxkit/pkg_remotetag.go:16–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func pkgRemoteTagCmd() *cobra.Command {
17 var release string
18 cmd := &cobra.Command{
19 Use: "remote-tag",
20 Short: "tag a package in a remote registry with another tag",
21 Long: `Tag a package in a remote registry with another tag, without downloading or pulling.
22 Will simply tag using the identical descriptor.
23 First argument is "from" tag, second is "to" tag.
24
25 If the "to" and "from" repositories are the same, then it is a simple tag operation.
26 If they are not, then the "from" image is pulled and pushed to the "to" repository.
27`,
28 Args: cobra.ExactArgs(2),
29 RunE: func(cmd *cobra.Command, args []string) error {
30 var finalErr error
31 from := args[0]
32 to := args[1]
33 remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)}
34
35 fromFullname := util.ReferenceExpand(from, util.ReferenceWithTag())
36 toFullname := util.ReferenceExpand(to, util.ReferenceWithTag())
37 fromRef, err := namepkg.ParseReference(fromFullname)
38 if err != nil {
39 return err
40 }
41 toRef, err := namepkg.ParseReference(toFullname)
42 if err != nil {
43 return err
44 }
45 fromDesc, err := registry.GetRemote().Get(fromRef, remoteOptions...)
46 if err != nil {
47 return fmt.Errorf("error getting manifest for from image %s: %v", fromFullname, err)
48 }
49 toDesc, err := registry.GetRemote().Get(toRef, remoteOptions...)
50 if err == nil {
51 if toDesc.Digest == fromDesc.Digest {
52 log.Infof("image %s already exists in the registry, identical to %s, skipping", toFullname, fromFullname)
53 return nil
54 }
55 log.Infof("image %s already exists in the registry, but is different from %s, overwriting", toFullname, fromFullname)
56 }
57 // see if they are from the same sources
58 if fromRef.Context().String() == toRef.Context().String() {
59 toTag, err := namepkg.NewTag(toFullname)
60 if err != nil {
61 return err
62 }
63 finalErr = registry.GetRemote().Tag(toTag, fromDesc, remoteOptions...)
64 } else {
65 // different, so need to copy
66 finalErr = crane.Copy(fromFullname, toFullname)
67 }
68
69 return finalErr
70 },
71 }
72 cmd.Flags().StringVar(&release, "release", "", "Release the given version")
73

Callers 1

pkgCmdFunction · 0.85

Calls 3

StringMethod · 0.65
TagMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected