mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
redis driver for blob cache information and metadb (#2865)
* feat: add redis cache support https://github.com/project-zot/zot/pull/2005 Fixes https://github.com/project-zot/zot/issues/2004 * feat: add redis cache support Currently, we have dynamoDB as the remote shared cache but ideal only for the cloud use case. For on-prem use case, add support for redis. Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> * feat(redis): added blackbox tests for redis Signed-off-by: Petu Eusebiu <peusebiu@cisco.com> * feat(redis): dummy implementation of MetaDB interface for redis cache Signed-off-by: Alexei Dodon <adodon@cisco.com> * feat: check validity of driver configuration on metadb instantiation Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat: multiple fixes for redis cache driver implementation - add missing method GetAllBlobs - add redis cache tests, with and without mocking Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): redis implementation for MetaDB Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): use redsync to block concurrent write access to the redis DB Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): update .github/workflows/cluster.yaml to also test redis Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(metadb): add keyPrefix parameter for redis and remove unneeded method meta.Crate() Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): support RedisCluster configuration and add unit tests Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): more tests for redis metadb implementation Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): add more examples and update examples/README.md Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): move option parsing and redis client initialization under pkg/api/config/redis Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * chore(cachedb): move Cache interface to pkg/storage/types Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): reorganize code in pkg/storage/cache.go Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): call redis.SetLogger() with the zot logger as parameter Signed-off-by: Andrei Aaron <aaaron@luxoft.com> * feat(redis): rename pkg/meta/redisdb to pkg/meta/redis Signed-off-by: Andrei Aaron <aaaron@luxoft.com> --------- Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> Signed-off-by: Petu Eusebiu <peusebiu@cisco.com> Signed-off-by: Alexei Dodon <adodon@cisco.com> Signed-off-by: Andrei Aaron <aaaron@luxoft.com> Co-authored-by: a <a@tuxpa.in> Co-authored-by: Ramkumar Chinchani <rchincha@cisco.com> Co-authored-by: Petu Eusebiu <peusebiu@cisco.com> Co-authored-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
@@ -900,6 +900,36 @@ The following AWS policy is required by zot for caching blobs. Make sure to repl
|
||||
]
|
||||
}
|
||||
|
||||
### Redis
|
||||
|
||||
Redis is an alternative to BoltDB (which cannot be shared by multiple zot instances) and DynamoDB (requires access to AWS).
|
||||
Redis can be set up using a configuration similar to the one below:
|
||||
|
||||
```json
|
||||
"storage": {
|
||||
"rootDirectory": "/tmp/zot",
|
||||
"remoteCache": true,
|
||||
"cacheDriver": {
|
||||
"name": "redis",
|
||||
"url": "redis://localhost:6379",
|
||||
"keyprefix": "zot"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The "name" setting selects the Redis driver implementation.
|
||||
The "keyprefix" is a string prepended to all Redis keys created by this zot instance.
|
||||
The "url" setting points to the Redis server (or servers in the case of a Redis cluster).
|
||||
More details on how this is parsed are available at:
|
||||
- https://github.com/redis/go-redis/blob/v9.7.0/options.go#L247
|
||||
- https://github.com/redis/go-redis/blob/v9.7.0/osscluster.go#L144
|
||||
|
||||
If the "url" setting is missing, the parameters need to be passed individually as keys in the same "cacheDriver" map.
|
||||
The keys are the same as the attributes that would otherwise be included in the "url".
|
||||
Note that at this time the library we import only supports "url" parsing in the case of a Redis single instance, or cluster configuration.
|
||||
In the case of a Redis Sentinel setup, you would need to add each key manually in the "cacheDriver" map and make sure to specify
|
||||
a "master_name" key, see https://github.com/redis/go-redis/blob/v9.7.0/universal.go#L240
|
||||
|
||||
## Sync
|
||||
|
||||
Enable and configure sync with:
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"distSpecVersion": "1.1.0",
|
||||
"storage": {
|
||||
"dedupe": true,
|
||||
"gc": true,
|
||||
"rootDirectory": "/tmp/zot",
|
||||
"cacheDriver": {
|
||||
"name": "redis",
|
||||
"keyprefix": "zot",
|
||||
"addr": ["host1:6379", "host2:6379", "host3:6379"],
|
||||
"client_name": "client",
|
||||
"db": 1,
|
||||
"protocol": 3,
|
||||
"username": "user1",
|
||||
"password": "pass1",
|
||||
"sentinel_username": "user2",
|
||||
"sentinel_password": "pass2",
|
||||
"max_retries": 3,
|
||||
"min_retry_backoff": "5s",
|
||||
"max_retry_backoff": "5s",
|
||||
"dial_timeout": "5s",
|
||||
"read_timeout": "5s",
|
||||
"write_timeout": "5s",
|
||||
"context_timeout_enabled": false,
|
||||
"pool_fifo": false,
|
||||
"pool_size": 3,
|
||||
"pool_timeout": "5s",
|
||||
"min_idle_conns": 1,
|
||||
"max_idle_conns": 3,
|
||||
"max_active_conns": 3,
|
||||
"conn_max_idle_time": "5s",
|
||||
"conn_max_lifetime": "5s",
|
||||
"max_redirects": 3,
|
||||
"read_only": false,
|
||||
"route_by_latency": false,
|
||||
"route_randomly": false,
|
||||
"master_name": "zotmeta",
|
||||
"disable_identity": false,
|
||||
"identity_suffix": "zotmeta",
|
||||
"unstable_resp3": false
|
||||
},
|
||||
"storageDriver": {
|
||||
"name": "s3",
|
||||
"rootdirectory": "/zot",
|
||||
"region": "us-east-2",
|
||||
"regionendpoint": "localhost:4566",
|
||||
"bucket": "zot-storage",
|
||||
"forcepathstyle": true,
|
||||
"secure": false,
|
||||
"skipverify": false
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"address": "0.0.0.0",
|
||||
"port": "8484"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": true
|
||||
},
|
||||
"search": {
|
||||
"enable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"distSpecVersion": "1.1.0",
|
||||
"storage": {
|
||||
"dedupe": true,
|
||||
"gc": true,
|
||||
"rootDirectory": "/tmp/zot",
|
||||
"cacheDriver": {
|
||||
"name": "redis",
|
||||
"url": "redis://user:password@host1:6379?dial_timeout=3&read_timeout=6s&addr=host2:6379&addr=host3:6379",
|
||||
"keyprefix": "zot"
|
||||
},
|
||||
"storageDriver": {
|
||||
"name": "s3",
|
||||
"rootdirectory": "/zot",
|
||||
"region": "us-east-2",
|
||||
"regionendpoint": "localhost:4566",
|
||||
"bucket": "zot-storage",
|
||||
"forcepathstyle": true,
|
||||
"secure": false,
|
||||
"skipverify": false
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"address": "0.0.0.0",
|
||||
"port": "8484"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": true
|
||||
},
|
||||
"search": {
|
||||
"enable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"distSpecVersion": "1.1.0",
|
||||
"storage": {
|
||||
"dedupe": true,
|
||||
"gc": true,
|
||||
"rootDirectory": "/tmp/zot",
|
||||
"cacheDriver": {
|
||||
"name": "redis",
|
||||
"url": "redis://localhost:6379",
|
||||
"keyprefix": "zot"
|
||||
},
|
||||
"storageDriver": {
|
||||
"name": "s3",
|
||||
"rootdirectory": "/zot",
|
||||
"region": "us-east-2",
|
||||
"regionendpoint": "localhost:4566",
|
||||
"bucket": "zot-storage",
|
||||
"forcepathstyle": true,
|
||||
"secure": false,
|
||||
"skipverify": false
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"address": "0.0.0.0",
|
||||
"port": "8484"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": true
|
||||
},
|
||||
"search": {
|
||||
"enable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user