2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
2020-04-09 01:05:17 +00:00
|
|
|
"os"
|
2019-11-02 14:32:58 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2019-11-02 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
2020-04-09 01:05:17 +00:00
|
|
|
//nolint:unparam
|
2019-11-02 14:32:58 +00:00
|
|
|
func waitUntilServiceLogDetected(
|
|
|
|
interval time.Duration,
|
|
|
|
timeout time.Duration,
|
|
|
|
dockerEnvironment *DockerEnvironment,
|
|
|
|
service string,
|
2019-11-18 23:37:36 +00:00
|
|
|
logPatterns []string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
log.Debug("Waiting for service " + service + " to be ready...")
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2023-01-15 23:58:13 +00:00
|
|
|
err := utils.CheckUntil(interval, timeout, func() (bool, error) {
|
2019-11-02 14:32:58 +00:00
|
|
|
logs, err := dockerEnvironment.Logs(service, []string{"--tail", "20"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2019-11-18 23:37:36 +00:00
|
|
|
for _, pattern := range logPatterns {
|
|
|
|
if strings.Contains(logs, pattern) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
2019-11-02 14:32:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func waitUntilAutheliaBackendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 14:32:58 +00:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-backend",
|
2023-02-20 05:37:22 +00:00
|
|
|
[]string{"Startup complete"})
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2019-11-02 14:32:58 +00:00
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
func waitUntilAutheliaFrontendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 14:32:58 +00:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-frontend",
|
2023-01-12 10:57:44 +00:00
|
|
|
[]string{"dev server running at", "ready in", "server restarted"})
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2019-11-15 21:10:12 +00:00
|
|
|
|
2022-12-12 23:15:32 +00:00
|
|
|
func waitUntilK3DIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"k3d",
|
|
|
|
[]string{"API listen on [::]:2376"})
|
|
|
|
}
|
|
|
|
|
2020-11-27 09:59:22 +00:00
|
|
|
func waitUntilSambaIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"sambaldap",
|
|
|
|
[]string{"samba entered RUNNING state"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitUntilAutheliaIsReady(dockerEnvironment *DockerEnvironment, suite string) error {
|
2019-11-30 16:49:52 +00:00
|
|
|
log.Info("Waiting for Authelia to be ready...")
|
|
|
|
|
|
|
|
if err := waitUntilAutheliaBackendIsReady(dockerEnvironment); err != nil {
|
2019-11-15 21:10:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-01 03:32:58 +00:00
|
|
|
if os.Getenv("CI") != t && suite != "CLI" {
|
2020-04-09 01:05:17 +00:00
|
|
|
if err := waitUntilAutheliaFrontendIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-11-27 09:59:22 +00:00
|
|
|
if suite == "ActiveDirectory" {
|
|
|
|
if err := waitUntilSambaIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
log.Info("Authelia is now ready!")
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2019-11-15 21:10:12 +00:00
|
|
|
return nil
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|