diff --git a/Dockerfile b/Dockerfile index e19a349..5e2ac73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app COPY . . -RUN GOOS=linux CGO_ENABLED=0 go build -o /app/dsfx ./cmd/dsfxnode +RUN GOOS=linux CGO_ENABLED=0 go build -o /app/dsfx ./cmd/dsfx FROM scratch diff --git a/README.md b/README.md index d6ad526..5b0f6f2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ _DSFX is a next generation file exchange that that liberates users from big tech ```bash # Run a server -go run koti.casa/numenor-labs/dsfx/cmd/dsfxnode@latest +go run koti.casa/numenor-labs/dsfx/cmd/dsfx@latest # serving: dsfx://0.0.0.0:8000# # Get the client diff --git a/cmd/dsfx/main.go b/cmd/dsfx/main.go index 047c9fb..7715c82 100644 --- a/cmd/dsfx/main.go +++ b/cmd/dsfx/main.go @@ -1,9 +1,31 @@ package main import ( - "log" + "context" + "log/slog" + + "koti.casa/numenor-labs/dsfx/internal/lib/disk" + "koti.casa/numenor-labs/dsfx/internal/lib/system" + "koti.casa/numenor-labs/dsfx/internal/peer/node" + + "koti.casa/numenor-labs/dsfx/internal/lib/storage/scoped" ) func main() { - log.Println("hello from dsfx!") + ctx := context.Background() + + sys := system.Default() + + configDir := sys.GetEnv("DSFXNODE_CONFIG_DIR") + if configDir == "" { + configDir = "/etc/dsfxnode/config" + } + configScope := scoped.New(disk.Default(), configDir) + + err := node.New(configScope, sys).Run(ctx) + if err != nil { + // Log the error and exit with a non-zero status code. + slog.Error("Error running dsfxnode", slog.Any("error", err)) + sys.Exit(1) + } } diff --git a/cmd/dsfxnode/main.go b/cmd/dsfxnode/main.go deleted file mode 100644 index 7715c82..0000000 --- a/cmd/dsfxnode/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "context" - "log/slog" - - "koti.casa/numenor-labs/dsfx/internal/lib/disk" - "koti.casa/numenor-labs/dsfx/internal/lib/system" - "koti.casa/numenor-labs/dsfx/internal/peer/node" - - "koti.casa/numenor-labs/dsfx/internal/lib/storage/scoped" -) - -func main() { - ctx := context.Background() - - sys := system.Default() - - configDir := sys.GetEnv("DSFXNODE_CONFIG_DIR") - if configDir == "" { - configDir = "/etc/dsfxnode/config" - } - configScope := scoped.New(disk.Default(), configDir) - - err := node.New(configScope, sys).Run(ctx) - if err != nil { - // Log the error and exit with a non-zero status code. - slog.Error("Error running dsfxnode", slog.Any("error", err)) - sys.Exit(1) - } -} diff --git a/docs/hosting.md b/docs/hosting.md index c2ed924..cc7cee7 100644 --- a/docs/hosting.md +++ b/docs/hosting.md @@ -39,16 +39,16 @@ git clone https://koti.casa/numenor-labs/dsfx.git cd dsfx -go build -o ./cmd/dsfxnode +go build -o ./cmd/dsfx ``` ## Environment Variables DSFX uses the following environment variables to configure its behavior: -| Variable | Description | Default Value | -| -------------------- | ----------------------------------------------------------- | -------------------- | -| DSFXNODE_PORT | The port on which the DSFX server will listen | 8000 | -| DSFXNODE_HOST | The host on which the DSFX server will run | 0.0.0.0 | -| DSFXNODE_CONFIG_DIR | The directory where the DSFX configuration files are stored | /etc/dsfxnode/config | -| DSFXNODE_STORAGE_DIR | The directory where the DSFX storage files are stored | /etx/dsfxnode/data | +| 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_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 | /etx/dsfx/data | diff --git a/internal/peer/conf/conf.go b/internal/peer/conf/conf.go index df367a1..ae2ac42 100644 --- a/internal/peer/conf/conf.go +++ b/internal/peer/conf/conf.go @@ -3,8 +3,10 @@ package conf import "koti.casa/numenor-labs/dsfx/internal/lib/system" const ( - // DefaultConfigDir is the default directory for the dsfxctl configuration. - DefaultConfigDir = "/etc/dsfxnode/config" + // 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" // DefaultHost is the default host for the dsfxctl application. DefaultHost = "0.0.0.0" // DefaultPort is the default port for the dsfxctl application. @@ -14,7 +16,8 @@ const ( // Conf holds the configuration for the dsfxctl application. type Conf struct { // Directories - ConfigDir string + ConfigDir string + StorageDir string // Networking Host string Port string @@ -23,17 +26,22 @@ type Conf struct { func FromSystem(sys system.System) Conf { var c Conf - c.ConfigDir = sys.GetEnv("DSFXNODE_CONFIG_DIR") + c.ConfigDir = sys.GetEnv("DSFX_CONFIG_DIR") if c.ConfigDir == "" { c.ConfigDir = DefaultConfigDir } - c.Host = sys.GetEnv("DSFXNODE_HOST") + c.StorageDir = sys.GetEnv("DSFX_STORAGE_DIR") + if c.StorageDir == "" { + c.StorageDir = DefaultStorageDir + } + + c.Host = sys.GetEnv("DSFX_HOST") if c.Host == "" { c.Host = DefaultHost } - c.Port = sys.GetEnv("DSFXNODE_PORT") + c.Port = sys.GetEnv("DSFX_PORT") if c.Port == "" { c.Port = DefaultPort }