#How Can I add custom health logic
1 messages · Page 1 of 1 (latest)
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"})
}