From 90a2ff959a958e8f7654f577e88e942378b0a7c2 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Sun, 29 Dec 2019 18:36:08 +0100 Subject: Allow data directories outside pwd Running ponzu-cms inside a docker container, and maintaining data files in a volume (or several) was not possible with the previous directory schema without copying files or binaries to the volume. This commit adds several environment variables to allow the administrator to specify paths for directories while retaining backwards compatibility. - PONZU_DATA_DIR : is the directory where all the data and other directories will be stored, still the other directories can be controlled by the other env variables. - PONZU_TLS_DIR : is the directory to store devcerts and autocerts - PONZU_ADMINSTATIC_DIR : directory where the admin static files are served from. - PONZU_UPLOAD_DIR: upload files directory - PONZU_SEARCH_DIR: index directory for searches --- system/cfg/env.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 system/cfg/env.go (limited to 'system/cfg/env.go') diff --git a/system/cfg/env.go b/system/cfg/env.go new file mode 100644 index 0000000..71f48a2 --- /dev/null +++ b/system/cfg/env.go @@ -0,0 +1,56 @@ +package cfg + +import ( + "log" + "os" + "path/filepath" +) + +func getWd() string { + wd, err := os.Getwd() + if err != nil { + log.Fatalln("Couldn't find working directory", err) + } + return wd +} + +func DataDir() string { + dataDir := os.Getenv("PONZU_DATA_DIR") + if dataDir == "" { + return getWd() + } + return dataDir +} + +func TlsDir() string { + tlsDir := os.Getenv("PONZU_TLS_DIR") + if tlsDir == "" { + tlsDir = filepath.Join(getWd(), "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system", "tls") + } + return tlsDir +} + +func AdminStaticDir() string { + staticDir := os.Getenv("PONZU_ADMINSTATIC_DIR") + if staticDir == "" { + + staticDir = filepath.Join(getWd(), "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system", "admin", "static") + } + return staticDir +} + +func UploadDir() string { + uploadDir := os.Getenv("PONZU_UPLOAD_DIR") + if uploadDir == "" { + uploadDir = filepath.Join(DataDir(),"uploads") + } + return uploadDir +} + +func SearchDir() string { + searchDir := os.Getenv("PONZU_SEARCH_DIR") + if searchDir == "" { + searchDir = filepath.Join(DataDir(),"search") + } + return searchDir +} -- cgit v1.2.3