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.
This commit is contained in:
parent
167a0b3263
commit
790bce219c
3 changed files with 11 additions and 1 deletions
|
@ -42,6 +42,7 @@ type Backend int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GCS = iota
|
GCS = iota
|
||||||
|
FileSystem
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config holds the Nixery configuration options.
|
// Config holds the Nixery configuration options.
|
||||||
|
@ -64,6 +65,8 @@ func FromEnv() (Config, error) {
|
||||||
switch os.Getenv("NIXERY_STORAGE_BACKEND") {
|
switch os.Getenv("NIXERY_STORAGE_BACKEND") {
|
||||||
case "gcs":
|
case "gcs":
|
||||||
b = GCS
|
b = GCS
|
||||||
|
case "filesystem":
|
||||||
|
b = FileSystem
|
||||||
default:
|
default:
|
||||||
log.WithField("values", []string{
|
log.WithField("values", []string{
|
||||||
"gcs",
|
"gcs",
|
||||||
|
|
|
@ -202,6 +202,8 @@ func main() {
|
||||||
switch cfg.Backend {
|
switch cfg.Backend {
|
||||||
case config.GCS:
|
case config.GCS:
|
||||||
s, err = storage.NewGCSBackend()
|
s, err = storage.NewGCSBackend()
|
||||||
|
case config.FileSystem:
|
||||||
|
s, err = storage.NewFSBackend()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Fatal("failed to initialise storage backend")
|
log.WithError(err).Fatal("failed to initialise storage backend")
|
||||||
|
|
|
@ -15,7 +15,12 @@ type FSBackend struct {
|
||||||
path string
|
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)
|
p = path.Clean(p)
|
||||||
err := os.MkdirAll(p, 0755)
|
err := os.MkdirAll(p, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue