refactor(internal/peer): change DSFX_STORAGE_DIR to DSFX_DATA_DIR

This commit is contained in:
Dustin Stiles 2025-03-23 10:17:45 -04:00
parent 080f3d92d5
commit c1df1ec84a
Signed by: duwstiles
GPG Key ID: BCD9912EC231FC87
2 changed files with 43 additions and 30 deletions

View File

@ -47,17 +47,17 @@ go build -o <installation-target> ./cmd/dsfx
DSFX uses the following environment variables to configure its behavior:
| Variable | Description | Default Value |
| ---------------- | ----------------------------------------------------------- | ---------------- |
| --------------- | ----------------------------------------------------------- | ---------------- |
| DSFX_HOST | The host on which the DSFX server will run | 0.0.0.0 |
| DSFX_PORT | The port on which the DSFX server will listen | 8000 |
| DSFX_LOG_LEVEL | The log level to use. One of (error, warn, info, debug) | info |
| DSFX_DATA_DIR | The directory where the DSFX data files are stored | /etc/dsfx/data |
| DSFX_CONFIG_DIR | The directory where the DSFX configuration files are stored | /etc/dsfx/config |
| DSFX_STORAGE_DIR | The directory where the DSFX storage files are stored | /etc/dsfx/data |
## Local Files
The DSFX server uses local files for configuration and storage. The default directories for these
files are specified in the `DSFX_CONFIG_DIR` and `DSFX_STORAGE_DIR` environment variables. You can
files are specified in the `DSFX_CONFIG_DIR` and `DSFX_DATA_DIR` environment variables. You can
change these directories by setting the corresponding environment variables before starting the server.
For docker installations, it is recommended to mount the local directories to the container

View File

@ -21,14 +21,27 @@ import (
)
const (
// DefaultConfigDir is the default directory for the dsfx configuration.
DefaultConfigDir = "/etc/dsfx/config"
// DefaultStorageDir is the default directory for the dsfx storage.
DefaultStorageDir = "/etc/dsfx/data"
// EnvHost is the environment variable for the dsfx host.
EnvHost = "DSFX_HOST"
// EnvPort is the environment variable for the dsfx port.
EnvPort = "DSFX_PORT"
// EnvLogLevel is the environment variable for the dsfx log level.
EnvLogLevel = "DSFX_LOG_LEVEL"
// EnvDataDir is the environment variable for the dsfx storage directory.
EnvDataDir = "DSFX_DATA_DIR"
// EnvConfigDir is the environment variable for the dsfx configuration directory.
EnvConfigDir = "DSFX_CONFIG_DIR"
)
const (
// DefaultHost is the default host for the dsfxctl application.
DefaultHost = "0.0.0.0"
// DefaultPort is the default port for the dsfxctl application.
DefaultPort = "8000"
// DefaultDataDir is the default directory for the dsfx storage.
DefaultDataDir = "/etc/dsfx/data"
// DefaultConfigDir is the default directory for the dsfx configuration.
DefaultConfigDir = "/etc/dsfx/config"
)
// Conf holds the configuration for the dsfxctl application.
@ -36,7 +49,7 @@ type Conf struct {
LogLevel string
// Directories
ConfigDir string
StorageDir string
DataDir string
// Networking
Host string
Port string
@ -61,26 +74,26 @@ func (c Conf) SlogLevel() slog.Level {
func loadConfigFromSystem(sys system.System) Conf {
var c Conf
c.ConfigDir = sys.GetEnv("DSFX_CONFIG_DIR")
if c.ConfigDir == "" {
c.ConfigDir = DefaultConfigDir
}
c.StorageDir = sys.GetEnv("DSFX_STORAGE_DIR")
if c.StorageDir == "" {
c.StorageDir = DefaultStorageDir
}
c.Host = sys.GetEnv("DSFX_HOST")
if c.Host == "" {
c.Host = sys.GetEnv(EnvHost)
if len(c.Host) == 0 {
c.Host = DefaultHost
}
c.Port = sys.GetEnv("DSFX_PORT")
if c.Port == "" {
c.Port = sys.GetEnv(EnvPort)
if len(c.Port) == 0 {
c.Port = DefaultPort
}
c.ConfigDir = sys.GetEnv(EnvConfigDir)
if len(c.ConfigDir) == 0 {
c.ConfigDir = DefaultConfigDir
}
c.DataDir = sys.GetEnv(EnvDataDir)
if len(c.DataDir) == 0 {
c.DataDir = DefaultDataDir
}
// defaults are handled by Conf.SlogLevel.
c.LogLevel = sys.GetEnv("DSFX_LOG_LEVEL")
@ -101,7 +114,7 @@ func New(disk disk.Disk, system system.System) *Peer {
conf := loadConfigFromSystem(system)
config := scoped.New(disk, conf.ConfigDir)
storage := scoped.New(disk, conf.StorageDir)
storage := scoped.New(disk, conf.DataDir)
return &Peer{disk, system, config, storage, conf}
}
@ -123,7 +136,7 @@ func (p *Peer) Run(ctx context.Context) error {
return err
}
err = p.disk.MkdirAll(p.conf.StorageDir, 0755)
err = p.disk.MkdirAll(p.conf.DataDir, 0755)
if err != nil {
logger.ErrorContext(ctx, "failed to create storage dir", slog.Any("error", err))
return err