2022-04-27 01:00:20 -05:00
|
|
|
//go:build scrub
|
|
|
|
// +build scrub
|
2022-03-04 02:37:06 -05:00
|
|
|
|
|
|
|
package scrub
|
|
|
|
|
|
|
|
import (
|
2022-05-09 17:30:11 -05:00
|
|
|
"fmt"
|
|
|
|
"path"
|
2022-03-04 02:37:06 -05:00
|
|
|
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
"zotregistry.io/zot/pkg/storage"
|
|
|
|
)
|
|
|
|
|
2022-05-09 17:30:11 -05:00
|
|
|
// Scrub Extension for repo...
|
2022-09-23 00:27:56 -05:00
|
|
|
func RunScrubRepo(imgStore storage.ImageStore, repo string, log log.Logger) error {
|
2022-05-09 17:30:11 -05:00
|
|
|
execMsg := fmt.Sprintf("executing scrub to check manifest/blob integrity for %s", path.Join(imgStore.RootDir(), repo))
|
|
|
|
log.Info().Msg(execMsg)
|
2022-03-04 02:37:06 -05:00
|
|
|
|
2022-05-09 17:30:11 -05:00
|
|
|
results, err := storage.CheckRepo(repo, imgStore)
|
|
|
|
if err != nil {
|
|
|
|
errMessage := fmt.Sprintf("error while running scrub for %s", path.Join(imgStore.RootDir(), repo))
|
|
|
|
log.Error().Err(err).Msg(errMessage)
|
2022-09-23 00:27:56 -05:00
|
|
|
log.Info().Msg(fmt.Sprintf("scrub unsuccessfully completed for %s", path.Join(imgStore.RootDir(), repo)))
|
|
|
|
|
|
|
|
return err
|
2022-05-09 17:30:11 -05:00
|
|
|
}
|
2022-03-04 02:37:06 -05:00
|
|
|
|
2022-05-09 17:30:11 -05:00
|
|
|
for _, result := range results {
|
|
|
|
if result.Status == "ok" {
|
|
|
|
log.Info().
|
|
|
|
Str("image", result.ImageName).
|
|
|
|
Str("tag", result.Tag).
|
|
|
|
Str("status", result.Status).
|
|
|
|
Msg("scrub: blobs/manifest ok")
|
|
|
|
} else {
|
|
|
|
log.Warn().
|
|
|
|
Str("image", result.ImageName).
|
|
|
|
Str("tag", result.Tag).
|
|
|
|
Str("status", result.Status).
|
|
|
|
Str("error", result.Error).
|
|
|
|
Msg("scrub: blobs/manifest affected")
|
2022-03-04 02:37:06 -05:00
|
|
|
}
|
|
|
|
}
|
2022-05-09 17:30:11 -05:00
|
|
|
|
2022-09-23 00:27:56 -05:00
|
|
|
log.Info().Msg(fmt.Sprintf("scrub successfully completed for %s", path.Join(imgStore.RootDir(), repo)))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Task struct {
|
|
|
|
imgStore storage.ImageStore
|
|
|
|
repo string
|
|
|
|
log log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTask(imgStore storage.ImageStore, repo string, log log.Logger) *Task {
|
|
|
|
return &Task{imgStore, repo, log}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scrubT *Task) DoWork() error {
|
|
|
|
return RunScrubRepo(scrubT.imgStore, scrubT.repo, scrubT.log)
|
2022-03-04 02:37:06 -05:00
|
|
|
}
|