2022-08-13 13:12:38 +08:00
|
|
|
package cmd
|
|
|
|
|
2022-08-13 22:41:01 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
)
|
2022-08-13 13:12:38 +08:00
|
|
|
|
|
|
|
type (
|
|
|
|
// Config provides the system configuration.
|
|
|
|
Config struct {
|
2022-08-13 14:15:21 +08:00
|
|
|
Debug bool `envconfig:"GITEA_DEBUG"`
|
|
|
|
Trace bool `envconfig:"GITEA_TRACE"`
|
2022-08-13 22:41:01 +08:00
|
|
|
|
|
|
|
Client struct {
|
|
|
|
Address string `ignored:"true"`
|
|
|
|
Proto string `envconfig:"GITEA_RPC_PROTO" default:"http"`
|
|
|
|
Host string `envconfig:"GITEA_RPC_HOST" required:"true"`
|
|
|
|
Secret string `envconfig:"GITEA_RPC_SECRET" required:"true"`
|
|
|
|
SkipVerify bool `envconfig:"GITEA_RPC_SKIP_VERIFY"`
|
|
|
|
}
|
|
|
|
|
|
|
|
Runner struct {
|
|
|
|
Name string `envconfig:"GITEA_RUNNER_NAME"`
|
|
|
|
Capacity int `envconfig:"GITEA_RUNNER_CAPACITY" default:"2"`
|
|
|
|
Procs int64 `envconfig:"GITEA_RUNNER_MAX_PROCS"`
|
|
|
|
Environ map[string]string `envconfig:"GITEA_RUNNER_ENVIRON"`
|
|
|
|
EnvFile string `envconfig:"GITEA_RUNNER_ENV_FILE"`
|
|
|
|
}
|
2022-08-13 13:12:38 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// fromEnviron returns the settings from the environment.
|
|
|
|
func fromEnviron() (Config, error) {
|
|
|
|
cfg := Config{}
|
|
|
|
err := envconfig.Process("", &cfg)
|
2022-08-13 22:41:01 +08:00
|
|
|
|
|
|
|
// runner config
|
|
|
|
if cfg.Runner.Environ == nil {
|
|
|
|
cfg.Runner.Environ = map[string]string{}
|
|
|
|
}
|
|
|
|
if cfg.Runner.Name == "" {
|
|
|
|
cfg.Runner.Name, _ = os.Hostname()
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.Client.Address = fmt.Sprintf(
|
|
|
|
"%s://%s",
|
|
|
|
cfg.Client.Proto,
|
|
|
|
cfg.Client.Host,
|
|
|
|
)
|
|
|
|
|
|
|
|
if file := cfg.Runner.EnvFile; file != "" {
|
|
|
|
envs, err := godotenv.Read(file)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
for k, v := range envs {
|
|
|
|
cfg.Runner.Environ[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-13 13:12:38 +08:00
|
|
|
return cfg, err
|
|
|
|
}
|