diff --git a/.travis.yml b/.travis.yml index e73c222a..0a26fca9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget -N https://github.com/bazelbuild/bazel/releases/download/3.0.0/bazel-3.0.0-installer-linux-x86_64.sh && chmod +x bazel-3.0.0-installer-linux-x86_64.sh && ./bazel-3.0.0-installer-linux-x86_64.sh --user; go get -u github.com/swaggo/swag/cmd/swag; go mod download; sudo apt-get update; sudo apt-get install rpm; sudo apt install snapd; sudo snap install skopeo --edge --devmode; fi script: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_wait make && travis_wait make -f Makefile.bazel build; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then travis_wait 40 make && travis_wait 40 make -f Makefile.bazel build; fi after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/codecov.yml b/codecov.yml index 09aaabed..475ebafa 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,4 +1,6 @@ ignore: - "*_gen.go" - "./pkg/extensions/search/*_gen.go" - - "./pkg/extensions/search/generated.go" \ No newline at end of file + - "./pkg/extensions/search/generated.go" + - "./pkg/extensions/minimal.go" + - "./pkg/cli/minimal.go" \ No newline at end of file diff --git a/pkg/api/controller.go b/pkg/api/controller.go index e10812be..40f9422b 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -50,9 +50,9 @@ func (c *Controller) Run() error { os.Exit(1) } - // Updating the CVE Database - if c.Config != nil { - ext.EnableExtension(c.Config.Extensions, c.Log, c.Config.Storage.RootDirectory) + // Enable extensions if extension config is provided + if c.Config != nil && c.Config.Extensions != nil { + ext.EnableExtensions(c.Config.Extensions, c.Log, c.Config.Storage.RootDirectory) } c.Router = engine diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 08c70613..99817cdb 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -88,7 +88,7 @@ func (rh *RouteHandler) SetupRoutes() { } // swagger docs "/swagger/v2/index.html" rh.c.Router.PathPrefix("/swagger/v2/").Methods("GET").Handler(httpSwagger.WrapHandler) - // Zot Search Extension Router + // Setup Extensions Routes if rh.c.Config != nil && rh.c.Config.Extensions != nil { ext.SetupRoutes(rh.c.Router, rh.c.Config.Storage.RootDirectory, rh.c.ImageStore, rh.c.Log) } diff --git a/pkg/extensions/BUILD.bazel b/pkg/extensions/BUILD.bazel index 7077b6d2..ee8f2feb 100644 --- a/pkg/extensions/BUILD.bazel +++ b/pkg/extensions/BUILD.bazel @@ -4,7 +4,7 @@ go_library( name = "go_default_library", srcs = [ "config.go", - "extension.go", + "extensions.go", "minimal.go", ], importpath = "github.com/anuvu/zot/pkg/extensions", diff --git a/pkg/extensions/extension.go b/pkg/extensions/extensions.go similarity index 71% rename from pkg/extensions/extension.go rename to pkg/extensions/extensions.go index 774fc081..f2d96abc 100644 --- a/pkg/extensions/extension.go +++ b/pkg/extensions/extensions.go @@ -16,24 +16,24 @@ import ( ) // DownloadTrivyDB ... -func DownloadTrivyDB(dbDir string, log log.Logger, updateInterval time.Duration) error { +func downloadTrivyDB(dbDir string, log log.Logger, updateInterval time.Duration) error { for { - log.Info().Msg("Updating the CVE database") + log.Info().Msg("updating the CVE database") err := cveinfo.UpdateCVEDb(dbDir, log) if err != nil { return err } - log.Info().Str("Db update completed, next update scheduled after", updateInterval.String()).Msg("") + log.Info().Str("DB update completed, next update scheduled after", updateInterval.String()).Msg("") time.Sleep(updateInterval) } } -func EnableExtension(extension *ExtensionConfig, log log.Logger, rootDir string) { - if extension != nil && extension.Search != nil && - extension.Search.CVE != nil { +// EnableExtensions ... +func EnableExtensions(extension *ExtensionConfig, log log.Logger, rootDir string) { + if extension.Search != nil && extension.Search.CVE != nil { defaultUpdateInterval, _ := time.ParseDuration("2h") if extension.Search.CVE.UpdateInterval < defaultUpdateInterval { @@ -43,18 +43,20 @@ func EnableExtension(extension *ExtensionConfig, log log.Logger, rootDir string) } go func() { - err := DownloadTrivyDB(rootDir, log, + err := downloadTrivyDB(rootDir, log, extension.Search.CVE.UpdateInterval) if err != nil { panic(err) } }() } else { - log.Info().Msg("Cve config not provided, skipping cve update") + log.Info().Msg("CVE config not provided, skipping CVE update") } } +// SetupRoutes ... func SetupRoutes(router *mux.Router, rootDir string, imgStore *storage.ImageStore, log log.Logger) { + log.Info().Msg("setting up extensions routes") resConfig := search.GetResolverConfig(rootDir, log, imgStore) router.PathPrefix("/query").Methods("GET", "POST"). Handler(gqlHandler.NewDefaultServer(search.NewExecutableSchema(resConfig))) diff --git a/pkg/extensions/minimal.go b/pkg/extensions/minimal.go index 907751b9..f1e2967a 100644 --- a/pkg/extensions/minimal.go +++ b/pkg/extensions/minimal.go @@ -11,13 +11,16 @@ import ( ) // DownloadTrivyDB ... -func DownloadTrivyDB(dbDir string, log log.Logger, updateInterval time.Duration) error { +func downloadTrivyDB(dbDir string, log log.Logger, updateInterval time.Duration) error { return nil } -func EnableExtension(extension *ExtensionConfig, log log.Logger, rootDir string) { - log.Info().Msg("given zot binary doesn't support any extensions, please build zot full binary for this feature") +// EnableExtensions ... +func EnableExtensions(extension *ExtensionConfig, log log.Logger, rootDir string) { + log.Warn().Msg("skipping enabling extensions because given zot binary doesn't support any extensions, please build zot full binary for this feature") } +// SetupRoutes ... func SetupRoutes(router *mux.Router, rootDir string, imgStore *storage.ImageStore, log log.Logger) { + log.Warn().Msg("skipping setting up extensions routes because given zot binary doesn't support any extensions, please build zot full binary for this feature") } diff --git a/pkg/extensions/search/cve/cve_test.go b/pkg/extensions/search/cve/cve_test.go index 2f8cfba5..8f6f76df 100644 --- a/pkg/extensions/search/cve/cve_test.go +++ b/pkg/extensions/search/cve/cve_test.go @@ -684,3 +684,46 @@ func TestCVESearch(t *testing.T) { So(resp.StatusCode(), ShouldEqual, 200) }) } + +func TestCVEConfig(t *testing.T) { + Convey("Verify CVE config", t, func() { + config := api.NewConfig() + config.HTTP.Port = SecurePort1 + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) + + config.HTTP.Auth = &api.AuthConfig{ + HTPasswd: api.AuthHTPasswd{ + Path: htpasswdPath, + }, + } + c := api.NewController(config) + dir, err := ioutil.TempDir("", "oci-repo-test") + if err != nil { + panic(err) + } + defer os.RemoveAll(dir) + c.Config.Storage.RootDirectory = dir + c.Config.Extensions = &ext.ExtensionConfig{} + go func() { + // this blocks + if err := c.Run(); err != nil { + return + } + }() + + // wait till ready + for { + _, err := resty.R().Get(BaseURL1) + if err == nil { + break + } + time.Sleep(100 * time.Millisecond) + } + + defer func() { + ctx := context.Background() + _ = c.Server.Shutdown(ctx) + }() + }) +}