@@ -11,7 +11,6 @@ import (
11
11
"github.com/Altinity/docker-sync/internal/telemetry"
12
12
"github.com/Altinity/docker-sync/structs"
13
13
"github.com/cenkalti/backoff/v4"
14
- "github.com/google/go-containerregistry/pkg/logs"
15
14
"github.com/google/go-containerregistry/pkg/name"
16
15
"github.com/google/go-containerregistry/pkg/v1/remote"
17
16
"github.com/rs/zerolog/log"
@@ -31,7 +30,7 @@ func checkRateLimit(err error) error {
31
30
}
32
31
33
32
func push (ctx context.Context , image * structs.Image , desc * remote.Descriptor , dst string , tag string ) error {
34
- return backoff .Retry (func () error {
33
+ return backoff .RetryNotify (func () error {
35
34
pushAuth , _ := getAuth (image .GetRegistry (dst ), image .GetRepository (dst ))
36
35
37
36
pusher , err := remote .NewPusher (pushAuth )
@@ -44,16 +43,22 @@ func push(ctx context.Context, image *structs.Image, desc *remote.Descriptor, ds
44
43
return fmt .Errorf ("failed to parse tag: %w" , err )
45
44
}
46
45
47
- logs .Progress .Printf ("Pushing %s" , dstTag )
48
-
49
46
if err := pusher .Push (ctx , dstTag , desc ); err != nil {
50
47
return checkRateLimit (err )
51
48
}
52
49
53
50
return nil
54
- }, backoff .NewExponentialBackOff (
51
+ }, backoff .WithMaxRetries ( backoff . NewExponentialBackOff (
55
52
backoff .WithInitialInterval (1 * time .Minute ),
56
- ))
53
+ ), config .SyncMaxErrors .UInt64 ()), func (err error , dur time.Duration ) {
54
+ log .Error ().
55
+ Err (err ).
56
+ Dur ("backoff" , dur ).
57
+ Str ("image" , image .Source ).
58
+ Str ("tag" , tag ).
59
+ Str ("target" , dst ).
60
+ Msg ("Push failed" )
61
+ })
57
62
}
58
63
59
64
func pull (ctx context.Context , puller * remote.Puller , image * structs.Image , tag string ) (* remote.Descriptor , error ) {
@@ -64,17 +69,22 @@ func pull(ctx context.Context, puller *remote.Puller, image *structs.Image, tag
64
69
65
70
var desc * remote.Descriptor
66
71
67
- logs .Progress .Printf ("Fetching %s" , srcTag )
68
-
69
- if err := backoff .Retry (func () error {
72
+ if err := backoff .RetryNotify (func () error {
70
73
desc , err = puller .Get (ctx , srcTag )
71
74
if err != nil {
72
75
return checkRateLimit (err )
73
76
}
74
77
return nil
75
- }, backoff .NewExponentialBackOff (
78
+ }, backoff .WithMaxRetries ( backoff . NewExponentialBackOff (
76
79
backoff .WithInitialInterval (1 * time .Minute ),
77
- )); err != nil {
80
+ ), config .SyncMaxErrors .UInt64 ()), func (err error , dur time.Duration ) {
81
+ log .Error ().
82
+ Err (err ).
83
+ Dur ("backoff" , dur ).
84
+ Str ("image" , image .Source ).
85
+ Str ("tag" , tag ).
86
+ Msg ("Pull failed" )
87
+ }); err != nil {
78
88
return nil , err
79
89
}
80
90
0 commit comments