#Can't access service

1 messages · Page 1 of 1 (latest)

flat summit
#

Hey all,
this is almost defiantly a problem with my understanding of how this should work.

Pretty much I have 3 services, a db , a migration service and then a swagger service.
The migration service is running as intended and the swagger is accessible but I can seem to get swagger to hit the db.

Here's the gist of the setup

func (i *Integration) TestSwagger(ctx context.Context, src *dagger.Directory) (*dagger.Service, error) {
db, err := i.postgresDB().
Start(ctx)

if err != nil {
    return nil, err
}

defer db.Stop(ctx)

    // adds db as service : WithServiceBinding("db", db).
server, err := i.swagger(db, src).
    Start(ctx)

if err != nil {
    return nil, err
}

    // adds db as service : WithServiceBinding("db", db).
migration, err := i.migrationService(src, db).
    Start(ctx)

if err != nil {
    return nil, err
}

defer migration.Stop(ctx)

return server, nil

}

Here's the whole file : https://github.com/bardic/gocrib/blob/feature/dagger/integration/.dagger/main.go

Any thoughts or directions to investigate would be much appreciated!

GitHub

Contribute to bardic/gocrib development by creating an account on GitHub.

proper spade
#

Hi @flat summit

Looks like your AsService() needs to add useEntrypoint because of a breaking change in 0.15.1 that we may revert.

The change made it so that the container's default ENTRYPOINT would not be run for AsService(), but that breaks many container images that rely on that for an initialization script like the postgres image's docker-entrypoint.sh.

https://github.com/dagger/dagger/issues/9190#issuecomment-2558254529

    func (i *Integration) postgresDB() *dagger.Service {
    return dag.Container().
        From("postgres:latest").
        WithEnvVariable("POSTGRES_USER", "postgres").
        WithEnvVariable("POSTGRES_PASSWORD", "example").
        WithEnvVariable("POSTGRES_DB", "cribbage").
        WithExposedPort(5432).
        AsService().
        WithHostname("db")
    }

needs to be

    func (i *Integration) postgresDB() *dagger.Service {
    return dag.Container().
        From("postgres:latest").
        WithEnvVariable("POSTGRES_USER", "postgres").
        WithEnvVariable("POSTGRES_PASSWORD", "example").
        WithEnvVariable("POSTGRES_DB", "cribbage").
        WithExposedPort(5432).
        AsService(dagger.ContainerAsServiceOpts{UseEntrypoint: true}).
        WithHostname("db")
    }
#

cc @vocal sequoia @sharp rivet