about summary refs log tree commit diff
path: root/tools/nixery
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-10-28T17·19+0100
committerVincent Ambo <github@tazj.in>2019-10-28T21·31+0100
commit790bce219cf9acf01de3257fcf137a0a2833529e (patch)
treea26922af66344e3d08d42b87e50371e1f888bdc4 /tools/nixery
parent167a0b32630ed86b3a053e56fa499957872d7b38 (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/nixery')
-rw-r--r--tools/nixery/server/config/config.go3
-rw-r--r--tools/nixery/server/main.go2
-rw-r--r--tools/nixery/server/storage/filesystem.go7
3 files changed, 11 insertions, 1 deletions
diff --git a/tools/nixery/server/config/config.go b/tools/nixery/server/config/config.go
index 6cc69fa1f5..7ec102bd6c 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 282fe9773a..f4f707313f 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 ef763da67f..f343d67b65 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 {