mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
2402296e9a
* fix: migrate to Go module v2 for proper semantic versioning This change updates the module path from 'zotregistry.dev/zot' to 'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules. According to Go's module versioning requirements, major version v2+ must include the major version in the module path. The current module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x versions, making existing v2.x.x tags (like v2.1.8) unusable. Changes: - Updated go.mod module path to zotregistry.dev/zot/v2 - Updated all internal import paths across 280+ Go source files - Updated configuration files (golangcilint.yaml, gqlgen.yml) - Updated README.md Go reference badge This fix enables proper use of existing v2.x.x Git tags and allows external packages to import zot v2+ versions without compatibility errors. Resolves: Go module import compatibility for v2+ versions Fixes: #3071 Signed-off-by: Luca Muscariello <muscariello@ieee.org> * fix: regenerate GraphQL files with updated v2 import paths The gqlgen tool needs to regenerate the GraphQL schema files after the module path change to use the new v2 imports. Signed-off-by: Luca Muscariello <muscariello@ieee.org> --------- Signed-off-by: Luca Muscariello <muscariello@ieee.org>
154 lines
4.8 KiB
Go
154 lines
4.8 KiB
Go
package meta
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"zotregistry.dev/zot/v2/errors"
|
|
"zotregistry.dev/zot/v2/pkg/api/config"
|
|
rediscfg "zotregistry.dev/zot/v2/pkg/api/config/redis"
|
|
"zotregistry.dev/zot/v2/pkg/log"
|
|
"zotregistry.dev/zot/v2/pkg/meta/boltdb"
|
|
mdynamodb "zotregistry.dev/zot/v2/pkg/meta/dynamodb"
|
|
"zotregistry.dev/zot/v2/pkg/meta/redis"
|
|
mTypes "zotregistry.dev/zot/v2/pkg/meta/types"
|
|
sconstants "zotregistry.dev/zot/v2/pkg/storage/constants"
|
|
)
|
|
|
|
func New(storageConfig config.StorageConfig, log log.Logger) (mTypes.MetaDB, error) {
|
|
if storageConfig.RemoteCache {
|
|
if storageConfig.CacheDriver["name"] == sconstants.DynamoDBDriverName {
|
|
dynamoParams := getDynamoParams(storageConfig.CacheDriver, log)
|
|
|
|
client, err := mdynamodb.GetDynamoClient(dynamoParams)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return mdynamodb.New(client, dynamoParams, log) //nolint:contextcheck
|
|
}
|
|
|
|
if storageConfig.CacheDriver["name"] == sconstants.RedisDriverName {
|
|
redisParams := getRedisParams(storageConfig.CacheDriver, log)
|
|
|
|
client, err := rediscfg.GetRedisClient(storageConfig.CacheDriver, log)
|
|
if err != nil { //nolint:wsl
|
|
return nil, err
|
|
}
|
|
|
|
return redis.New(client, redisParams, log) //nolint:contextcheck
|
|
}
|
|
|
|
// this behavior is also mentioned in the configuration validation logic inside the cli package
|
|
return nil, fmt.Errorf("%w: cachedriver %s and remotecache %t", errors.ErrBadConfig,
|
|
storageConfig.CacheDriver["name"], storageConfig.RemoteCache)
|
|
}
|
|
|
|
if driverName, ok := storageConfig.CacheDriver["name"]; ok && driverName != sconstants.BoltdbName {
|
|
// this behavior is also mentioned in the configuration validation logic inside the cli package
|
|
log.Warn().Interface("cachedriver", driverName).Bool("remotecache", storageConfig.RemoteCache).
|
|
Msg("unsupported cachedriver for remotecache disabled, will default to boltdb")
|
|
}
|
|
|
|
params := boltdb.DBParameters{}
|
|
params.RootDir = storageConfig.RootDirectory
|
|
|
|
driver, err := boltdb.GetBoltDriver(params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return boltdb.New(driver, log) //nolint:contextcheck
|
|
}
|
|
|
|
func getDynamoParams(cacheDriverConfig map[string]interface{}, log log.Logger) mdynamodb.DBDriverParameters {
|
|
allParametersOk := true
|
|
|
|
endpoint, ok := toStringIfOk(cacheDriverConfig, "endpoint", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
region, ok := toStringIfOk(cacheDriverConfig, "region", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
repoMetaTablename, ok := toStringIfOk(cacheDriverConfig, "repometatablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
repoBlobsInfoTablename, ok := toStringIfOk(cacheDriverConfig, "repoblobsinfotablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
imageMetaTablename, ok := toStringIfOk(cacheDriverConfig, "imagemetatablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
apiKeyTablename, ok := toStringIfOk(cacheDriverConfig, "apikeytablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
versionTablename, ok := toStringIfOk(cacheDriverConfig, "versiontablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
userDataTablename, ok := toStringIfOk(cacheDriverConfig, "userdatatablename", "", log)
|
|
allParametersOk = allParametersOk && ok
|
|
|
|
if !allParametersOk {
|
|
log.Panic().Msg("dynamo parameters are not specified correctly, can't proceed")
|
|
}
|
|
|
|
return mdynamodb.DBDriverParameters{
|
|
Endpoint: endpoint,
|
|
Region: region,
|
|
RepoMetaTablename: repoMetaTablename,
|
|
RepoBlobsInfoTablename: repoBlobsInfoTablename,
|
|
ImageMetaTablename: imageMetaTablename,
|
|
UserDataTablename: userDataTablename,
|
|
APIKeyTablename: apiKeyTablename,
|
|
VersionTablename: versionTablename,
|
|
}
|
|
}
|
|
|
|
func getRedisParams(cacheDriverConfig map[string]interface{}, log log.Logger) redis.DBDriverParameters {
|
|
keyPrefix, ok := toStringIfOk(cacheDriverConfig, "keyprefix", "zot", log)
|
|
if !ok {
|
|
log.Panic().Msg("redis parameters are not specified correctly, can't proceed")
|
|
}
|
|
|
|
return redis.DBDriverParameters{
|
|
KeyPrefix: keyPrefix,
|
|
}
|
|
}
|
|
|
|
func toStringIfOk(cacheDriverConfig map[string]interface{},
|
|
param string,
|
|
defaultVal string,
|
|
log log.Logger,
|
|
) (string, bool) {
|
|
val, ok := cacheDriverConfig[param]
|
|
|
|
if !ok && defaultVal != "" {
|
|
log.Info().Str("field", param).Str("default", defaultVal).
|
|
Msg("field is not present in CacheDriver config, using default value")
|
|
|
|
return defaultVal, true
|
|
} else if !ok {
|
|
log.Error().Str("field", param).Msg("failed to parse CacheDriver config, field is not present")
|
|
|
|
return "", false
|
|
}
|
|
|
|
str, ok := val.(string)
|
|
if !ok {
|
|
log.Error().Str("parameter", param).Msg("failed to parse CacheDriver config, parameter isn't a string")
|
|
|
|
return "", false
|
|
}
|
|
|
|
if str == "" {
|
|
log.Error().Str("field", param).Msg("failed to parse CacheDriver config, field is empty")
|
|
|
|
return "", false
|
|
}
|
|
|
|
return str, true
|
|
}
|
|
|
|
func Close(metadb mTypes.MetaDB) error {
|
|
return metadb.Close()
|
|
}
|