mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
92e382ce39
- implement scrub also for S3 storage by replacing umoci - change scrub implementation for ImageIndex - take the `Subject` into consideration when running scrub - remove test code relying on the umoci library. Since we started relying on images in test/data, and we create our own images using go code we can obtain digests by other means. (cherry picked from commit 489d4e2d23c1b4e48799283f8281024bbef6123f) Signed-off-by: Andrei Aaron <aaaron@luxoft.com> Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
//go:build scrub
|
|
// +build scrub
|
|
|
|
package scrub
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
"zotregistry.io/zot/pkg/storage"
|
|
storageTypes "zotregistry.io/zot/pkg/storage/types"
|
|
)
|
|
|
|
// Scrub Extension for repo...
|
|
func RunScrubRepo(ctx context.Context, imgStore storageTypes.ImageStore, repo string, log log.Logger) error {
|
|
execMsg := fmt.Sprintf("executing scrub to check manifest/blob integrity for %s", path.Join(imgStore.RootDir(), repo))
|
|
log.Info().Msg(execMsg)
|
|
|
|
results, err := storage.CheckRepo(ctx, 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)
|
|
log.Info().Msg(fmt.Sprintf("scrub unsuccessfully completed for %s", path.Join(imgStore.RootDir(), repo)))
|
|
|
|
return err
|
|
}
|
|
|
|
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("affected blob", result.AffectedBlob).
|
|
Str("error", result.Error).
|
|
Msg("scrub: blobs/manifest affected")
|
|
}
|
|
}
|
|
|
|
log.Info().Msg(fmt.Sprintf("scrub successfully completed for %s", path.Join(imgStore.RootDir(), repo)))
|
|
|
|
return nil
|
|
}
|
|
|
|
type Task struct {
|
|
imgStore storageTypes.ImageStore
|
|
repo string
|
|
log log.Logger
|
|
}
|
|
|
|
func NewTask(imgStore storageTypes.ImageStore, repo string, log log.Logger) *Task {
|
|
return &Task{imgStore, repo, log}
|
|
}
|
|
|
|
func (scrubT *Task) DoWork(ctx context.Context) error {
|
|
return RunScrubRepo(ctx, scrubT.imgStore, scrubT.repo, scrubT.log) //nolint: contextcheck
|
|
}
|