Skip to content

Commit

Permalink
Merge pull request #4012 from deitch/remote-tag-with-copy
Browse files Browse the repository at this point in the history
remote-tag enable copying across repositories and registries
  • Loading branch information
deitch committed Mar 6, 2024
2 parents 0d89422 + 51696d2 commit b8b00e8
Show file tree
Hide file tree
Showing 30 changed files with 1,661 additions and 358 deletions.
23 changes: 16 additions & 7 deletions src/cmd/linuxkit/pkg_remotetag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
namepkg "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
Expand All @@ -19,9 +20,13 @@ func pkgRemoteTagCmd() *cobra.Command {
Long: `Tag a package in a remote registry with another tag, without downloading or pulling.
Will simply tag using the identical descriptor.
First argument is "from" tag, second is "to" tag.
If the "to" and "from" repositories are the same, then it is a simple tag operation.
If they are not, then the "from" image is pulled and pushed to the "to" repository.
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
var finalErr error
from := args[0]
to := args[1]
remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)}
Expand All @@ -48,15 +53,19 @@ func pkgRemoteTagCmd() *cobra.Command {
}
log.Infof("image %s already exists in the registry, but is different from %s, overwriting", toFullname, fromFullname)
}
toTag, err := namepkg.NewTag(toFullname)
if err != nil {
return err
}
if err := remote.Tag(toTag, fromDesc, remoteOptions...); err != nil {
return fmt.Errorf("error tagging image %s as %s: %v", fromFullname, toFullname, err)
// see if they are from the same sources
if fromRef.Context().String() == toRef.Context().String() {
toTag, err := namepkg.NewTag(toFullname)
if err != nil {
return err
}
finalErr = remote.Tag(toTag, fromDesc, remoteOptions...)
} else {
// different, so need to copy
finalErr = crane.Copy(fromFullname, toFullname)
}

return nil
return finalErr
},
}
cmd.Flags().StringVar(&release, "release", "", "Release the given version")
Expand Down
191 changes: 0 additions & 191 deletions src/cmd/linuxkit/vendor/github.com/estesp/manifest-tool/v2/LICENSE

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b8b00e8

Please sign in to comment.