Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change default DAGs directory to ~/.dagu/dags for scheduler and server command #207

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Download the latest binary from the [Releases page](https://github.com/yohamta/d

Start the server with `dagu server` and browse to `http://127.0.0.1:8080` to explore the Web UI.

Note: Dagu reads YAML files placed in the current directory by default. To change the DAGs directory please create a config file. See [Admin Configuration](#admin-configuration) for more detail. Will fix this behavior soon.
*Note: Dagu reads YAML files placed in `~/.dagu/dags` by default. To change the DAGs directory please create a config file. See [Admin Configuration](#admin-configuration) for more detail.*

### 2. Create a new DAG

Expand Down Expand Up @@ -386,6 +386,7 @@ The global configuration file `~/.dagu/config.yaml` is useful to gather common s

You can customize the admin web UI by environment variables.

- `DAGU__DAGS` - path to directory for DAG files (default : `~/.dagu/dags`)
- `DAGU__DATA` - path to directory for internal use by dagu (default : `~/.dagu/data`)
- `DAGU__LOGS` - path to directory for logging (default : `~/.dagu/logs`)
- `DAGU__ADMIN_PORT` - port number for web URL (default : `8080`)
Expand All @@ -399,7 +400,7 @@ Please create `~/.dagu/admin.yaml`.
```yaml
host: <hostname for web UI address> # default value is 127.0.0.1
port: <port number for web UI address> # default value is 8000
dags: <the location of DAG configuration files> # default value is current working directory
dags: <the location of DAG configuration files> # [optional] default value is ~/.dagu/dags
command: <Absolute path to the dagu binary> # [optional] required if the dagu command not in $PATH
isBasicAuth: <true|false> # [optional] basic auth config
basicAuthUsername: <username for basic auth of web UI> # [optional] basic auth config
Expand Down
8 changes: 3 additions & 5 deletions internal/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ func (c *Config) setup() {
c.Command = "dagu"
}
if c.DAGs == "" {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
c.DAGs = wd
c.DAGs = path.Join(
settings.MustGet(settings.SETTING__ADMIN_DAGS_DIR),
)
}
if c.LogDir == "" {
c.LogDir = path.Join(
Expand Down
3 changes: 2 additions & 1 deletion internal/admin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestLoadConfig(t *testing.T) {
{
Yaml: ``,
Want: &Config{
DAGs: wd,
DAGs: settings.MustGet(
settings.SETTING__ADMIN_DAGS_DIR),
Host: "127.0.0.1",
Port: "8080",
Command: "dagu",
Expand Down
5 changes: 2 additions & 3 deletions internal/admin/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ var testsConfig = path.Join(testsDir, "admin.yaml")

func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
wd, err := os.Getwd()
home, err := os.UserHomeDir()
require.NoError(t, err)

testConfig(t, cfg, &testWant{
Host: "127.0.0.1",
Port: "8080",
DAGs: path.Join(wd),
DAGs: path.Join(home, ".dagu/dags"),
Command: "dagu",
})
}
Expand Down
25 changes: 13 additions & 12 deletions internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
SETTING__ADMIN_NAVBAR_COLOR = "DAGU__ADMIN_NAVBAR_COLOR"
SETTING__ADMIN_NAVBAR_TITLE = "DAGU__ADMIN_NAVBAR_TITLE"
SETTING__ADMIN_LOGS_DIR = "DAGU__ADMIN_LOGS_DIR"
SETTING__ADMIN_DAGS_DIR = "DAGU__ADMIN_DAGS_DIR"
)

// MustGet returns the value of the setting or
Expand Down Expand Up @@ -57,19 +58,19 @@ func load() {
homeDir := utils.MustGetUserHomeDir()

cache = map[string]string{}
cache[SETTING__DATA_DIR] = readEnv(
SETTING__DATA_DIR,
path.Join(homeDir, "/.dagu/data"))
cache[SETTING__LOGS_DIR] = readEnv(SETTING__LOGS_DIR,
path.Join(homeDir, "/.dagu/logs"))
cache[SETTING__SUSPEND_FLAGS_DIR] = readEnv(SETTING__SUSPEND_FLAGS_DIR,
path.Join(homeDir, "/.dagu/suspend"))

cache[SETTING__ADMIN_PORT] = readEnv(SETTING__ADMIN_PORT, "8080")
cache[SETTING__ADMIN_NAVBAR_COLOR] = readEnv(SETTING__ADMIN_NAVBAR_COLOR, "")
cache[SETTING__ADMIN_NAVBAR_TITLE] = readEnv(SETTING__ADMIN_NAVBAR_TITLE, "Dagu admin")
cache[SETTING__ADMIN_LOGS_DIR] = readEnv(SETTING__ADMIN_LOGS_DIR,
path.Join(homeDir, "/.dagu/logs/admin"))
cacheEnv(SETTING__DATA_DIR, path.Join(homeDir, "/.dagu/data"))
cacheEnv(SETTING__LOGS_DIR, path.Join(homeDir, "/.dagu/logs"))
cacheEnv(SETTING__SUSPEND_FLAGS_DIR, path.Join(homeDir, "/.dagu/suspend"))
cacheEnv(SETTING__ADMIN_PORT, "8080")
cacheEnv(SETTING__ADMIN_NAVBAR_COLOR, "")
cacheEnv(SETTING__ADMIN_NAVBAR_TITLE, "Dagu admin")
cacheEnv(SETTING__ADMIN_LOGS_DIR, path.Join(homeDir, "/.dagu/logs/admin"))
cacheEnv(SETTING__ADMIN_DAGS_DIR, path.Join(homeDir, "/.dagu/dags"))
}

func cacheEnv(key, def string) {
cache[key] = readEnv(key, def)
}

func readEnv(env, def string) string {
Expand Down