diff --git a/README.md b/README.md index 13aed92..05a6add 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Successor to the `*-keepalive` family: one binary, one image, six datastore adap ## Configuration -By default, keepalive reads the first config file it finds: `keepalive.yaml`, `keepalive.yml`, `/keepalive.yaml`, then `/keepalive.yml`. One deployment can keep any number of services alive. +By default, keepalive reads the first config file it finds: `config.yml`, `config.yaml`, `/config.yml`, then `/config.yaml`. One deployment can keep any number of services alive. ```yaml interval: 1m @@ -53,7 +53,7 @@ services: ## Quick start (Compose) ```bash -cp keepalive.example.yaml keepalive.yaml +cp config.example.yml config.yml docker compose up -d --build ``` @@ -62,18 +62,25 @@ docker compose up -d --build ```bash docker build -t keepalive:local . docker run -d --name keepalive --restart unless-stopped \ - -v "$PWD/keepalive.yaml:/keepalive.yaml:ro" \ + -v "$PWD/config.yml:/config.yml:ro" \ keepalive:local ``` -If your host config file is named `keepalive.yml`, mount it to `/keepalive.yml` instead. +If you prefer to mount the config into a working directory instead of the container root, set the container working directory and mount the file there: + +```bash +docker run -d --name keepalive --restart unless-stopped \ + --workdir /workspace \ + -v "$PWD/config.yml:/workspace/config.yml:ro" \ + keepalive:local +``` ## Quick start (local) ```bash git clone https://github.com/tiennm99/keepalive cd keepalive -cp keepalive.example.yaml keepalive.yaml +cp config.example.yml config.yml go run . ``` @@ -104,7 +111,7 @@ Seed the value with your configured `counter_key` when it is not `counter`. MySQ ```go func init() { Registry[""] = func(cfg Config) (Adapter, error) { return &myAdapter{}, nil } } ``` -4. Add an `import _ "your driver"` if needed, and the adapter config keys to `keepalive.example.yaml` and the table above. +4. Add an `import _ "your driver"` if needed, and the adapter config keys to `config.example.yml` and the table above. ## Migrated from diff --git a/compose.yml b/compose.yml index b51733f..82925ee 100644 --- a/compose.yml +++ b/compose.yml @@ -6,4 +6,4 @@ services: container_name: keepalive restart: unless-stopped volumes: - - ./keepalive.yaml:/keepalive.yaml:ro + - ./config.yml:/config.yml:ro diff --git a/keepalive.example.yaml b/config.example.yml similarity index 92% rename from keepalive.example.yaml rename to config.example.yml index 1a98270..6066b96 100644 --- a/keepalive.example.yaml +++ b/config.example.yml @@ -1,4 +1,4 @@ -# Optional defaults for every service. +# Optional defaults shared by every service. interval: 1m counter_key: counter diff --git a/config.go b/config.go index 1dd5a78..2d1f126 100644 --- a/config.go +++ b/config.go @@ -20,10 +20,10 @@ const ( ) var defaultConfigFiles = []string{ - "keepalive.yaml", - "keepalive.yml", - "/keepalive.yaml", - "/keepalive.yml", + "config.yml", + "config.yaml", + "/config.yml", + "/config.yaml", } type appConfig struct { diff --git a/config_test.go b/config_test.go index 1ed3556..0532f3b 100644 --- a/config_test.go +++ b/config_test.go @@ -28,8 +28,8 @@ func TestNormalizeConfigGeneratesNamesFromAdapterAndHost(t *testing.T) { } } -func TestKeepaliveExampleConfigParses(t *testing.T) { - services, err := loadConfigFile("keepalive.example.yaml") +func TestConfigExampleYMLParses(t *testing.T) { + services, err := loadConfigFile("config.example.yml") if err != nil { t.Fatalf("loadConfigFile returned error: %v", err) } @@ -40,13 +40,13 @@ func TestKeepaliveExampleConfigParses(t *testing.T) { func TestFirstExistingConfigFileFindsYMLFallback(t *testing.T) { dir := t.TempDir() - ymlPath := filepath.Join(dir, "keepalive.yml") + ymlPath := filepath.Join(dir, "config.yml") if err := os.WriteFile(ymlPath, []byte("services: []\n"), 0o600); err != nil { t.Fatalf("write config: %v", err) } got, err := firstExistingConfigFile([]string{ - filepath.Join(dir, "keepalive.yaml"), + filepath.Join(dir, "config.yaml"), ymlPath, }) if err != nil { @@ -60,13 +60,13 @@ func TestFirstExistingConfigFileFindsYMLFallback(t *testing.T) { func TestFirstExistingConfigFileReportsCandidates(t *testing.T) { dir := t.TempDir() _, err := firstExistingConfigFile([]string{ - filepath.Join(dir, "keepalive.yaml"), - filepath.Join(dir, "keepalive.yml"), + filepath.Join(dir, "config.yaml"), + filepath.Join(dir, "config.yml"), }) if err == nil { t.Fatal("firstExistingConfigFile returned nil error") } - if !strings.Contains(err.Error(), "keepalive.yaml") || !strings.Contains(err.Error(), "keepalive.yml") { + if !strings.Contains(err.Error(), "config.yaml") || !strings.Contains(err.Error(), "config.yml") { t.Fatalf("error %q does not list expected candidates", err) } }