From 7da1069a41629b92f316b34b8d5898e0cd2deea2 Mon Sep 17 00:00:00 2001 From: fishkerez <89929372+fishkerez@users.noreply.github.com> Date: Tue, 27 Jun 2023 11:49:27 +0300 Subject: [PATCH] fix: remove db files on boot (#33) --- grype-server/cmd/grype-server/main.go | 7 ++++--- grype-server/pkg/config/config.go | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/grype-server/cmd/grype-server/main.go b/grype-server/cmd/grype-server/main.go index 231768a..662587f 100644 --- a/grype-server/cmd/grype-server/main.go +++ b/grype-server/cmd/grype-server/main.go @@ -2,13 +2,15 @@ package main import ( "context" - "fmt" "os" "os/signal" + "path" + "strconv" "syscall" "github.com/Portshift/go-utils/healthz" logutils "github.com/Portshift/go-utils/log" + "github.com/anchore/grype/grype/vulnerability" log "github.com/sirupsen/logrus" "github.com/spf13/viper" "github.com/urfave/cli" @@ -24,7 +26,7 @@ func run(c *cli.Context) { conf := config.LoadConfig() // remove database directory if it exists to avoid using a corrupt database - dbDir := fmt.Sprintf("%s/%s", conf.DbRootDir, conf.DbDirName) + dbDir := path.Join(conf.DbRootDir, strconv.Itoa(vulnerability.SchemaVersion)) if _, err := os.Stat(dbDir); !os.IsNotExist(err) { if err = os.RemoveAll(dbDir); err != nil { log.Fatalf("Unable to delete existing DB directory: %v", err) @@ -73,7 +75,6 @@ func main() { viper.SetDefault(config.HealthCheckAddress, ":8080") viper.SetDefault(config.DbRootDir, "/app/") viper.SetDefault(config.DbUpdateURL, "https://toolbox-data.anchore.io/grype/databases/listing.json") - viper.SetDefault(config.DbDirName, "3") viper.AutomaticEnv() app := cli.NewApp() diff --git a/grype-server/pkg/config/config.go b/grype-server/pkg/config/config.go index f071a44..c719e33 100644 --- a/grype-server/pkg/config/config.go +++ b/grype-server/pkg/config/config.go @@ -10,7 +10,6 @@ const ( HealthCheckAddress = "HEALTH_CHECK_ADDRESS" DbRootDir = "DB_ROOT_DIR" DbUpdateURL = "DB_UPDATE_URL" - DbDirName = "DB_DIR_NAME" ) type Config struct { @@ -19,7 +18,6 @@ type Config struct { HealthCheckAddress string DbRootDir string DbUpdateURL string - DbDirName string } func LoadConfig() *Config { @@ -30,7 +28,6 @@ func LoadConfig() *Config { config.HealthCheckAddress = viper.GetString(HealthCheckAddress) config.DbRootDir = viper.GetString(DbRootDir) config.DbUpdateURL = viper.GetString(DbUpdateURL) - config.DbDirName = viper.GetString(DbDirName) return config }