#How to handle Nginx with multiple services

1 messages · Page 1 of 1 (latest)

lean ravine
#

Hello! I have been building out a local CI runner to test out dagger for my team and so far its been working great!

There is one snag I have hit and can't quite figure out how to resolve it. In a docker-compose setup all the services have access to each others defined hostnames within the network. So this makes routing through nginx using its hostname relatively straight forward. However, with my limited knowledge and experience with dagger I am having a hard time replicating this. As I understand WithServiceBinding is only available to the container with which its being bound to. Also it doesn't seem to be possible to attach additional services once AsService has been called (I assume that attaching an additional service and calling AsService again would just create another separate instance of that service). So would the solution here be to expose nginx to the host or some other tunneling mechanism? Then to route the container calls that are proxied by nginx to that? Or is there a better solution?

Thank you!

honest crater
#

Great question, there are a couple ways to approach this.

Would you be able to share what you have so far? It's ok if not, but would make things a bit easier.

I am also curious if you got started with zenith modules, or if you are using "standard" dagger.

#

The most relevant parts of our docs are here: https://docs.dagger.io/757394/use-services/#conclusion

Dagger supports container to container, container to host, and host to container networking, so there are a lot of ways to approach this problem.

I'd love to get a better sense of what your whole stack looks like so we can discuss the best approach.

I'm not 100% sure what you mean by this, but I think the answer to my previous questions will help me understand what you mean here:

As I understand WithServiceBinding is only available to the container with which its being bound to. Also it doesn't seem to be possible to attach additional services once AsService has been called (I assume that attaching an additional service and calling AsService again would just create another separate instance of that service).

Dagger v0.9.0 includes a breaking change for binding service containers. The Container.withServiceBinding API now takes a Service instead of a Container, so you must call Container.asService on its argument. See the section on binding service containers for examples.

stoic fractal
#

@lean ravine service bindings are point to point, so there is no direct equivalent of docker compose-style "N-to-N" networking.

I see two options:

  1. explicitly bind services that do need to talk to each other, by making each 1-to-1 binding call

  2. Implement the N-to-N model yourself as code. Should be very doable with a double for loop. Perhaps @quiet nimbus has already done this in his docker compose compat module?

#

(mm actually point 2 is maybe not that trivial since you have a chicken and egg problem as you described. so would need to walk the depency graph to do bindings in the right order. and could not support loops)

lean ravine
#

Hey @stoic fractal thank you for the reply!

Yes, I am currently doing point 1 with our newer services and that has been working very well in the integration test setup that I built using dagger. The issue has been our legacy service that we inherited that's a bit of a black box to us. We generally don't interact with it between the backend services, but there are a few exceptions to this. So it's just been easier to route communication through nginx instead of direct communication with that system. With that said though, this is more or less because of our unique situation. I can fiddle around with it and should be able to figure something out for this case.

Also thanks for all the hard work on dagger! So far it's been a great experience working with it. Being able to create a shared library for CI is amazing and I think will help us bring consistency to CI in our multi repo setup.

lean ravine