config.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package config
  2. import (
  3. "log"
  4. "time"
  5. "github.com/joeshaw/envdecode"
  6. )
  7. // Conf is the configuration for the Go server
  8. type Conf struct {
  9. Debug bool `env:"DEBUG,default=false"`
  10. Server ServerConf
  11. Db DBConf
  12. K8s K8sConf
  13. Redis RedisConf
  14. }
  15. // ServerConf is the server configuration
  16. type ServerConf struct {
  17. ServerURL string `env:"SERVER_URL,default=http://localhost:8080"`
  18. Port int `env:"SERVER_PORT,default=8080"`
  19. StaticFilePath string `env:"STATIC_FILE_PATH,default=/porter/static"`
  20. CookieName string `env:"COOKIE_NAME,default=porter"`
  21. CookieSecrets []string `env:"COOKIE_SECRETS,default=random_hash_key_;random_block_key"`
  22. TokenGeneratorSecret string `env:"TOKEN_GENERATOR_SECRET,default=secret"`
  23. TimeoutRead time.Duration `env:"SERVER_TIMEOUT_READ,default=5s"`
  24. TimeoutWrite time.Duration `env:"SERVER_TIMEOUT_WRITE,default=10s"`
  25. TimeoutIdle time.Duration `env:"SERVER_TIMEOUT_IDLE,default=15s"`
  26. IsLocal bool `env:"IS_LOCAL,default=false"`
  27. IsTesting bool `env:"IS_TESTING,default=false"`
  28. AppRootDomain string `env:"APP_ROOT_DOMAIN,default=porter.run"`
  29. DefaultHelmRepoURL string `env:"HELM_REPO_URL,default=https://porter-dev.github.io/chart-repo/"`
  30. GithubClientID string `env:"GITHUB_CLIENT_ID"`
  31. GithubClientSecret string `env:"GITHUB_CLIENT_SECRET"`
  32. DOClientID string `env:"DO_CLIENT_ID"`
  33. DOClientSecret string `env:"DO_CLIENT_SECRET"`
  34. ProvisionerImageTag string `env:"PROV_IMAGE_TAG,default=latest"`
  35. }
  36. // DBConf is the database configuration: if generated from environment variables,
  37. // it assumes the default docker-compose configuration is used
  38. type DBConf struct {
  39. // EncryptionKey is the key to use for sensitive values that are encrypted at rest
  40. EncryptionKey string `env:"ENCRYPTION_KEY,default=__random_strong_encryption_key__"`
  41. Host string `env:"DB_HOST,default=postgres"`
  42. Port int `env:"DB_PORT,default=5432"`
  43. Username string `env:"DB_USER,default=porter"`
  44. Password string `env:"DB_PASS,default=porter"`
  45. DbName string `env:"DB_NAME,default=porter"`
  46. SQLLite bool `env:"SQL_LITE,default=false"`
  47. SQLLitePath string `env:"SQL_LITE_PATH,default=/porter/porter.db"`
  48. }
  49. // K8sConf is the global configuration for the k8s agents
  50. type K8sConf struct {
  51. IsTesting bool `env:"K8S_IS_TESTING,default=false"`
  52. }
  53. // FromEnv generates a configuration from environment variables
  54. func FromEnv() *Conf {
  55. var c Conf
  56. if err := envdecode.StrictDecode(&c); err != nil {
  57. log.Fatalf("Failed to decode server conf: %s", err)
  58. }
  59. return &c
  60. }