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
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gitea := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Gitea mock: %s %s", r.Method, r.URL.Path)
|
||||
switch {
|
||||
case r.URL.Path == "/api/v1/repos/test-owner/yoresee_doc/branches/main":
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"name": "main",
|
||||
"commit": map[string]string{"id": "abc123def456"},
|
||||
})
|
||||
case r.URL.Path == "/api/v1/user/repos":
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"name": "new-repo"})
|
||||
default:
|
||||
w.WriteHeader(404)
|
||||
fmt.Fprintf(w, `{"message": "not found"}`)
|
||||
}
|
||||
}))
|
||||
defer gitea.Close()
|
||||
|
||||
fmt.Printf("Mock Gitea running at: %s\n", fmt.Sprintf(`export GIT_BASE_URL=%s`, gitea.URL))
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user