Repository navigation
Conversation
|
Update: added h2c support |
|
FYI, I added more details on the summary above. |
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
1231ac4 to
be2804d
Compare
|
Really excited to dig in to this! re: service aliases:
I like the idea here but I think there may be significant technical hurdles (possibly blockers). The great thing is that it lets you avoid using interpolation/env vars and write code like the following instead. (Arbitrary code based on my original mockup for a minimal diff.) diff --git a/test.go b/test.go
index 8c50b1c..c4c7edd 100644
--- a/test.go
+++ b/test.go
@@ -17,8 +17,8 @@ func TestServices(t *testing.T) {
client := c.Container().
From("alpine").
- WithServiceVariable("URL", srv.Address("http", "http://$host:$port")).
- WithExec([]string{"sh", "-c", "wget -O- $URL"})
+ WithServiceDependency(srv, "mysvc").
+ WithExec([]string{"wget", "-O-", "http://mysvc:8080"})
out, err := client.Stdout(ctx)
require.NoError(t, err)The main difference is being able to avoid templating + env vars + the Here are the downsides I see:
re: start/stop: Bass doesn't have either of these and makes it transparent instead (start when any client needs, stop when all clients are done), so I just have some questions to build bridges in my brain:
re: proxy: I like it! Statefulness (having a |
Yes, exactly. I consider this to be a major advantage, which motivates me to at least try to address the potential downsides. Speaking of which...
I agree that we should consider TLS now. A few potential solutions, keeping in mind that I am absolutely not a TLS wizard:
I actually think this is a good thing. Direct IP addressing is the correct abstraction layer to focus on. It's "low" enough that we can support 99% of real world use cases, and "high" enough that we can still implement lots of magic. This is especially true now that we have full control over buildkit configuration, CNI hooks etc. IMO we should only move up to the port layer if we absolutely cannot find a way to make it work at the IP layer. In Docker we didn't have the luxury of offering a complete networking model at the IP layer, and we missed it sorely every day, especially for c2c. "Less hospitable networks" are definitely a reality, but I think there are good tools we can reach for:
I agree with your assessment. I started with CNAME because of the extra information it carries (you can look up the real hostname with a CNAME lookup). Whether that's actually useful remains to be seen (see option 3 in how to handle TLS, above).
This is a question for @aluzzardi , I just copy-pasted this field from his original design :) Thanks for the thoughtful review! |
On the same page! 👍
Yeah, I largely agree. There were only two things that led me to adding TLS:
With your proposal, the second point has changed slightly: the user can control hostnames, but on the client side instead. So now you could theoretically generate a CA + certificate for the alias, pass the cert + key to the service, and the CA to the client. It wouldn't help for the Buildkit -> registry traffic, but that's a bit of a corner case, and it might be something we can address in the future if Buildkit does moby/buildkit#3366.
Yeah this seems like a reasonable approach.
Fair. I agree that direct addressing is a much more powerful layer to build upon and it wouldn't be a terrible thing to make it a hard requirement. I think it's worth thinking about the client/server coupling aspect though. What if the server and the client are written by different people or are organized into separate parts of the codebase? Say for example an extension provides a In #4080 (comment) this is addressed by having each port be named, and then using the template string to substitute I don't have a solution I love for this yet, but here's a strawman: make exposed ports named, and have the client use |
The buildkit->registry use case is interesting. It agree that it's a corner case, since it's the only one that involves the buildkit
🥳
That is a good question. I think no matter what, there will always be some level of tight coupling. Either my client requires your port Sure, in theory you could change your service to listen to port
At the risk of invoking my Docker experience too much (I know you're familiar with this fear 😄), one lesson I learned is that people have very subjective opinions on how to do service discovery "right". There is no method that will make everyone happy, and not break someone's software somewhere. So IMO the best method is "no method": provide the bare minimum for a solid experience, and let people build their own Rube Goldberg machine on top for service discovery - and they will! For example, some software just needs to control the entire port range, because they will allocate ports dynamically as part of their own damn protocol. Just ask @gerhard about RabbitMQ networking... Here's a teaser 😁
The more opinions we have on the topic of port allocation, port naming etc, the less software will be able to use it, and the more important it is to make it optional or just not define it at all. That said I think there is one feature missing from my proposal: port introspection. There should be an API call to list ports by a given service, with the description (that's what the "description" field is for Sorry for the wall of text :) |
|
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. |
|
@shykes continuing the conversation in case someone else wants to carry the torch:
True
Realistically, that documentation probably won't exist for "internal" CI code so I wouldn't want to completely rely on it. One way to get around the docs requirement is to let user guess and get feedback when they're wrong via helpful error messages. Another is through introspection as you proposed (more on that later).
Yep - using a named port will be helpful if your dependency changes in any way. Either things will continue to work (backwards-compatible change to different port), or you'll get But as you said it comes down to whether the frequency and acuteness of this pain justifies the added friction, and whether we can make that friction feel justified by other means (e.g. code that's more readable, maintainable, or easier to write).
This is definitely important - I had this in mind when bringing up named ports too. Also we'd probably want a separate description field even with names. The code authoring workflow seems kind of awkward though. To figure out the port I want to use I would have to write throwaway code to call the port introspection API, print them, and exit. Then I would run my pipeline, deduce the port from the description, and then hardcode the port and delete the code. With named ports I could write
Completely agree that this is OK either way, and I don't think this really changes based on whether ports are named or queried before they're used. With direct addressing this and any other dynamic software should Just Work, but it does imply we would need a way to get a service's address without a port or port name. I suppose the port name param could be optional, or we could add A not-so-hidden motivator for all of the above is to avoid the CNAME complexity. It's not the higher-order bit (DX comes first), but it's still there. With that in mind, here's an alternative proposal without port names: instead of calling This is roughly the same as above, but without port names. We wouldn't need the CNAME complexity, and you'd get a nice error if the port isn't among the service's exposed ports. It won't handle a port changing semantics, but that seems less likely. In the dynamic case (RabbitMQ), you could just do edit: Also just to be clear I'm good with sticking with CNAME + direct ports as proposed, just trying to navigate the decision tree. 😄 |
|
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. |
|
@shykes Some interesting prior art from testcontainers which has a ton of parallels to what we're trying to solve here:
Also, they have an additional way for checking service health: waiting for a log line to appear! It's implemented as a pluggable Their model seems closest to the last part of my last comment. No named ports, and you call a method to get an address to a given port. They also allow you to specify a protocol if you want to get |
|
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 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. |
Overview
This is a proposal for a unified container networking API. It is directly inspired by the design of bass as described by @vito, with some API tweaks and expanded to also support networking between containers and host (c2h and h2c).
Features include:
Standalone service API
As discussed with @aluzzardi : we don't currently have a source of truth API design for services, so I'm including one here. If a source of truth emerges elsewhere, I can rebase my proposal on top of it.
DNS-based service discovery
The primitive for this design is point-to-point IP connectivity between containers, with DNS-based service discovery.
Both the overall design, and specifics of how to implement it on top of buildkit (keep the IP address out of llb, use solve first to dedup, etc), are directly lifted from Bass. See this comment for details.
Note: the part about TLS injection is awesome, and I think we should do exactly the same thing. It is not included in this proposal simply for lack of time, but adding it should not require any major API changes.
Configurable service alias
This is an important feature layered on top of the Bass design.
In addition to allocating a unique, non-configurable hostname for each service.. we allow each downstream consumer of a service to define its own alias for that service. This alias should be implemented as a CNAME record pointing to the unique service hostname. Crucially, aliases are local to each container. This avoids naming conflicts which in turn makes user-configurable aliases possible. The tradeoff is increased complexity in implementing the resolver, since there are as many DNS resolver configurations as there are containers. Note that resolver configuration can no longer be updated after executing the process (command or service) that will do the resolving, which should help reduce complexity.
This approach to service discovery has a major benefit: compatibility with existing software. Virtually any program that connects to a TCP or UDP service can be packaged in a Dagger container, and wired to another service, with zero code modification or wrapper. This was a deliberate design decision in Docker as well. It was controversial at the time because Heroku-style
$PORTconventions were all the rage. But not requiring code modification or wrappers turned out to be a huge advantage for adoption.Host proxy service for c2h and h2c
For communication between containers and host, we build on top of the
Serviceprimitive with a special "proxy service". A proxy service follows the same networking rules as a regular container service (see DNS-based service discovery and Configurable service alias). But instead of running a user-defined container image, it runs Dagger's builtin proxy with port forwarding rules in both directions.This "everything is a service approach" has DX and OX benefits:
DX benefits: less concepts to learn; easier to swap host and container services for mocking and decoupling. For example, a pipeline might take a Service dependency as argument, and the caller can decide whether to pass a container or host service.
OX benefits: easier to understand the operational model; if you look at a list of running services, you are looking at all networking involving your containers (except outbound to the public internet). Any operational tooling on services also benefits host networking: stats, hooks, access control, pluggable networking backends, visualization, etc.
Health checks and service coordination
A simple mechanism for health checks and coordination is included. The default behavior is what most users expect: wait for the services you depend on to be available, before running your own.
Note that thanks to the "everything is a service" approach, health checks and coordination work exactly the same way for both c2c and c2h.