small pixel drawing of a pufferfish gore

add + supervise works
Jes Olson j3s@c3f.net
Sun, 29 Dec 2024 22:34:34 -0500
commit

acc90224f3b19250f9432d4f6e88e7893dd08cec

parent

d3ade1f70d2c5b4c33946e19444f5e7decbfd8f5

3 files changed, 32 insertions(+), 36 deletions(-)

jump to
M internal/module/module.gointernal/module/module.go

@@ -46,29 +46,34 @@ escapedImportPath, err := module.EscapePath(importPath)

if err != nil { return nil, err } + fmt.Println("proxyRequest", proxyBase+"/"+escapedImportPath+"/"+escapedSuffix) req, err := http.NewRequest("GET", proxyBase+"/"+escapedImportPath+"/"+escapedSuffix, nil) if err != nil { return nil, err } // TODO: dynamic version here pls - req.Header.Set("User-Agent", "gore runs everything alpha") + req.Header.Set("User-Agent", "gore runs everything") return req, nil } func moduleInfo(ctx context.Context, importPath, version string) (*latestResp, error) { + fmt.Printf("moduleInfo\n importpath=%s\n version=%s\n", importPath, version) suffix := version + ".info" if version == "latest" { suffix = "@latest" } req, err := proxyRequest(importPath, suffix) if err != nil { + fmt.Println("moduleInfo proxyRequestErr", err) return nil, err } req.Header.Set("Accept", "application/json") resp, err := http.DefaultClient.Do(req.WithContext(ctx)) if err != nil { + fmt.Println("moduleInfo DefaultClient.Do err", err) return nil, err } + fmt.Println("moduleInfo success: ", resp) defer func() { io.ReadAll(resp.Body) resp.Body.Close()

@@ -91,6 +96,7 @@ return &latest, nil

} func resolveGoMod(ctx context.Context, importPath string, latest *latestResp) (*resolvedModule, error) { + fmt.Println("importpath", importPath) req, err := proxyRequest(importPath, latest.Version+".mod") if err != nil { return nil, err

@@ -121,10 +127,13 @@ func Resolve(ctx context.Context, importPath, version string) (*resolvedModule, error) {

eg, latestctx := errgroup.WithContext(ctx) parts := strings.Split(path.Clean(importPath), "/") + fmt.Println("Resolve importpath", importPath) + fmt.Println("parts", parts) resps := make([]*latestResp, len(parts)) for idx := len(parts); idx > 0; idx-- { idx := idx // copy importPath := strings.Join(parts[:idx], "/") + fmt.Println("Resolve loop importPath", importPath) eg.Go(func() error { if importPath == "github.com" { // Short-circuit: github.com is not a Go module :)

@@ -151,11 +160,17 @@ }

for idx := len(parts); idx > 0; idx-- { importPath := strings.Join(parts[:idx], "/") + fmt.Println("Resolve importpath2", importPath) resp := resps[idx-1] + fmt.Println("Resolve resp", importPath) if resp == nil { + fmt.Println("response nil") continue } - return resolveGoMod(ctx, importPath, resp) + r, err := resolveGoMod(ctx, importPath, resp) + fmt.Printf("Resolution module=%s version=%s", r.Module, r.Version) + fmt.Printf("Resolution Error %+v", err) + return r, err } return nil, fmt.Errorf("could not resolve import path %q to any Go module", importPath)
M status.gostatus.go

@@ -266,10 +266,8 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {

services.Lock() defer services.Unlock() status := struct { - Services []*service - BuildTimestamp string - Meminfo map[string]int64 - Hostname string + Services []*service + Meminfo map[string]int64 }{ Services: services.S, Meminfo: parseMeminfo(),

@@ -331,36 +329,10 @@ return

} } - // if _, err := os.Stat(filepath.Join(buildDir, "go.mod")); err == nil { - // log.Printf("Adding require line to existing go.mod") - // } else { - // log.Printf("Creating go.mod based on upstream go.mod") - // modf, err := modfile.Parse("go.mod", resolved.GoMod, nil) - // if err != nil { - // log.Printf("parsing old go.mod: %v", err) - // return - // } - // if err := modf.AddModuleStmt("gore/build/" + resolved.Module); err != nil { - // log.Println(err) - // return - // } - // - // b, err := modf.Format() - // if err != nil { - // log.Println(err) - // return - // } - - // if err := os.WriteFile(filepath.Join(buildDir, "go.mod"), b, 0600); err != nil { - // log.Println(err) - // return - // } - // } - get := exec.Command("go", "install", resolved.Module+"@"+resolved.Version) absoluteInstallPath, err := filepath.Abs(filepath.Join(buildDir + "@" + resolved.Version)) if err != nil { - fmt.Fprintf(w, "oopsie woopsie, we made a fucky wu- actually, you know what? 500 internal server error. fuck you.") + fmt.Fprintf(w, "500 internal server error\n%s", err) log.Println(err) return }

@@ -368,12 +340,12 @@ get.Env = append(os.Environ(), "CGO_ENABLED=0", "GOBIN="+absoluteInstallPath)

get.Stdout = os.Stdout get.Stderr = os.Stderr if err := get.Run(); err != nil { - fmt.Fprintf(w, "oopsie woopsie, we made a fucky wu- actually, you know what? 500 internal server error. fuck you.") + fmt.Fprintf(w, "500 internal server error\n%s", err) log.Println(err) return } - // add to service list - + svc := newService(filepath.Join(absoluteInstallPath, filepath.Base(path))) + superviseService(svc) http.Redirect(w, r, "/", http.StatusSeeOther) }
M supervise.gosupervise.go

@@ -668,6 +668,15 @@ }.Encode()

http.Redirect(w, r, u.String(), http.StatusSeeOther) } +// superviseService adds a single service to the +// existing supervision tree +func superviseService(svc *service) { + services.Lock() + services.S = append(services.S, svc) + defer services.Unlock() + go supervise(svc) +} + func superviseServices(svc []*service) { services.Lock() services.S = svc