#exposing ports from an intermediate service

1 messages · Page 1 of 1 (latest)

topaz vale
#

Hi,

I have a service that depends on other services:

my-service (port 11170)
├── cassandra (port 9042)
├── kafka (port 9092)
└── zookeeper (port 2181)

in code I do this:

WithServiceBinding("zookeeper", zookeeperService).
WithServiceBinding("kafka", kafkaService).
WithServiceBinding("cassandra", cassandraService).

I'd like to expose all these ports to the host but when I run this:

dagger call my-service up --ports 11170:11170 --ports 9042:9042
``` 
it doesn't work, I think it's trying to expose the port 9042 from the my-service container, which doesn't exist ?

is it possible to do what I want ?
fleet inlet
#

If you're looking to debug, one thing you can do is open an interactive terminal in the container backing my-service, and from there you can ping, curl, etc

topaz vale
#

yes it's for debugging: i'm trying out dagger for local development and for example I usually want to be able to query cassandra to see what has actually been inserted, or consume data from kafka etc.
Using an interactive terminal might work for some things but it won't work if I want to use TablePlus for example.

I guess I was expecting exposing ports to work a bit like Docker Compose.
with compose if I do something like this:

include:
  - cassandra.yaml

services:
  my-service:
    depends_on:
      - cassandra

if the cassandra service has ports: [9042:9042] then I'll be able to access it from the host

fleet inlet
#

cc @wanton thicket

#

Yeah there's a slight mismatch between dagger's and docker-compose's networking model, Dagger is more "strict" by default, you can only expose one service at a time from the CLI.

In your case, I think what you need is a way to expose my-service + its service dependencies, "flattened", as a convenience

#

In the meantime you can implement this yourself with an optional boolean argument to my-service. If the argument is set, instead of returning your service container, you would return a proxy that exposes both my-service + all its dependencies.

#

Something like:

func MyService(
  // +optional
  proxyDependencies bool
) *dagger.Service {
  myService := ... // your usual logic
  if proxyDependencies {
    return dag.
      Proxy().
      WithService(myService, "frontend", 8000, 8000) // Not sure what port your frontend service exposes
      WithService(zookeeperService, "zookeeper", 2181, 2181).
      WithService(kafkaService, "kafka", 9092, 9092).
      WithService(cassandraService, "cassandra", 9042, 9042).
      Service()
  }
  return myService
}
#

(this assumes you use Kyle's proxy module, dagger install github.com/kpenfound/dagger-modules/proxy@v0.2.0)

topaz vale
#

alright, I'll try that, thanks for the help !

in your case, I think what you need is a way to expose my-service + its service dependencies, "flattened", as a convenience
yeah it would be nice if Dagger could do this at some point

topaz vale
#

fyi I just tested your workaround and it works, thank you.