Skip to content

Commit 85b3c2f

Browse files
authored
fix: add retry client for pull and push operation (#102)
Signed-off-by: chlins <[email protected]>
1 parent 9347ed1 commit 85b3c2f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pkg/backend/pull.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"oras.land/oras-go/v2/registry/remote"
3333
"oras.land/oras-go/v2/registry/remote/auth"
3434
"oras.land/oras-go/v2/registry/remote/credentials"
35+
"oras.land/oras-go/v2/registry/remote/retry"
3536
)
3637

3738
// Pull pulls an artifact from a registry.
@@ -63,19 +64,19 @@ func (b *backend) Pull(ctx context.Context, target string, opts ...Option) error
6364
}
6465

6566
// create the http client.
66-
httpClient := http.DefaultClient
67+
httpClient := &http.Client{}
6768
if options.proxy != "" {
6869
proxyURL, err := url.Parse(options.proxy)
6970
if err != nil {
7071
return fmt.Errorf("failed to parse the proxy URL: %w", err)
7172
}
7273

73-
httpClient.Transport = &http.Transport{
74+
httpClient.Transport = retry.NewTransport(&http.Transport{
7475
Proxy: http.ProxyURL(proxyURL),
7576
TLSClientConfig: &tls.Config{
7677
InsecureSkipVerify: options.insecure,
7778
},
78-
}
79+
})
7980
}
8081

8182
src.Client = &auth.Client{

pkg/backend/push.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"oras.land/oras-go/v2/registry/remote"
3232
"oras.land/oras-go/v2/registry/remote/auth"
3333
"oras.land/oras-go/v2/registry/remote/credentials"
34+
"oras.land/oras-go/v2/registry/remote/retry"
3435
)
3536

3637
// Push pushes the image to the registry.
@@ -66,6 +67,7 @@ func (b *backend) Push(ctx context.Context, target string, opts ...Option) error
6667
dst.Client = &auth.Client{
6768
Cache: auth.NewCache(),
6869
Credential: credentials.Credential(credStore),
70+
Client: retry.DefaultClient,
6971
}
7072

7173
if options.plainHTTP {

0 commit comments

Comments
 (0)