I am using a database and cache in my application, and I need these services up and running when I execute my tests; the database has a UI which I use check the data.
Right now, some of the tests are failing times, I need to inspect the DB using UI.
I cannot find a way to expose the DB service to the host while running the tests.
Would prefer:
- dagger call test
- add terminal() before the exec command
- run the test one by one in python container and inspect the database when the test fails.
Would be 100% okay with:
- running both the services using one function
- dagger call run-services
- running the python container, passing the services as host service, run the test one by one.
@object_type
class FooTests:
@function
def run_db(self) -> dagger.Service:
return (
dag.container()
.from_("arangodb:3.12.3")
.with_env_variable(name="ARANGO_ROOT_PASSWORD", value="mycomplexpass")
.with_exposed_port(8529)
.as_service())
@function
def run_cache(self) -> dagger.Service:
return (dag.container()
.from_("valkey/valkey:8.0.2")
.with_exposed_port(6379)
.as_service())
def test(self,
source: Annotated[dagger.Directory, DefaultPath("/")]
) -> str:
db = self.run_db()
cache = self.run_cache()
return (dag.container()
.from_("python:3.12-slim-bullseye")
.with_service_binding("db", db)
.with_service_binding("cache", cache)
.with_mounted_directory("/mycode", source)
.with_exec(["sh", "-c", "pytest"], use_entrypoint=False)
.stdout)
@function
async def run_services(self) -> str:
await self.run_db().up() ## this doesn't work -- not sure how to call it.
await self.run_cache().up() ## this doesn't work -- not sure how to call it.
return ""