#How Can I add custom health logic

1 messages · Page 1 of 1 (latest)

gentle thunder
#

Hi everyone,
i have dagger file which has two svcs A and psql, svc A depends on psql but psql become health as soon as 5432 is listening on (before db fully initialized) so that my svc A give me a db starting up error. is there any way to add custom health check logic to services in dagger
Thanks in advance :<3

raw fiber
# gentle thunder Hi everyone, i have dagger file which has two svcs A and psql, svc A depends on ...

hey @gentle thunder! there's nothing natively en the Dagger API but it should be trivial to do this in upserspace, you can add a function in your pipeline chain that performs whatever check you need to do. i.e:

func healthCheck(c *dagger.Container) *dagger.Container {

    for {
        out, _ := c.WithEnvVariable("CACHE", time.Now().String()). // invalidate the cache for each loop
                                        WithExec([]string{"curl", "http://nginx"}).
                                        Stdout(context.TODO())

        if strings.Contains(out, "nginx") {
            break
        }

    }

    return c
}

// Returns a container that echoes whatever string argument is provided
func (m *Lele) Test() *dagger.Container {

    svc := dag.Container().From("nginx").
        WithExposedPort(80).AsService()

    return dag.Container().From("alpine:latest").
        WithExec([]string{"apk", "add", "curl"}).
        WithServiceBinding("nginx", svc).
        With(healthCheck).
        WithExec([]string{"curl", "http://nginx"})

}