2022-08-13 05:12:38 +00:00
|
|
|
package cmd
|
|
|
|
|
2022-08-13 14:41:01 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
)
|
2022-08-13 05:12:38 +00:00
|
|
|
|
|
|
|
type (
|
|
|
|
// Config provides the system configuration.
|
|
|
|
Config struct {
|
2022-08-13 06:15:21 +00:00
|
|
|
Debug bool `envconfig:"GITEA_DEBUG"`
|
|
|
|
Trace bool `envconfig:"GITEA_TRACE"`
|
2022-08-13 14:41:01 +00: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"`
|
2022-09-25 10:54:00 +00:00
|
|
|
GRPC bool `envconfig:"GITEA_RPC_GRPC" default:"true"`
|
2022-08-14 02:59:09 +00:00
|
|
|
GRPCWeb bool `envconfig:"GITEA_RPC_GRPC_WEB"`
|
2022-08-13 14:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-14 02:34:19 +00:00
|
|
|
|
|
|
|
Platform struct {
|
|
|
|
OS string `envconfig:"GITEA_PLATFORM_OS" default:"linux"`
|
|
|
|
Arch string `envconfig:"GITEA_PLATFORM_ARCH" default:"amd64"`
|
|
|
|
Kernel string `envconfig:"GITEA_PLATFORM_KERNEL"`
|
|
|
|
Variant string `envconfig:"GITEA_PLATFORM_VARIANT"`
|
|
|
|
}
|
2022-08-13 05:12:38 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// fromEnviron returns the settings from the environment.
|
|
|
|
func fromEnviron() (Config, error) {
|
|
|
|
cfg := Config{}
|
|
|
|
err := envconfig.Process("", &cfg)
|
2022-08-13 14:41:01 +00: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 05:12:38 +00:00
|
|
|
return cfg, err
|
|
|
|
}
|