2022-04-27 01:00:20 -05:00
|
|
|
//go:build sync
|
|
|
|
// +build sync
|
|
|
|
|
|
|
|
package extensions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/sync"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
2023-03-09 13:41:48 -05:00
|
|
|
"zotregistry.io/zot/pkg/meta/repodb"
|
2022-04-27 01:00:20 -05:00
|
|
|
"zotregistry.io/zot/pkg/storage"
|
|
|
|
)
|
|
|
|
|
2023-03-29 13:37:58 -05:00
|
|
|
func EnableSyncExtension(ctx context.Context, config *config.Config,
|
2023-03-09 13:41:48 -05:00
|
|
|
repoDB repodb.RepoDB, storeController storage.StoreController, log log.Logger,
|
2022-04-27 01:00:20 -05:00
|
|
|
) {
|
|
|
|
if config.Extensions.Sync != nil && *config.Extensions.Sync.Enable {
|
2023-03-29 13:37:58 -05:00
|
|
|
if err := sync.Run(ctx, *config.Extensions.Sync, repoDB, storeController, log); err != nil {
|
2022-04-27 01:00:20 -05:00
|
|
|
log.Error().Err(err).Msg("Error encountered while setting up syncing")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Info().Msg("Sync registries config not provided or disabled, skipping sync")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-09 13:41:48 -05:00
|
|
|
func SyncOneImage(ctx context.Context, config *config.Config, repoDB repodb.RepoDB,
|
|
|
|
storeController storage.StoreController, repoName, reference string, artifactType string, log log.Logger,
|
2022-04-27 01:00:20 -05:00
|
|
|
) error {
|
2023-04-27 21:44:22 -05:00
|
|
|
log.Info().Str("repository", repoName).Str("reference", reference).Msg("syncing image")
|
2022-04-27 01:00:20 -05:00
|
|
|
|
2023-03-09 13:41:48 -05:00
|
|
|
err := sync.OneImage(ctx, *config.Extensions.Sync, repoDB, storeController, repoName, reference, artifactType, log)
|
2022-04-27 01:00:20 -05:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|