Skip to content

Commit 26e69f2

Browse files
committed
added implementation for scoped-without-registry support on sync
Signed-off-by: Martin Schuessler <[email protected]>
1 parent c88576b commit 26e69f2

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

cmd/skopeo/sync.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ import (
2727

2828
// syncOptions contains information retrieved from the skopeo sync command line.
2929
type syncOptions struct {
30-
global *globalOptions // Global (not command dependent) skopeo options
31-
srcImage *imageOptions // Source image options
32-
destImage *imageDestOptions // Destination image options
33-
retryOpts *retry.RetryOptions
34-
removeSignatures bool // Do not copy signatures from the source image
35-
signByFingerprint string // Sign the image using a GPG key with the specified fingerprint
36-
source string // Source repository name
37-
destination string // Destination registry name
38-
scoped bool // When true, namespace copied images at destination using the source repository name
39-
all bool // Copy all of the images if an image in the source is a list
30+
global *globalOptions // Global (not command dependent) skopeo options
31+
srcImage *imageOptions // Source image options
32+
destImage *imageDestOptions // Destination image options
33+
retryOpts *retry.RetryOptions
34+
removeSignatures bool // Do not copy signatures from the source image
35+
signByFingerprint string // Sign the image using a GPG key with the specified fingerprint
36+
source string // Source repository name
37+
destination string // Destination registry name
38+
scoped bool // When true, namespace copied images at destination using the source repository name
39+
all bool // Copy all of the images if an image in the source is a list
40+
scopedWithoutRegistry bool // When true, like scoped but without the registry prefix
4041
}
4142

4243
// repoDescriptor contains information of a single repository used as a sync source.
@@ -98,6 +99,7 @@ See skopeo-sync(1) for details.
9899
flags.StringVarP(&opts.source, "src", "s", "", "SOURCE transport type")
99100
flags.StringVarP(&opts.destination, "dest", "d", "", "DESTINATION transport type")
100101
flags.BoolVar(&opts.scoped, "scoped", false, "Images at DESTINATION are prefix using the full source image path as scope")
102+
flags.BoolVar(&opts.scopedWithoutRegistry, "scoped-without-registry", false, "Images at DESTINATION are prefix using the full source image path as scope but without the registry")
101103
flags.BoolVarP(&opts.all, "all", "a", false, "Copy all images if SOURCE-IMAGE is a list")
102104
flags.AddFlagSet(&sharedFlags)
103105
flags.AddFlagSet(&srcFlags)
@@ -570,6 +572,13 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) error {
570572
case docker.Transport:
571573
// docker -> dir or docker -> docker
572574
destSuffix = ref.DockerReference().String()
575+
if opts.scopedWithoutRegistry {
576+
removeRegistry := func(s string) string {
577+
split := strings.Split(s, "/")
578+
return strings.Join(split[1:], "/")
579+
}
580+
destSuffix = removeRegistry(ref.DockerReference().String())
581+
}
573582
case directory.Transport:
574583
// dir -> docker (we don't allow `dir` -> `dir` sync operations)
575584
destSuffix = strings.TrimPrefix(ref.StringWithinTransport(), srcRepo.DirBasePath)
@@ -579,7 +588,7 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) error {
579588
}
580589
}
581590

582-
if !opts.scoped {
591+
if !opts.scoped && !opts.scopedWithoutRegistry {
583592
destSuffix = path.Base(destSuffix)
584593
}
585594

0 commit comments

Comments
 (0)