#enabling dag.Host()
1 messages · Page 1 of 1 (latest)
Thanks for the tip! Here's what I have
https://v3.dagger.cloud/kpenfound/traces/699b76e56a6c954b4b1a0168f2ea2846#81b66c2294f51337
clean.pprof with nothing running, hanging.pprof in the state shown in the screenshot. Nothing immediately jumps out at me in that trace
oh and the code
// Run the GitHub Webhook Listener
func (m *GithubWebhooks) Listen() (*dagger.Service, error) {
http.HandleFunc("/", handler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
return nil, err
}
return dag.Host().Service([]dagger.PortForward{{Backend: 8080}}), nil
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}
the goal is to take that http.ListenAndServe in the runtime container and return it as a dagger.Service
update on this
- the "hanging" I was seeing was really not hanging and working as intended lol. I needed a
go http.ListenAndServe
- @shy citrus helped get past some broken type things on the llm branch
- Trying to get through
tunneling to non-Container services is not supported. Maybe the tunnel needs to get created withNative: true? I haven't figured out yet where to wire that through without breaking things
hrm don't think native: true would help there, that just configures how to select ports (frontend == backend)
ah got it. Maybe there's a way to set svc.Container to the runtime container?
what are you trying to tunnel?
basically this
slightly surprised it ended up down that code path, but i haven't been following extremely closely
maybe there's an easier way?
where does the tunnel come in?
oh, are you calling up on the outside?
yes exactly
so the goal is to start a service in the container, and then serve traffic to it through the (outer) host network?
yes. If there's any other way to do that, I'm in
I don't specifically care about host.service
yeah feels like a common enough use case
the problem is the module function is trying to do two things: 1) run a service indefinitely, but then 2) return the service from the function. right now 2) implies the function exits, hence no 1)
ah true
trying to think of any gymnastics to get around it, but conceptually that feels confusing at least
maybe some way to pass the http.Serve as a callback to some dag function
maybe a good topic for the core dev architecture chat in 10mins 😛
this makes sense on paper but the problem will be that the runtime container has a specific calling convention
my specific use case is to run a go webserver that listens for github webhook events and depending on the event call different functions in my module. So there's no good way to just run that in a container in my module. Maybe if there's some dagger-in-dagger in the service container calling a second module for the event functions... but 🤮
technically i think we could have a function that "returns" (i.e. makes the internal API calls that return a value from a function) but then doesn't actually exit, but it would probably require some SDK changes, e.g. to wait on your http.ListenAndServe goroutine instead of just exiting from main()
not sure how it would look in other languages
seems plausible though
back to this - couldn't we return the runtime itself as a service container? There's nothing specifically watching the listening process, but it can just run until I cancel it
don't think so. it would be started fresh, and it wouldn't be told to run the service
(core dev chat starting)
(cc @trail monolith - this is the thread if you wanna follow along)
the basic idea we came up with was to have a way to ✨somehow✨ turn any object that implements serve: Void (aka Serve(context.Context) error) into a Service
no idea if that's feasible on a demo timeline - maybe with some hacks. ideally we'd have self-calls for this, but we can get by without it
sounds great! i'll push forward on other demos for now but I'm eager to try this out!
There's another possible route maybe - if we made all core types interfaces like we discussed - maybe the module type could implement Service?
I guess that doesn't really help since either way, your function has to return, and there's no way for long-running code started by a dagger function to outlive its function
Feels like maybe the "start a container, let it call dagger-in-dagger" route is more realistic? But then the limitation is self-calls
Yeah I can go forward with the dagger-in-dagger and see how bad it really looks. Maybe I can abstract some of the bad parts away so it doesn't look scary
I think making the server a standalone go program (not a dagger module), in a sub-package, with a dagger.json with dependencies on modules you want to call + generated client to call them from the standalone server, will really help clean it up
then the remaining problem (besides plumbing the above) is: which module? I think actually Tom got "self calls" to work in generated client so it might be possible for the standalone server at ./pkg/webhook-server to call ./foo-module
it might just work