#Connecting To External Database During Builds

1 messages · Page 1 of 1 (latest)

spiral knoll
#

Hi I have just begun experimenting with dagger for a java application and able to run the integration tests with a database service.

As part of build process I would like to capture some metadata about the tests and etc to an externally hosted database ( ie this database is not running the host machine)

I have looked at the container to host networking example in 0.9, but still not understanding how i can let the code that posts to the remote database get access to the remote db machine/port from within dagger. And eventually want this to be running on gitlab + dagger

Appreciate your help. Thank you.

maiden idol
#

Hi @spiral knoll! If you have your database on an instance that is reachable from where dagger runs then you should be able to connect it just fine!

spiral knoll
#

Hi @maiden idol thank you very much for the reply.
In my case the application trying to capture the build metrics and post it to the remote db is itself another container being run by dagger.
So we would like to process the build output from the java app in another metrics processing container.

the above works for me locally

    dbService := client.Host().Service([]dagger.PortForward{
        {Frontend: 5432, Backend: 5432, Protocol: "TCP"},
    })
    

    contents, err := client.Container().
        Import(tarFile).
        WithServiceBinding("db", dbService).
        WithEnvVariable("DB_URI", "db_uri").
        WithEnvVariable("DB_USERNAME", "username").
        WithEnvVariable("DB_PASSWORD", "password").
        WithDirectory("/app", build.Directory(".")).
        WithExec([]string{"/bin/metrics-collector.sh", "-n"}).
        Stdout(ctx)

I was nt sure how i could connect the remote db machine similarly from another cotainer in dagger. Thank you will try that