Skip to content

Commit

Permalink
Merge pull request #138 from castai/feat/config-from-file
Browse files Browse the repository at this point in the history
feat: add ablity to read config from file
  • Loading branch information
aldor007 authored Oct 17, 2023
2 parents fe138da + a3eb7d2 commit 680eecb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ Visit the [docs](https://docs.cast.ai/docs/getting-started) to connect your clus

The helm chart for the CAST AI Kubernetes agent is published in the [castai/helm-charts](https://github.com/castai/helm-charts) repo.


## Reading configuration from file

You can pass configuration to agent via YAML file.

Example file
```yaml
api:
key: "api key"
url: "api.cast.ai"
```
or
```yaml
api.key: "api key"
api.url: "api.cast.ai"
```
Shell example
```shell
CONFIG_PATH=<PATH_TO_CONFIG> ./castai-agent
```

## Contributing

### Run the agent in your IDE
Expand Down
11 changes: 11 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -150,6 +151,16 @@ func Get() Config {

cfg = &Config{}
bindEnvs(*cfg)

if cfgFile := os.Getenv("CONFIG_PATH"); cfgFile != "" {
fmt.Println("Using config from a file", cfgFile)
viper.SetConfigType("yaml")
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
panic(fmt.Errorf("reading default config: %v", err))
}
}

if err := viper.Unmarshal(&cfg); err != nil {
panic(fmt.Errorf("parsing configuration: %v", err))
}
Expand Down

0 comments on commit 680eecb

Please sign in to comment.