Skip to content

Commit

Permalink
Add embedded db to storage engines
Browse files Browse the repository at this point in the history
Add embedded-db storage engine based on
[boltdb](https://github.com/boltdb/bolt).
Embedding the storage directly in grafeas provides deployment simplicity
and persistency (assuming a persistent volume is used).

Replace `status.Error` with `status.Errorf`

Signed-off-by: Liron Levin <[email protected]>
  • Loading branch information
Liron Levin committed Sep 14, 2018
1 parent f6bb4fd commit 12c3a63
Show file tree
Hide file tree
Showing 36 changed files with 6,047 additions and 57 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# of contributors, see the revision history in source control.
Google Inc.
JFrog Ltd
Twistlock
7 changes: 4 additions & 3 deletions samples/server/go-server/api/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type file struct {

// Config is the global configuration for an instance of Grafeas.
type config struct {
API *api.Config `yaml:"api"`
StorageType string `yaml:"storage_type"` // Supported storage types are "memstore" and "postgres"
PgSQLConfig *storage.PgSQLConfig `yaml:"postgres"`
API *api.Config `yaml:"api"`
StorageType string `yaml:"storage_type"` // Supported storage types are "memstore", "postgres" and "embedded"
PgSQLConfig *storage.PgSQLConfig `yaml:"postgres"`
EmbeddedConfig *storage.EmbeddedStoreConfig `yaml:"embedded"` // EmbeddedConfig is the embedded store config
}

// DefaultConfig is a configuration that can be used as a fallback value.
Expand Down
19 changes: 8 additions & 11 deletions samples/server/go-server/api/server/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ func main() {
if err != nil {
log.Fatalf("Failed to load config file: %s", err)
}
storage := createStorage(config.StorageType, config.PgSQLConfig)
api.Run(config.API, &storage)
}

func createStorage(storageType string, pgSQLConfig *storage.PgSQLConfig) server.Storager {
switch storageType {
var storager server.Storager
switch config.StorageType {
case "memstore":
return storage.NewMemStore()
storager = storage.NewMemStore()
case "postgres":
return storage.NewPgSQLStore(pgSQLConfig)
storager = storage.NewPgSQLStore(config.PgSQLConfig)
case "embedded":
storager = storage.NewEmbeddedStore(config.EmbeddedConfig)
default:
log.Fatalf("Storage type unsupported: %s", storageType)
log.Fatalf("Storage type unsupported: %s", config.StorageType)
}

return nil
api.Run(config.API, &storager)
}
Loading

0 comments on commit 12c3a63

Please sign in to comment.