mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
Update dist-spec version automatically
Warning if config has wrong dist-spec version Signed-off-by: laurentiuNiculae <themelopeus@gmail.com>
This commit is contained in:
parent
fa27e22404
commit
63d94d4ac5
25 changed files with 108 additions and 40 deletions
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot"
|
"rootDirectory":"/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot",
|
"rootDirectory": "/tmp/zot",
|
||||||
"commit": true
|
"commit": true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot",
|
"rootDirectory":"/tmp/zot",
|
||||||
"gc": false,
|
"gc": false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot"
|
"rootDirectory":"/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
version:
|
distSpecVersion:
|
||||||
0.1.0-dev
|
0.1.0-dev
|
||||||
storage:
|
storage:
|
||||||
rootDirectory: /tmp/zot
|
rootDirectory: /tmp/zot
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot",
|
"rootDirectory": "/tmp/zot",
|
||||||
"gc": true,
|
"gc": true,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot",
|
"rootDirectory": "/tmp/zot",
|
||||||
"dedupe": true,
|
"dedupe": true,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot",
|
"rootDirectory": "/tmp/zot",
|
||||||
"dedupe": true,
|
"dedupe": true,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/tmp/zot"
|
"rootDirectory": "/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/zot",
|
"rootDirectory": "/zot",
|
||||||
"storageDriver": {
|
"storageDriver": {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot"
|
"rootDirectory":"/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot"
|
"rootDirectory":"/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version":"0.1.0-dev",
|
"distSpecVersion":"1.0.0",
|
||||||
"storage":{
|
"storage":{
|
||||||
"rootDirectory":"/tmp/zot"
|
"rootDirectory":"/tmp/zot"
|
||||||
},
|
},
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -33,7 +33,6 @@ require (
|
||||||
github.com/notaryproject/notation v0.7.0-alpha.1
|
github.com/notaryproject/notation v0.7.0-alpha.1
|
||||||
github.com/notaryproject/notation-go-lib v1.0.0-alpha-1
|
github.com/notaryproject/notation-go-lib v1.0.0-alpha-1
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
github.com/olekukonko/tablewriter v0.0.5
|
||||||
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220217185014-dd38b7ed8a99
|
|
||||||
github.com/opencontainers/go-digest v1.0.0
|
github.com/opencontainers/go-digest v1.0.0
|
||||||
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
|
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
|
||||||
github.com/opencontainers/umoci v0.4.8-0.20210922062158-e60a0cc726e6
|
github.com/opencontainers/umoci v0.4.8-0.20210922062158-e60a0cc726e6
|
||||||
|
@ -287,6 +286,7 @@ require (
|
||||||
github.com/oklog/run v1.1.0 // indirect
|
github.com/oklog/run v1.1.0 // indirect
|
||||||
github.com/oklog/ulid v1.3.1 // indirect
|
github.com/oklog/ulid v1.3.1 // indirect
|
||||||
github.com/open-policy-agent/opa v0.37.0 // indirect
|
github.com/open-policy-agent/opa v0.37.0 // indirect
|
||||||
|
github.com/opencontainers/distribution-spec v1.0.0
|
||||||
github.com/opencontainers/runc v1.1.0 // indirect
|
github.com/opencontainers/runc v1.1.0 // indirect
|
||||||
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
|
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -2023,8 +2023,8 @@ github.com/open-policy-agent/opa v0.32.0/go.mod h1:5sJdtc+1/U8zy/j30njpQl6u9rM4M
|
||||||
github.com/open-policy-agent/opa v0.35.0/go.mod h1:xEmekKlk6/c+so5HF9wtPnGPXDfBuBsrMGhSHOHEF+U=
|
github.com/open-policy-agent/opa v0.35.0/go.mod h1:xEmekKlk6/c+so5HF9wtPnGPXDfBuBsrMGhSHOHEF+U=
|
||||||
github.com/open-policy-agent/opa v0.37.0 h1:OUXB+RAcxQpmXeNW2BN1wYzQQvVCPF1T9zv+QXGr9Wg=
|
github.com/open-policy-agent/opa v0.37.0 h1:OUXB+RAcxQpmXeNW2BN1wYzQQvVCPF1T9zv+QXGr9Wg=
|
||||||
github.com/open-policy-agent/opa v0.37.0/go.mod h1:xX3NUCZuXK8f0CNhFQvhm4495mZLptf94pIkWRLaFqo=
|
github.com/open-policy-agent/opa v0.37.0/go.mod h1:xX3NUCZuXK8f0CNhFQvhm4495mZLptf94pIkWRLaFqo=
|
||||||
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220217185014-dd38b7ed8a99 h1:yGqpYh1h3ZXxGg4Mqd5ZwhlwQ9wXOgvuodxbxJA7iMY=
|
github.com/opencontainers/distribution-spec v1.0.0 h1:3qi5mXdKrXCacBYm8y46okmGmCR0pSgfaEd2/T0QXWE=
|
||||||
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220217185014-dd38b7ed8a99/go.mod h1:aA4vdXRS8E1TG7pLZOz85InHi3BiPdErh8IpJN6E0x4=
|
github.com/opencontainers/distribution-spec v1.0.0/go.mod h1:copR2flp+jTEvQIFMb6MIx45OkrxzqyjszPDT3hx/5Q=
|
||||||
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
|
|
|
@ -122,26 +122,26 @@ type Policy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string
|
DistSpecVersion string `json:"distSpecVersion" mapstructure:"distSpecVersion"`
|
||||||
GoVersion string
|
GoVersion string
|
||||||
Commit string
|
Commit string
|
||||||
BinaryType string
|
BinaryType string
|
||||||
AccessControl *AccessControlConfig
|
AccessControl *AccessControlConfig
|
||||||
Storage GlobalStorageConfig
|
Storage GlobalStorageConfig
|
||||||
HTTP HTTPConfig
|
HTTP HTTPConfig
|
||||||
Log *LogConfig
|
Log *LogConfig
|
||||||
Extensions *extconf.ExtensionConfig
|
Extensions *extconf.ExtensionConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Config {
|
func New() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Version: distspec.Version,
|
DistSpecVersion: distspec.Version,
|
||||||
GoVersion: GoVersion,
|
GoVersion: GoVersion,
|
||||||
Commit: Commit,
|
Commit: Commit,
|
||||||
BinaryType: BinaryType,
|
BinaryType: BinaryType,
|
||||||
Storage: GlobalStorageConfig{GC: true, GCDelay: storage.DefaultGCDelay, Dedupe: true},
|
Storage: GlobalStorageConfig{GC: true, GCDelay: storage.DefaultGCDelay, Dedupe: true},
|
||||||
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
||||||
Log: &LogConfig{Level: "debug"},
|
Log: &LogConfig{Level: "debug"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,9 @@ func (c *Controller) Run() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
monitoring.SetServerInfo(c.Metrics, c.Config.Commit, c.Config.BinaryType, c.Config.GoVersion, c.Config.Version)
|
monitoring.SetServerInfo(c.Metrics, c.Config.Commit, c.Config.BinaryType, c.Config.GoVersion,
|
||||||
|
c.Config.DistSpecVersion)
|
||||||
|
|
||||||
_ = NewRouteHandler(c)
|
_ = NewRouteHandler(c)
|
||||||
|
|
||||||
addr := fmt.Sprintf("%s:%s", c.Config.HTTP.Address, c.Config.HTTP.Port)
|
addr := fmt.Sprintf("%s:%s", c.Config.HTTP.Address, c.Config.HTTP.Port)
|
||||||
|
|
|
@ -363,6 +363,23 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.DistSpecVersion != distspec.Version {
|
||||||
|
log.Warn().Err(errors.ErrBadConfig).
|
||||||
|
Msgf("config dist-spec version: %s differs from version actually used: %s, will be corrected automatically",
|
||||||
|
config.DistSpecVersion, distspec.Version)
|
||||||
|
|
||||||
|
// rewrite the config file
|
||||||
|
viperInstance.Set("distSpecVersion", distspec.Version)
|
||||||
|
|
||||||
|
err := viperInstance.WriteConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Err(errors.ErrBadConfig).
|
||||||
|
Msg("can't rewrite the config file")
|
||||||
|
}
|
||||||
|
|
||||||
|
config.DistSpecVersion = distspec.Version
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfiguration(config *config.Config, configPath string) {
|
func LoadConfiguration(config *config.Config, configPath string) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
distspec "github.com/opencontainers/distribution-spec/specs-go"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"gopkg.in/resty.v1"
|
"gopkg.in/resty.v1"
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
|
@ -282,7 +283,7 @@ func TestVerify(t *testing.T) {
|
||||||
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
|
tmpfile, err := ioutil.TempFile("", "zot-test*.json")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer os.Remove(tmpfile.Name()) // clean up
|
defer os.Remove(tmpfile.Name()) // clean up
|
||||||
content := []byte(`{"version": "0.1.0-dev", "storage": {"rootDirectory": "/tmp/zot"},
|
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot"},
|
||||||
"http": {"address": "127.0.0.1", "port": "8080", "ReadOnly": false},
|
"http": {"address": "127.0.0.1", "port": "8080", "ReadOnly": false},
|
||||||
"log": {"level": "debug"}}`)
|
"log": {"level": "debug"}}`)
|
||||||
_, err = tmpfile.Write(content)
|
_, err = tmpfile.Write(content)
|
||||||
|
@ -527,3 +528,51 @@ func TestScrub(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyDefaultValues(t *testing.T) {
|
||||||
|
Convey("Test rewriting of config file if version is wrong", t, func() {
|
||||||
|
configContent := []byte(`{"distSpecVersion": "1.0.0555", "storage": {"rootDirectory": "/tmp/zot"},
|
||||||
|
"http": {"address": "127.0.0.1", "port": "8080", "ReadOnly": false},
|
||||||
|
"log": {"level": "debug"}}
|
||||||
|
`)
|
||||||
|
oldConfig := config.New()
|
||||||
|
|
||||||
|
file, err := ioutil.TempFile("", "default-val-test-config*.json")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
defer os.Remove(file.Name())
|
||||||
|
_, err = file.Write(configContent)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
Convey("The file can be rewritten", func() {
|
||||||
|
err = os.Chmod(file.Name(), 0o777)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
cli.LoadConfiguration(oldConfig, file.Name())
|
||||||
|
|
||||||
|
configContent, err = ioutil.ReadFile(file.Name())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
newConfig := config.New()
|
||||||
|
err = json.Unmarshal(configContent, newConfig)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(newConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||||
|
So(newConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("The file can't be rewritten", func() {
|
||||||
|
err = os.Chmod(file.Name(), 0o444)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
cli.LoadConfiguration(oldConfig, file.Name())
|
||||||
|
|
||||||
|
configContent, err = ioutil.ReadFile(file.Name())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
newConfig := config.New()
|
||||||
|
err = json.Unmarshal(configContent, newConfig)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(newConfig.DistSpecVersion, ShouldEqual, "1.0.0555")
|
||||||
|
So(oldConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.0-dev",
|
"distSpecVersion": "1.0.0",
|
||||||
"storage": {
|
"storage": {
|
||||||
"rootDirectory": "/zot",
|
"rootDirectory": "/zot",
|
||||||
"gc": false,
|
"gc": false,
|
||||||
|
|
Loading…
Reference in a new issue