Files
yoresee_codegen/cmd/server/main.go
T
XingfenD 4e467e1136 feat: implement proto-gen platform
- Config loader with env var expansion and validation
- SQLite database with tasks and toolchain_versions tables
- Gitea REST API client for repository and branch operations
- K8s client for Job lifecycle management (with noop fallback for local dev)
- REST API: tasks CRUD, retry, plugins, version management
- Worker/scheduler with polling, concurrency control, and job tracking
- Static frontend: generate, tasks, settings pages
- Toolchain images: Go and Node.js Dockerfiles with entrypoint scripts
- Helm chart with deployment, service, configmap, ingress, PVC
- Multi-stage Dockerfile for service
- Unit tests for config, database, gitclient, k8s, api, worker
- E2E tests for idempotency, version switch, failure recovery
2026-08-10 16:54:30 +08:00

79 lines
1.7 KiB
Go

package main
import (
"context"
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"proto-gen/internal/api"
"proto-gen/internal/config"
"proto-gen/internal/database"
"proto-gen/internal/gitclient"
"proto-gen/internal/k8s"
"proto-gen/internal/worker"
)
func main() {
configPath := flag.String("config", "config.yaml", "path to config file")
flag.Parse()
cfg, err := config.Load(*configPath)
if err != nil {
log.Fatalf("loading config: %v", err)
}
db, err := database.New("proto-gen.db")
if err != nil {
log.Fatalf("initializing database: %v", err)
}
defer db.Close()
git := gitclient.NewClient(cfg.Git.BaseURL, cfg.Git.Token)
var k8sClient k8s.K8sClient
if cfg.Cluster.Kubeconfig == "" || cfg.Cluster.Kubeconfig == "/dev/null" {
log.Println("no kubeconfig provided, running in local mode (no K8s jobs)")
k8sClient = k8s.NewNoopClient()
} else {
k8sClient, err = k8s.NewClient(cfg.Cluster.Kubeconfig)
if err != nil {
log.Printf("warning: k8s client init failed: %v, running in local mode", err)
k8sClient = k8s.NewNoopClient()
}
}
scheduler := worker.NewScheduler(db, k8sClient, cfg)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go scheduler.Start(ctx)
server := api.NewServer(db, cfg, git)
httpServer := &http.Server{
Addr: cfg.Server.Addr,
Handler: server,
}
go func() {
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("server error: %v", err)
}
}()
log.Printf("proto-gen server started on %s", cfg.Server.Addr)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("shutting down...")
cancel()
httpServer.Shutdown(context.Background())
}