Harden CI and switch release builds to tagged immutable images
This commit is contained in:
parent
bed2e6cfb6
commit
f24e96efa7
60 changed files with 4710 additions and 64 deletions
55
internal/config/config.go
Normal file
55
internal/config/config.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
HTTPAddress string
|
||||
WebRoot string
|
||||
StorageRoot string
|
||||
PreviewCacheDir string
|
||||
DatabaseURL string
|
||||
LogLevel slog.Level
|
||||
}
|
||||
|
||||
func FromEnvironment() (Config, error) {
|
||||
level, err := parseLogLevel(environment("DRIVE_LOG_LEVEL", "info"))
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return Config{
|
||||
HTTPAddress: environment("DRIVE_HTTP_ADDRESS", ":8080"),
|
||||
WebRoot: environment("DRIVE_WEB_ROOT", "web/dist"),
|
||||
StorageRoot: environment("DRIVE_STORAGE_ROOT", "/storage/.drive"),
|
||||
PreviewCacheDir: environment("DRIVE_PREVIEW_CACHE_ROOT", "/cache/previews"),
|
||||
DatabaseURL: os.Getenv("DRIVE_DATABASE_URL"),
|
||||
LogLevel: level,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func environment(name, fallback string) string {
|
||||
if value := strings.TrimSpace(os.Getenv(name)); value != "" {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func parseLogLevel(value string) (slog.Level, error) {
|
||||
switch strings.ToLower(value) {
|
||||
case "debug":
|
||||
return slog.LevelDebug, nil
|
||||
case "info":
|
||||
return slog.LevelInfo, nil
|
||||
case "warn", "warning":
|
||||
return slog.LevelWarn, nil
|
||||
case "error":
|
||||
return slog.LevelError, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("invalid DRIVE_LOG_LEVEL %q", value)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue