Skip to content

Commit

Permalink
fix: remove db files on boot (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishkerez authored Jun 27, 2023
1 parent c301813 commit 7da1069
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 4 additions & 3 deletions grype-server/cmd/grype-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions grype-server/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (
HealthCheckAddress = "HEALTH_CHECK_ADDRESS"
DbRootDir = "DB_ROOT_DIR"
DbUpdateURL = "DB_UPDATE_URL"
DbDirName = "DB_DIR_NAME"
)

type Config struct {
Expand All @@ -19,7 +18,6 @@ type Config struct {
HealthCheckAddress string
DbRootDir string
DbUpdateURL string
DbDirName string
}

func LoadConfig() *Config {
Expand All @@ -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
}

0 comments on commit 7da1069

Please # to comment.