fetch_ml/cmd/api-server/main.go
Jeremie Fraeys 7194826871
feat: implement research-grade maintainability phases 1,3,4,7
Phase 1: Event Sourcing
- Add TaskEvent types (queued, started, completed, failed, etc.)
- Create EventStore with Redis Streams (append-only)
- Support event querying by task ID and time range

Phase 3: Diagnosable Failures
- Enhance TaskExecutionError with Context map, Timestamp, Recoverable flag
- Update container.go to populate error context (image, GPU, duration)
- Add WithContext helper for building error context
- Create cmd/errors CLI for querying task errors

Phase 4: Testable Security
- Add security fields to PodmanConfig (Privileged, Network, ReadOnlyMounts)
- Create ValidateSecurityPolicy() with ErrSecurityViolation
- Add security contract tests (privileged rejection, host network rejection)
- Tests serve as executable security documentation

Phase 7: Reproducible Builds
- Add BuildHash and BuildTime ldflags to Makefile
- Create verify-build target for reproducibility testing
- Add -version and -verify flags to api-server

All tests pass:
- go test ./internal/errtypes/...
- go test ./internal/container/... -run Security
- go test ./internal/queue/...
- go build ./cmd/api-server/...
2026-02-18 15:27:50 -05:00

56 lines
1.3 KiB
Go

// Package main implements the fetch_ml API server
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/jfraeys/fetch_ml/internal/api"
)
// Build variables injected at build time
var (
BuildHash = "unknown"
BuildTime = "unknown"
)
func main() {
configFile := flag.String("config", "configs/api/dev.yaml", "Configuration file path")
apiKey := flag.String("api-key", "", "API key for authentication")
showVersion := flag.Bool("version", false, "Show version and build info")
verifyBuild := flag.Bool("verify", false, "Verify build integrity")
flag.Parse()
// Handle version display
if *showVersion {
fmt.Printf("fetch_ml API Server\n")
fmt.Printf(" Build Hash: %s\n", BuildHash)
fmt.Printf(" Build Time: %s\n", BuildTime)
os.Exit(0)
}
// Handle build verification (placeholder - always true for now)
if *verifyBuild {
fmt.Printf("Build verification: OK\n")
fmt.Printf(" Build Hash: %s\n", BuildHash)
os.Exit(0)
}
// Create and start server
server, err := api.NewServer(*configFile)
if err != nil {
log.Fatalf("Failed to create server: %v", err)
}
if err := server.Start(); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
// Wait for shutdown
server.WaitForShutdown()
// Reserved for future authentication enhancements
_ = apiKey
}