-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (55 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dockersync
import (
"context"
"time"
"github.com/Altinity/docker-sync/config"
"github.com/Altinity/docker-sync/internal/sync"
"github.com/Altinity/docker-sync/internal/telemetry"
"github.com/Altinity/docker-sync/structs"
"github.com/rs/zerolog/log"
"go.uber.org/multierr"
)
func Run(ctx context.Context) error {
if config.TelemetryEnabled.Bool() {
go func() {
if err := telemetry.Start(ctx); err != nil {
log.Error().
Err(err).
Msg("Failed to start telemetry")
}
}()
}
images := config.SyncImages.Images()
for {
if err := RunOnce(ctx, images); err != nil {
return err
}
dur := config.SyncInterval.Duration()
log.Info().Dur("interval", dur).Msg("Waiting for next sync")
time.Sleep(dur)
}
}
func RunOnce(ctx context.Context, images []*structs.Image) error {
var merr error
for k := range images {
select {
case <-ctx.Done():
return nil
default:
image := images[k]
if err := sync.SyncImage(ctx, image); err != nil {
log.Error().
Err(err).
Str("source", image.Source).
Msg("Failed to sync image")
merr = multierr.Append(merr, err)
if config.SyncMaxErrors.Int() > 0 {
if len(multierr.Errors(merr)) >= config.SyncMaxErrors.Int() {
return merr
}
}
}
}
}
return nil
}