#Standing up multiple services

1 messages · Page 1 of 1 (latest)

spiral aspen
#

Should the following code be open to localhost?
dag.proxy().with_service(redis, "redis", consts.REDIS_PORT, consts.REDIS_PORT).service()

It looks like it's listening on my public IP, like 10.87.x.x, and I can't connect to it either at that address or at localhost. Is there a working example of multiplexed services on localhost that I can study? Is dag.proxy still the recommended way of standing up multiple services?

#

Standing up multiple services

topaz sandal
#

@spiral aspen are you using modules?

#

s dag.proxy still the recommended way of standing up multiple services?

it is. You need to return a dagger.Service from your function and the call dagger call $fn up

spiral aspen
#

I believe so. The code, simplified for illustration to hold only one service, looks like

@object_type
class ApiServer:

  @function
    async def redis(self) -> Service:
        redis = (dag.container().from_(consts.REDIS_IMAGE)
                  .with_mounted_cache("/data", dag.cache_volume("redis-cache"))
                  .with_exposed_port(consts.REDIS_PORT)
                  .as_service())
        return dag.proxy().with_service(redis, "redis", consts.REDIS_PORT, consts.REDIS_PORT).service()
topaz sandal
#

that seems correct @spiral aspen .

If you call dagger call redis up it should be listening in the REDIS_PORT locally in your machine

#

one thing to note though is that "I believe" that the proxy module only proxies http services. If I'm not hallucinating, I think someone mentioned here that they changed it to support tcp as well. Let me do a quick search

spiral aspen
#

so it won't work for redis and databases? If so, what should I do?

topaz sandal
spiral aspen
#

I'd suggest writing some documentation on this; it must be a common task to stand up services. Is there another way to do this without running dagger separately for each service?

topaz sandal
#

@spiral aspen to unblock you, I could push the change I shared above to Kyle's proxy module if that works for you

spiral aspen
#

Please push it, I'll try it.

topaz sandal
#

sure, gimme a sec

topaz sandal
topaz sandal
#

@spiral aspen just confirming here that you're unblocked, correct?

spiral aspen
#

Yes

spiral aspen
#

It works locally but Github Actions fails with

input: moduleSource.withContextDirectory.asModule resolve: failed to create module: select: failed to update module dependencies: failed to load module dependencies: select: failed to load pre-configured dependencies: failed to create module source from dependency: select: failed to resolve git src to commit: failed to checkout remote https://github.com/kpenfound/dagger-modules: git error: exit status 128
stderr:
fatal: unable to read tree (beaf4600637b3f492cd3e1e1598ef799d8cd3164)

My dagger.json reads

{
  "name": "api_server",
  "sdk": "python",
  "dependencies": [
    {
      "name": "proxy",
      "source": "github.com/kpenfound/dagger-modules/proxy@beaf4600637b3f492cd3e1e1598ef799d8cd3164"
    },
    {
      "name": "testcontainers",
      "source": "github.com/vito/daggerverse/testcontainers@09c1b5b172e58a8fd58ee790d81018cd478590fc"
    }
  ],
  "source": "dagger",
  "engineVersion": "v0.12.0"
}

This is the current version https://daggerverse.dev/mod/github.com/kpenfound/dagger-modules/proxy@beaf4600637b3f492cd3e1e1598ef799d8cd3164

topaz sandal
#

@spiral aspen mind trying again?

#

just re-running the pipeline please

topaz sandal
#

I forgot to push the main branch so something was a bit off. It's somehow strange that it was working in your local machine but it wasn't working in GHA though. Will investigate further

spiral aspen
#

it works now. I'd noticed that you did not use the main branch. I assumed it was because main was protected.