Harden CI and switch release builds to tagged immutable images
All checks were successful
CI / Backend (push) Successful in 29s
CI / Frontend (push) Successful in 9m27s
CI / Contracts and repository policy (push) Successful in 7s
CI / Container (push) Successful in 18s

This commit is contained in:
Elijah 2026-07-15 19:21:07 -07:00
parent bed2e6cfb6
commit f24e96efa7
60 changed files with 4710 additions and 64 deletions

55
internal/config/config.go Normal file
View 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)
}
}

View file

@ -0,0 +1,18 @@
package config
import (
"log/slog"
"testing"
)
func TestParseLogLevel(t *testing.T) {
t.Parallel()
level, err := parseLogLevel("warning")
if err != nil {
t.Fatalf("parseLogLevel returned an error: %v", err)
}
if level != slog.LevelWarn {
t.Fatalf("parseLogLevel = %v, want %v", level, slog.LevelWarn)
}
}