Repository navigation
Conversation
This is a convenience API to replace this pattern:
```go
code, err := container.ExitCode(ctx)
if err != nil {
return err
}
if code != 0 {
return fmt.Errorf("exit code: %d", code)
}
```
Right now it's redundant because ExitCode returns an error when it
encounters a nonzero exit code, which is a bug (dagger#3192). Anyone relying
on that behavior and ignoring the code return value should switch to
this new API instead.
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
sipsma
left a comment
There was a problem hiding this comment.
Awesome! Left a few minor comments, looks great overall!
My only broad nit-pick is that there might be some performance benefits to using the socket session attachable mechanism instead of proxying through stdio pipe of gateway containers. The idea being that when a container is spun up that publishes a port, there will be a unix socket provided that is "intercepted" by the shim when it is updating the bundle and it uses that to proxy the connection instead of stdio pipes.
The main possible benefit is that it avoids the need to spin up a new container every time a connection is made on the host. It also avoids having to go through pipes, which I'm sure work fine but have weird limitations around the maximum size of a single read/write and a relatively low default buffer size (IIRC) as compared with socket defaults.
That being said, I highly doubt that this would be noticeable for most straightforward use cases, probably only makes a difference for relatively high load scenarios (which are probably rare), so this isn't a blocker at all. If this approach is about the same complexity as the existing one and you feel like trying it maybe it's worth a shot, but otherwise not a big deal at all. Super excited to have the feature in place!
| // NB(vito): we now use Logrus in other places so it's a bit unfortunate to | ||
| // disable this, solution TBD | ||
| logrus.StandardLogger().SetOutput(io.Discard) |
There was a problem hiding this comment.
We only want to disable logrus.StandardLogger() because it gets spammed with useless messages by the other library, we are free to use our own logger I think. We could re-use the pattern in buildkit of bklog.G(ctx) but just avoid use of StandardLogger maybe.
|
|
||
| proxyContainer, err := gw.NewContainer(ctx, containerReq) | ||
| if err != nil { | ||
| logrus.Warnf("create publish container for :%d: %s", publish, err) |
There was a problem hiding this comment.
When running as a subprocess dagger session needs to write any log messages to stderr, not stdout, just double checking that's where these will end up.
| publish := *port.Publish | ||
|
|
||
| // NB: listen synchronously | ||
| l, err := net.Listen(port.Protocol.Network(), fmt.Sprintf(":%d", publish)) |
There was a problem hiding this comment.
So this will listen on all interfaces on the host by default? If so I think we should make this configurable and probably default to just localhost, just so you have to be more explicit about exposing the service to every host network.
There was a problem hiding this comment.
So this will listen on all interfaces on the host by default? If so I think we should make this configurable and probably default to just localhost, just so you have to be more explicit about exposing the service to every host network.
does this require another experimental flag?
|
@sipsma Would definitely like to avoid the container-per-request overhead. Just threw something together for tomorrow's demo. An earlier iteration just did I don't quite grok how to use the SSH socket attachable yet but I can take a deeper look. I considered it briefly but it seemed more suited for proxying in the other direction (container -> host), and it didn't seem like there was much I could re-use, but I might be missing something. I'm currently running into a weird issue where after a handful of connections it hangs trying to start the proxy process. It's able to create the container, but the Container.Start call hangs. Not sure why yet, but all the more reason to use something more lightweight. Hopefully it doesn't happen in the demo. 😅 edit 1: I'm becoming convinced this is behavior of the thing I'm running, not the proxy. Works fine with simpler examples (e.g. edit 2: The last batch of commits seems to fix it. 🤔 (Closing proxy when stdin ends, and running in the host network.) |
much faster, since we don't really need a bridge for these. could probably do this for the health check too. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
|
Love the feature, don't love the API... The distinction between "exposing" and "publishing" a port was... not a highlight of the Docker UX, and I am not eager to perpetuate the problem in Dagger. As a strawman, I would like to bring back my original suggestion from the API draft. Basically it makes explicit the concept of proxy services. In the initial proposal, proxy services and container services had a common type, Thoughts? |
Ah yeah I was thinking the shim could call connect on the unix socket and then the client-side of the session attachable blocks until a connection on it's client-side listener is made, at which time it will accept the connection and start copying between the two, but I just realized that because we aren't the ones directly calling accept on the unix socket in the server, buildkitd code is, we can't implement that blocking behavior we'd need... There's probably ways of getting it to work but it would become a mess. That's sad but not a big deal since it seems like you got the gateway container idea working fully. The only other possibility I can think of is to maybe add our own session attachable implementation and see if we could use that somehow (plausible now that we control both client and server) but that's way way too complicated to be worth it for now, so never mind :-) |
Interesting to know.. FWIW I never personally found or heard in the wild that the |
That’s the thing, In the early days it was similar to ‘cmd’ and ‘entrypoint’: which is which? Then later the problem became more fundamental: publish where? We had plans to extend the publish concept beyond “a nat rule on the local host”, add a new extension point so that you could eg. publish your port on a firewall, punch holes through your VPC, register a route on an http proxy. But the ecosystem was already fragmenting, the various wrappers just wanted docker to be a dumb single-host runner while they fought each other with incompatible extension points… So Docker gave up on unifying the ecosystem around the engine API and shipped its own wrapper. ‘publish’ remained a single-host concept, impossible to extend. And gradually became irrelevant, like ONBUILD, links etc. So, I think the same question is relevant in our case: ‘publish’ where? It’s not intuitive that the answer is always ‘on the client host’. Especially since we have |
Haha, I completely forgot about that. Definitely worth avoiding the term "publish" then. Shower thought: maybe this is where we bring extend type Container {
"Returns a Socket routing to the specified port, or the first exposed port if unspecified."
socket(port: Int): Socket!
}
extend type Socket {
"Binds the socket in the host address space."
bind(
address: String!,
family: NetworkFamily=IP, # or UNIX?
): Proxy!
}
type Proxy {
close: Void!
}Just a sketch. Things I like:
Things that are weird:
Things I don't like:
This might be a narrower slice of what you accomplished with the earlier Proxy proposal though.
FWIW, I don't think any door needs to stay closed - we're pre-1.0 after all, and if addressing the rest of networking requires a more fleshed-out API, to me any change is on the table. There just needs to be enough carrot with the stick, and h2c networking seems like as good a carrot as any. I liked the symmetry that you found between the Proxy and Service, but I also like where we ended up without it, where services are really just inter-networked containers. We didn't end up needing them to fulfill a Service interface, and decided to avoid explicit service lifecycle management as much as we can. One way of looking at it is we chose to align Containers with Services rather than align Services with Proxies. |
Signed-off-by: Alex Suraci <[email protected]>
I think the main benefit of a common |
Possible alternative solution:
I think I still prefer adding |
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR was closed because it has been stalled for 7 days with no activity. |
|
+1 for networking upgrades, I need to be able to talk to host containers from dagger |
Adds the following API:
Whenever a service runs, either via
run(#4723) orwithServiceBinding, the Dagger session will listen on any published ports and forward traffic to the container via the shim.Note that this is a distinct behavior of
runas opposed toexitCode/stdout/stderr.