Skip to content

Commit

Permalink
Merge pull request #1468 from jaikiran/1466
Browse files Browse the repository at this point in the history
Introduce a --ignore option to allow "sync" command to continue syncing even after a particular image sync fails
  • Loading branch information
mtrmac authored Oct 5, 2021
2 parents a95b0cc + b950f83 commit 2d5a00e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/skopeo/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type syncOptions struct {
destination string // Destination registry name
scoped bool // When true, namespace copied images at destination using the source repository name
all bool // Copy all of the images if an image in the source is a list
keepGoing bool // Whether or not to abort the sync if there are any errors during syncing the images
}

// repoDescriptor contains information of a single repository used as a sync source.
Expand Down Expand Up @@ -104,6 +105,7 @@ See skopeo-sync(1) for details.
flags.StringVarP(&opts.destination, "dest", "d", "", "DESTINATION transport type")
flags.BoolVar(&opts.scoped, "scoped", false, "Images at DESTINATION are prefix using the full source image path as scope")
flags.BoolVarP(&opts.all, "all", "a", false, "Copy all images if SOURCE-IMAGE is a list")
flags.BoolVarP(&opts.keepGoing, "keep-going", "", false, "Do not abort the sync if any image copy fails")
flags.AddFlagSet(&sharedFlags)
flags.AddFlagSet(&deprecatedTLSVerifyFlags)
flags.AddFlagSet(&srcFlags)
Expand Down Expand Up @@ -568,7 +570,6 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) error {
return err
}

imagesNumber := 0
options := copy.Options{
RemoveSignatures: opts.removeSignatures,
SignBy: opts.signByFingerprint,
Expand All @@ -578,7 +579,8 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) error {
OptimizeDestinationImageAlreadyExists: true,
ForceManifestMIMEType: manifestType,
}

errorsPresent := false
imagesNumber := 0
for _, srcRepo := range srcRepoList {
options.SourceCtx = srcRepo.Context
for counter, ref := range srcRepo.ImageRefs {
Expand Down Expand Up @@ -614,12 +616,22 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) error {
_, err = copy.Image(ctx, policyContext, destRef, ref, &options)
return err
}, opts.retryOpts); err != nil {
return errors.Wrapf(err, "Error copying ref %q", transports.ImageName(ref))
if !opts.keepGoing {
return errors.Wrapf(err, "Error copying ref %q", transports.ImageName(ref))
}
// log the error, keep a note that there was a failure and move on to the next
// image ref
errorsPresent = true
logrus.WithError(err).Errorf("Error copying ref %q", transports.ImageName(ref))
continue
}
imagesNumber++
}
}

logrus.Infof("Synced %d images from %d sources", imagesNumber, len(srcRepoList))
return nil
if !errorsPresent {
return nil
}
return errors.New("Sync failed due to previous reported error(s) for one or more images")
}
1 change: 1 addition & 0 deletions completions/bash/skopeo
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ _skopeo_sync() {
--scoped
--src-no-creds
--src-tls-verify
--keep-going
"

local transports
Expand Down
3 changes: 3 additions & 0 deletions docs/skopeo-sync.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Print usage statement.

**--retry-times** the number of times to retry, retry wait time will be exponentially increased based on the number of failed attempts.

**--keep-going**
If any errors occur during copying of images, those errors are logged and the process continues syncing rest of the images and finally fails at the end.

## EXAMPLES

### Synchronizing to a local directory
Expand Down

0 comments on commit 2d5a00e

Please sign in to comment.