#New Services API usage

1 messages · Page 1 of 1 (latest)

novel crow
#

Hello! I was trying to use the new Services API that was released with the latest version of Dagger from the Golang SDK. My intent was to start Postgres and Redis services that are dependencies of one of our applications. However, I keep getting errors like:

input:1: container.from.withServiceBinding.withServiceBinding.withMountedDirectory.withWorkdir.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withEnvVariable.withExec.withExec.directory start  (aliased as postgres): service exited before healthcheck

I'm trying to use code like this:

    postgres := client.Container().From("public.ecr.aws/docker/library/postgres:14.5").WithExposedPort(5432)

    app = app.WithServiceBinding("postgres", postgres)

Do I have to specify the Postgres container in a special way? I'm just trying to use its default entrypoint. There are no debug logs I can get from as well, so I can't check why the container is exiting. The same issue is happening with the Redis, which is also exitting.

thick moth
#

cc summoning the Services master @sinful flower here :). Had very little time to play with the services API myself (cries in daggernaut tears)

jovial jacinth
#

@novel crow I am also not an expert in using the services API, but it looks like you're using it correctly. There is no special thing to do beyond what you're doing, I think

sinful flower
#

@novel crow if you add dagger.WithLogOutput(os.Stderr) to dagger.Connect(ctx, ...) do you see any logs from the services there?

#

oh - this might be the same thing as here, actually: #general message

tl;dr add WithExec(nil) to postgres and redis

#

you'll probably also need WithEnvVariable("POSTGRES_PASSWORD", "foo") but it should say that with an error now instead of silently exiting

novel crow
#

I did try the following before:

    postgres := client.Container().
        From("public.ecr.aws/docker/library/postgres:14.5").
        WithWorkdir("/usr/local/bin/").
        WithExec([]string{"docker-entrypoint.sh"}).
        WithExposedPort(5432)

    app = app.WithServiceBinding("postgres", postgres)

    redis := client.Container().
        From("public.ecr.aws/docker/library/redis:latest").
        WithWorkdir("/usr/local/bin/").
        WithExec([]string{"docker-entrypoint.sh"}).
        WithExposedPort(6379)

    app = app.WithServiceBinding("redis", redis)
#

Adding client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr)) doesn't give me any extra output :/

#

Oh, using WithExec(nil) seems to work, atleast I now get the expected password error. Let me add the environment variables and see if this works

sinful flower
novel crow
#

Ok, the app is now building and will run tests. Atleast it seems like the services are working. I'll report when the app tries to connect to them 😄 Thank you so much for the help so far!

sinful flower
#

nice! looking forward to seeing how it goes 👍

novel crow
#

Happy to report that it's now working! I ran an 8000 tests test suite against this setup and 99.9% of them passed. Seems like postgres and redis are working correctly 😄

thick moth