Skip to content

Commit

Permalink
feat(redis): redis implementation for MetaDB
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Aaron <[email protected]>
  • Loading branch information
andaaron committed Jan 8, 2025
1 parent ff74276 commit cae7e4d
Show file tree
Hide file tree
Showing 4 changed files with 2,277 additions and 146 deletions.
54 changes: 54 additions & 0 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/alicebob/miniredis/v2"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
guuid "github.com/gofrs/uuid"
"github.com/notaryproject/notation-core-go/signature/jws"
Expand All @@ -28,6 +29,7 @@ import (
"zotregistry.dev/zot/pkg/meta/boltdb"
"zotregistry.dev/zot/pkg/meta/common"
mdynamodb "zotregistry.dev/zot/pkg/meta/dynamodb"
"zotregistry.dev/zot/pkg/meta/redisdb"
mTypes "zotregistry.dev/zot/pkg/meta/types"
reqCtx "zotregistry.dev/zot/pkg/requestcontext"
tCommon "zotregistry.dev/zot/pkg/test/common"
Expand Down Expand Up @@ -164,6 +166,35 @@ func TestDynamoDBWrapper(t *testing.T) {
})
}

func TestRedisDB(t *testing.T) {
miniRedis := miniredis.RunT(t)

Convey("RedisDB Wrapper", t, func() {
rootDir := t.TempDir()
log := log.NewLogger("debug", "")

redisDriver, err := redisdb.GetRedisClient("redis://" + miniRedis.Addr())
So(err, ShouldBeNil)

metaDB, err := redisdb.New(redisDriver, log)
So(metaDB, ShouldNotBeNil)
So(err, ShouldBeNil)

imgTrustStore, err := imagetrust.NewLocalImageTrustStore(rootDir)
So(err, ShouldBeNil)

metaDB.SetImageTrustStore(imgTrustStore)

defer func() {
metaDB.ResetDB() //nolint: errcheck
os.RemoveAll(path.Join(rootDir, "_cosign"))
os.RemoveAll(path.Join(rootDir, "_notation"))
}()

RunMetaDBTests(t, metaDB)
})
}

func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func() error) { //nolint: thelper
ctx := context.Background()

Expand Down Expand Up @@ -2577,3 +2608,26 @@ func TestCreateBoltDB(t *testing.T) {
So(err, ShouldNotBeNil)
})
}

func TestCreateRedisDB(t *testing.T) {
Convey("Create", t, func() {
miniRedis := miniredis.RunT(t)

log := log.NewLogger("debug", "")
So(log, ShouldNotBeNil)

redisDriver, err := redisdb.GetRedisClient("redis://" + miniRedis.Addr())
So(err, ShouldBeNil)

metaDB, err := meta.Create("redis", redisDriver, nil, log)
So(metaDB, ShouldNotBeNil)
So(err, ShouldBeNil)
})

Convey("fails", t, func() {
log := log.NewLogger("debug", "")

_, err := meta.Create("redis", nil, mdynamodb.DBDriverParameters{}, log)
So(err, ShouldNotBeNil)
})
}
12 changes: 12 additions & 0 deletions pkg/meta/redisdb/buckets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package redisdb

// MetadataDB.
const (
ImageMetaBuck = "zot:ImageMeta"
RepoMetaBuck = "zot:RepoMeta"
RepoBlobsBuck = "zot:RepoBlobsMeta"
RepoLastUpdatedBuck = "zot:RepoLastUpdated"
UserDataBucket = "zot:UserData"
VersionBucket = "zot:Version"
UserAPIKeysBucket = "zot:UserAPIKeys" //nolint: gosec // these are not hardcoded credentials
)
Loading

0 comments on commit cae7e4d

Please sign in to comment.