Skip to content

Commit eb1fc1e

Browse files
committed
fix(push): add OnRetry handler for config and manifest retry
Signed-off-by: Zhao Chen <winters.zc@antgroup.com>
1 parent 1369e47 commit eb1fc1e

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

pkg/backend/push.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,33 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err
131131
FileSize: manifest.Config.Size,
132132
FileName: "config",
133133
Config: &cfg.RetryConfig,
134+
OnRetry: func(attempt uint, reason string, backoff time.Duration) {
135+
prompt := fmt.Sprintf("%s (retry %d, %s, waiting %s)",
136+
internalpb.NormalizePrompt("Copying config"), attempt, reason, backoff.Truncate(time.Second))
137+
pb.Add(prompt, manifest.Config.Digest.String(), manifest.Config.Size, nil)
138+
},
134139
}); err != nil {
135140
return fmt.Errorf("failed to push config to remote: %w", err)
136141
}
137142

138143
// copy the manifest.
144+
manifestDesc := ocispec.Descriptor{
145+
MediaType: manifest.MediaType,
146+
Size: int64(len(manifestRaw)),
147+
Digest: godigest.FromBytes(manifestRaw),
148+
Data: manifestRaw,
149+
}
139150
if err := retrypolicy.Do(ctx, func(rctx context.Context) error {
140-
return pushIfNotExist(rctx, pb, internalpb.NormalizePrompt("Copying manifest"), src, dst, ocispec.Descriptor{
141-
MediaType: manifest.MediaType,
142-
Size: int64(len(manifestRaw)),
143-
Digest: godigest.FromBytes(manifestRaw),
144-
Data: manifestRaw,
145-
}, repo, tag)
151+
return pushIfNotExist(rctx, pb, internalpb.NormalizePrompt("Copying manifest"), src, dst, manifestDesc, repo, tag)
146152
}, retrypolicy.DoOpts{
147-
FileSize: int64(len(manifestRaw)),
153+
FileSize: manifestDesc.Size,
148154
FileName: "manifest",
149155
Config: &cfg.RetryConfig,
156+
OnRetry: func(attempt uint, reason string, backoff time.Duration) {
157+
prompt := fmt.Sprintf("%s (retry %d, %s, waiting %s)",
158+
internalpb.NormalizePrompt("Copying manifest"), attempt, reason, backoff.Truncate(time.Second))
159+
pb.Add(prompt, manifestDesc.Digest.String(), manifestDesc.Size, nil)
160+
},
150161
}); err != nil {
151162
return fmt.Errorf("failed to push manifest to remote: %w", err)
152163
}

0 commit comments

Comments
 (0)