diff options
author | Vincent Ambo <tazjin@google.com> | 2019-10-28T17·19+0100 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2019-10-28T21·31+0100 |
commit | 790bce219cf9acf01de3257fcf137a0a2833529e (patch) | |
tree | a26922af66344e3d08d42b87e50371e1f888bdc4 /tools | |
parent | 167a0b32630ed86b3a053e56fa499957872d7b38 (diff) |
feat(server): Add filesystem storage backend config options
The filesystem storage backend can be enabled by setting `NIXERY_STORAGE_BACKEND` to `filesystem` and `STORAGE_PATH` to a disk location from which Nixery can serve files.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nixery/server/config/config.go | 3 | ||||
-rw-r--r-- | tools/nixery/server/main.go | 2 | ||||
-rw-r--r-- | tools/nixery/server/storage/filesystem.go | 7 |
3 files changed, 11 insertions, 1 deletions
diff --git a/tools/nixery/server/config/config.go b/tools/nixery/server/config/config.go index 6cc69fa1f599..7ec102bd6cee 100644 --- a/tools/nixery/server/config/config.go +++ b/tools/nixery/server/config/config.go @@ -42,6 +42,7 @@ type Backend int const ( GCS = iota + FileSystem ) // Config holds the Nixery configuration options. @@ -64,6 +65,8 @@ func FromEnv() (Config, error) { switch os.Getenv("NIXERY_STORAGE_BACKEND") { case "gcs": b = GCS + case "filesystem": + b = FileSystem default: log.WithField("values", []string{ "gcs", diff --git a/tools/nixery/server/main.go b/tools/nixery/server/main.go index 282fe9773a73..f4f707313f22 100644 --- a/tools/nixery/server/main.go +++ b/tools/nixery/server/main.go @@ -202,6 +202,8 @@ func main() { switch cfg.Backend { case config.GCS: s, err = storage.NewGCSBackend() + case config.FileSystem: + s, err = storage.NewFSBackend() } if err != nil { log.WithError(err).Fatal("failed to initialise storage backend") diff --git a/tools/nixery/server/storage/filesystem.go b/tools/nixery/server/storage/filesystem.go index ef763da67f14..f343d67b65f8 100644 --- a/tools/nixery/server/storage/filesystem.go +++ b/tools/nixery/server/storage/filesystem.go @@ -15,7 +15,12 @@ type FSBackend struct { path string } -func NewFSBackend(p string) (*FSBackend, error) { +func NewFSBackend() (*FSBackend, error) { + p := os.Getenv("STORAGE_PATH") + if p == "" { + return nil, fmt.Errorf("STORAGE_PATH must be set for filesystem storage") + } + p = path.Clean(p) err := os.MkdirAll(p, 0755) if err != nil { |