Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions cmd/skopeo/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func copyCmd(global *globalOptions) *cobra.Command {
srcFlags, srcOpts := imageFlags(global, sharedOpts, deprecatedTLSVerifyOpt, "src-", "screds")
destFlags, destOpts := imageDestFlags(global, sharedOpts, deprecatedTLSVerifyOpt, "dest-", "dcreds")
retryFlags, retryOpts := retryFlags()
opts := copyOptions{global: global,
opts := copyOptions{
global: global,
deprecatedTLSVerify: deprecatedTLSVerifyOpt,
srcImage: srcOpts,
destImage: destOpts,
Expand Down Expand Up @@ -102,22 +103,31 @@ See skopeo(1) section "IMAGE NAMES" for the expected format

// parseMultiArch parses the list processing selection
// It returns the copy.ImageListSelection to use with image.Copy option
func parseMultiArch(multiArch string) (copy.ImageListSelection, error) {
func parseMultiArch(multiArch string) (copy.ImageListSelection, []manifest.Schema2PlatformSpec, error) {
switch multiArch {
case "system":
return copy.CopySystemImage, nil
return copy.CopySystemImage, nil, nil
case "all":
return copy.CopyAllImages, nil
return copy.CopyAllImages, nil, nil
// There is no CopyNoImages value in copy.ImageListSelection, but because we
// don't provide an option to select a set of images to copy, we can use
// CopySpecificImages.
case "index-only":
Comment thread
cleverhu marked this conversation as resolved.
return copy.CopySpecificImages, nil
// We don't expose CopySpecificImages other than index-only above, because
// we currently don't provide an option to choose the images to copy. That
// could be added in the future.
return copy.CopySpecificImages, nil, nil
default:
return copy.CopySystemImage, fmt.Errorf("unknown multi-arch option %q. Choose one of the supported options: 'system', 'all', or 'index-only'", multiArch)
platformsArr := strings.Split(multiArch, ",")
platforms := []manifest.Schema2PlatformSpec{}
for _, platform := range platformsArr {
parts := strings.SplitN(platform, "/", 2)
if len(parts) != 2 {
return copy.CopySystemImage, nil, fmt.Errorf("invalid platform format %q: expected os/arch", platform)
}

os := parts[0]
arch := parts[1]
platforms = append(platforms, manifest.Schema2PlatformSpec{OS: os, Architecture: arch})
}
return copy.CopyCustomArchImages, platforms, nil
}
}

Expand Down Expand Up @@ -188,11 +198,12 @@ func (opts *copyOptions) run(args []string, stdout io.Writer) (retErr error) {
}

imageListSelection := copy.CopySystemImage
imageListPlatforms := []manifest.Schema2PlatformSpec{}
if opts.multiArch.Present() && opts.all {
return fmt.Errorf("Cannot use --all and --multi-arch flags together")
}
if opts.multiArch.Present() {
imageListSelection, err = parseMultiArch(opts.multiArch.Value())
imageListSelection, imageListPlatforms, err = parseMultiArch(opts.multiArch.Value())
if err != nil {
return err
}
Expand Down Expand Up @@ -303,6 +314,7 @@ func (opts *copyOptions) run(args []string, stdout io.Writer) (retErr error) {
OciEncryptLayers: encLayers,
OciEncryptConfig: encConfig,
MaxParallelDownloads: opts.imageParallelCopies,
ImageListPlatforms: imageListPlatforms,
})
if err != nil {
return err
Expand All @@ -312,7 +324,7 @@ func (opts *copyOptions) run(args []string, stdout io.Writer) (retErr error) {
if err != nil {
return err
}
if err = os.WriteFile(opts.digestFile, []byte(manifestDigest.String()), 0644); err != nil {
if err = os.WriteFile(opts.digestFile, []byte(manifestDigest.String()), 0o644); err != nil {
return fmt.Errorf("Failed to write digest to file %q: %w", opts.digestFile, err)
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/skopeo-copy.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Options:
- system: Copy only the image that matches the system architecture
- all: Copy the full multi-architecture image
- index-only: Copy only the index
- targetPlatforms: Copy only the images that match the specified platforms (e.g. linux/amd64,linux/arm64)

The index-only option usually fails unless the referenced per-architecture images are already present in the destination, or the target registry supports sparse indexes.

Expand Down