2022-04-27 01:00:20 -05:00
|
|
|
//go:build scrub
|
|
|
|
// +build scrub
|
2022-03-04 02:37:06 -05:00
|
|
|
|
|
|
|
package scrub
|
|
|
|
|
|
|
|
import (
|
2023-09-05 11:48:56 -05:00
|
|
|
"context"
|
2022-05-09 17:30:11 -05:00
|
|
|
"fmt"
|
|
|
|
"path"
|
2022-03-04 02:37:06 -05:00
|
|
|
|
2024-01-31 23:34:07 -05:00
|
|
|
"zotregistry.dev/zot/pkg/log"
|
|
|
|
"zotregistry.dev/zot/pkg/storage"
|
|
|
|
storageTypes "zotregistry.dev/zot/pkg/storage/types"
|
2022-03-04 02:37:06 -05:00
|
|
|
)
|
|
|
|
|
2022-05-09 17:30:11 -05:00
|
|
|
// Scrub Extension for repo...
|
2023-09-05 11:48:56 -05:00
|
|
|
func RunScrubRepo(ctx context.Context, imgStore storageTypes.ImageStore, repo string, log log.Logger) error {
|
2024-07-29 12:32:51 -05:00
|
|
|
execMsg := "executing scrub to check manifest/blob integrity for " + path.Join(imgStore.RootDir(), repo)
|
2022-05-09 17:30:11 -05:00
|
|
|
log.Info().Msg(execMsg)
|
2022-03-04 02:37:06 -05:00
|
|
|
|
2023-09-05 11:48:56 -05:00
|
|
|
results, err := storage.CheckRepo(ctx, repo, imgStore)
|
2022-05-09 17:30:11 -05:00
|
|
|
if err != nil {
|
2024-07-29 12:32:51 -05:00
|
|
|
errMessage := "failed to run scrub for " + path.Join(imgStore.RootDir(), repo)
|
2022-05-09 17:30:11 -05:00
|
|
|
log.Error().Err(err).Msg(errMessage)
|
2024-07-29 12:32:51 -05:00
|
|
|
log.Info().Msg("scrub unsuccessfully completed for " + path.Join(imgStore.RootDir(), repo))
|
2022-09-23 00:27:56 -05:00
|
|
|
|
|
|
|
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).
|
2023-12-08 03:05:02 -05:00
|
|
|
Str("component", "scrub").
|
|
|
|
Msg("blobs/manifest ok")
|
2022-05-09 17:30:11 -05:00
|
|
|
} else {
|
|
|
|
log.Warn().
|
|
|
|
Str("image", result.ImageName).
|
|
|
|
Str("tag", result.Tag).
|
|
|
|
Str("status", result.Status).
|
2023-09-26 13:02:11 -05:00
|
|
|
Str("affected blob", result.AffectedBlob).
|
2022-05-09 17:30:11 -05:00
|
|
|
Str("error", result.Error).
|
2023-12-08 03:05:02 -05:00
|
|
|
Str("component", "scrub").
|
|
|
|
Msg("blobs/manifest affected")
|
2022-03-04 02:37:06 -05:00
|
|
|
}
|
|
|
|
}
|
2022-05-09 17:30:11 -05:00
|
|
|
|
2024-07-29 12:32:51 -05:00
|
|
|
log.Info().Msg("scrub successfully completed for " + path.Join(imgStore.RootDir(), repo))
|
2022-09-23 00:27:56 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Task struct {
|
2023-05-26 13:08:19 -05:00
|
|
|
imgStore storageTypes.ImageStore
|
2022-09-23 00:27:56 -05:00
|
|
|
repo string
|
|
|
|
log log.Logger
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:08:19 -05:00
|
|
|
func NewTask(imgStore storageTypes.ImageStore, repo string, log log.Logger) *Task {
|
2022-09-23 00:27:56 -05:00
|
|
|
return &Task{imgStore, repo, log}
|
|
|
|
}
|
|
|
|
|
2023-09-05 11:48:56 -05:00
|
|
|
func (scrubT *Task) DoWork(ctx context.Context) error {
|
|
|
|
return RunScrubRepo(ctx, scrubT.imgStore, scrubT.repo, scrubT.log) //nolint: contextcheck
|
2022-03-04 02:37:06 -05:00
|
|
|
}
|
2023-12-04 17:13:50 -05:00
|
|
|
|
|
|
|
func (scrubT *Task) String() string {
|
|
|
|
return fmt.Sprintf("{taskGenerator: \"%s\", repo: \"%s\"}",
|
|
|
|
"image scrub", // description of generator's task purpose
|
|
|
|
scrubT.repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scrubT *Task) Name() string {
|
|
|
|
return "ScrubTask"
|
|
|
|
}
|