fix: add missing service container health check (#2354)
* fix: Implement missing health ceck for Services * Add test case * linter doesn't support min builtin and fix check --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/nektos/act/pkg/common"
|
||||
@@ -420,6 +421,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||
Mode: 0o666,
|
||||
Body: "",
|
||||
}),
|
||||
rc.waitForServiceContainers(),
|
||||
)(ctx)
|
||||
}
|
||||
}
|
||||
@@ -518,6 +520,40 @@ func (rc *RunContext) startServiceContainers(_ string) common.Executor {
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment) common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
sctx, cancel := context.WithTimeout(ctx, time.Minute*5)
|
||||
defer cancel()
|
||||
health := container.ContainerHealthStarting
|
||||
delay := time.Second
|
||||
for i := 0; ; i++ {
|
||||
health = c.GetHealth(sctx)
|
||||
if health != container.ContainerHealthStarting || i > 30 {
|
||||
break
|
||||
}
|
||||
time.Sleep(delay)
|
||||
delay *= 2
|
||||
if delay > 10*time.Second {
|
||||
delay = 10 * time.Second
|
||||
}
|
||||
}
|
||||
if health == container.ContainerHealthHealthy {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("service container failed to start")
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) waitForServiceContainers() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
execs := []common.Executor{}
|
||||
for _, c := range rc.ServiceContainers {
|
||||
execs = append(execs, rc.waitForServiceContainer(c))
|
||||
}
|
||||
return common.NewParallelExecutor(len(execs), execs...)(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) stopServiceContainers() common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
execs := []common.Executor{}
|
||||
|
||||
Reference in New Issue
Block a user