mirror of
https://github.com/tiennm99/keepalive.git
synced 2026-10-13 04:15:04 +00:00
feat(config): use config yml defaults
This commit is contained in:
1 parent
08da9dcb84
commit
16cf6277e1
5 files changed
+26
-19
No files matched your search
@@ -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["<name>"] = 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
|
||||
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ services:
|
||||
container_name: keepalive
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./keepalive.yaml:/keepalive.yaml:ro
|
||||
- ./config.yml:/config.yml:ro
|
||||
@@ -1,4 +1,4 @@
|
||||
# Optional defaults for every service.
|
||||
# Optional defaults shared by every service.
|
||||
interval: 1m
|
||||
counter_key: counter
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+7
-7
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user