mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
build: add build tags to create customizable binaries
This commit is contained in:
+2
-3
@@ -16,11 +16,9 @@ go_library(
|
||||
deps = [
|
||||
"//docs:go_default_library",
|
||||
"//errors:go_default_library",
|
||||
"//pkg/extensions/search:go_default_library",
|
||||
"//pkg/extensions/search/cve:go_default_library",
|
||||
"//pkg/extensions:go_default_library",
|
||||
"//pkg/log:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
"@com_github_99designs_gqlgen//graphql/handler:go_default_library",
|
||||
"@com_github_chartmuseum_auth//:go_default_library",
|
||||
"@com_github_getlantern_deepcopy//:go_default_library",
|
||||
"@com_github_go_ldap_ldap_v3//:go_default_library",
|
||||
@@ -42,6 +40,7 @@ go_test(
|
||||
"//:exported_testdata",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
gotags = ["extended"],
|
||||
race = "on",
|
||||
deps = [
|
||||
"//errors:go_default_library",
|
||||
|
||||
+2
-16
@@ -1,9 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/anuvu/zot/errors"
|
||||
ext "github.com/anuvu/zot/pkg/extensions"
|
||||
"github.com/anuvu/zot/pkg/log"
|
||||
"github.com/getlantern/deepcopy"
|
||||
dspec "github.com/opencontainers/distribution-spec"
|
||||
@@ -70,26 +69,13 @@ type LogConfig struct {
|
||||
Output string
|
||||
}
|
||||
|
||||
type ExtensionConfig struct {
|
||||
Search *SearchConfig
|
||||
}
|
||||
|
||||
type SearchConfig struct {
|
||||
// CVE search
|
||||
CVE *CVEConfig
|
||||
}
|
||||
|
||||
type CVEConfig struct {
|
||||
UpdateInterval time.Duration // should be 2 hours or more, if not specified default be kept as 24 hours
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Version string
|
||||
Commit string
|
||||
Storage StorageConfig
|
||||
HTTP HTTPConfig
|
||||
Log *LogConfig
|
||||
Extensions *ExtensionConfig
|
||||
Extensions *ext.ExtensionConfig
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
|
||||
+3
-27
@@ -8,10 +8,9 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/anuvu/zot/errors"
|
||||
cveinfo "github.com/anuvu/zot/pkg/extensions/search/cve"
|
||||
ext "github.com/anuvu/zot/pkg/extensions"
|
||||
"github.com/anuvu/zot/pkg/log"
|
||||
"github.com/anuvu/zot/pkg/storage"
|
||||
"github.com/gorilla/handlers"
|
||||
@@ -52,31 +51,8 @@ func (c *Controller) Run() error {
|
||||
}
|
||||
|
||||
// Updating the CVE Database
|
||||
if c.Config != nil && c.Config.Extensions != nil && c.Config.Extensions.Search != nil &&
|
||||
c.Config.Extensions.Search.CVE != nil {
|
||||
defaultUpdateInterval, _ := time.ParseDuration("2h")
|
||||
|
||||
if c.Config.Extensions.Search.CVE.UpdateInterval < defaultUpdateInterval {
|
||||
c.Config.Extensions.Search.CVE.UpdateInterval = defaultUpdateInterval
|
||||
c.Log.Warn().Msg("CVE update interval set to too-short interval <= 1, changing update duration to 2 hours and continuing.") // nolint: lll
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
c.Log.Info().Msg("Updating the CVE database")
|
||||
|
||||
err := cveinfo.UpdateCVEDb(c.Config.Storage.RootDirectory, c.Log)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.Log.Info().Str("Db update completed, next update scheduled after", c.Config.Extensions.Search.CVE.UpdateInterval.String()).Msg("") //nolint: lll
|
||||
|
||||
time.Sleep(c.Config.Extensions.Search.CVE.UpdateInterval)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
c.Log.Info().Msg("Cve config not provided, skipping cve update")
|
||||
if c.Config != nil {
|
||||
ext.EnableExtension(c.Config.Extensions, c.Log, c.Config.Storage.RootDirectory)
|
||||
}
|
||||
|
||||
c.Router = engine
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build extended
|
||||
|
||||
package api_test
|
||||
|
||||
import (
|
||||
|
||||
+2
-8
@@ -21,10 +21,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
gqlHandler "github.com/99designs/gqlgen/graphql/handler"
|
||||
_ "github.com/anuvu/zot/docs" // as required by swaggo
|
||||
"github.com/anuvu/zot/errors"
|
||||
"github.com/anuvu/zot/pkg/extensions/search"
|
||||
ext "github.com/anuvu/zot/pkg/extensions"
|
||||
"github.com/anuvu/zot/pkg/log"
|
||||
"github.com/gorilla/mux"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
@@ -52,11 +51,6 @@ func NewRouteHandler(c *Controller) *RouteHandler {
|
||||
return rh
|
||||
}
|
||||
|
||||
func (rh *RouteHandler) searchHandler() *gqlHandler.Server {
|
||||
resConfig := search.GetResolverConfig(rh.c.Config.Storage.RootDirectory, rh.c.Log, rh.c.ImageStore)
|
||||
return gqlHandler.NewDefaultServer(search.NewExecutableSchema(resConfig))
|
||||
}
|
||||
|
||||
func (rh *RouteHandler) SetupRoutes() {
|
||||
rh.c.Router.Use(AuthHandler(rh.c))
|
||||
g := rh.c.Router.PathPrefix(RoutePrefix).Subrouter()
|
||||
@@ -96,7 +90,7 @@ func (rh *RouteHandler) SetupRoutes() {
|
||||
rh.c.Router.PathPrefix("/swagger/v2/").Methods("GET").Handler(httpSwagger.WrapHandler)
|
||||
// Zot Search Extension Router
|
||||
if rh.c.Config != nil && rh.c.Config.Extensions != nil {
|
||||
rh.c.Router.PathPrefix("/query").Methods("GET", "POST").Handler(rh.searchHandler())
|
||||
ext.SetupRoutes(rh.c.Router, rh.c.Config.Storage.RootDirectory, rh.c.ImageStore, rh.c.Log)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user