2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-04-09 08:05:17 +07:00
|
|
|
"os"
|
2019-11-02 21:32:58 +07:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2019-11-02 21:32:58 +07:00
|
|
|
)
|
|
|
|
|
2020-04-09 08:05:17 +07:00
|
|
|
//nolint:unparam
|
2019-11-02 21:32:58 +07:00
|
|
|
func waitUntilServiceLogDetected(
|
|
|
|
interval time.Duration,
|
|
|
|
timeout time.Duration,
|
|
|
|
dockerEnvironment *DockerEnvironment,
|
|
|
|
service string,
|
2019-11-19 06:37:36 +07:00
|
|
|
logPatterns []string) error {
|
2019-11-02 21:32:58 +07:00
|
|
|
log.Debug("Waiting for service " + service + " to be ready...")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
err := utils.CheckUntil(5*time.Second, 1*time.Minute, func() (bool, error) {
|
|
|
|
logs, err := dockerEnvironment.Logs(service, []string{"--tail", "20"})
|
|
|
|
fmt.Printf(".")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2019-11-19 06:37:36 +07:00
|
|
|
for _, pattern := range logPatterns {
|
|
|
|
if strings.Contains(logs, pattern) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
2019-11-02 21:32:58 +07:00
|
|
|
})
|
|
|
|
|
|
|
|
fmt.Print("\n")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
func waitUntilAutheliaBackendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 21:32:58 +07:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-backend",
|
2021-08-03 16:55:21 +07:00
|
|
|
[]string{"Listening for"})
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2019-11-02 21:32:58 +07:00
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
func waitUntilAutheliaFrontendIsReady(dockerEnvironment *DockerEnvironment) error {
|
|
|
|
return waitUntilServiceLogDetected(
|
2019-11-02 21:32:58 +07:00
|
|
|
5*time.Second,
|
|
|
|
90*time.Second,
|
|
|
|
dockerEnvironment,
|
|
|
|
"authelia-frontend",
|
2021-10-08 11:00:06 +07:00
|
|
|
[]string{"vite v2.6.3 dev server running at", "ready in"})
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2019-11-16 04:10:12 +07:00
|
|
|
|
2020-11-27 16:59:22 +07: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 23:49:52 +07:00
|
|
|
log.Info("Waiting for Authelia to be ready...")
|
|
|
|
|
|
|
|
if err := waitUntilAutheliaBackendIsReady(dockerEnvironment); err != nil {
|
2019-11-16 04:10:12 +07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-16 17:25:02 +07:00
|
|
|
if os.Getenv("CI") != stringTrue && suite != "CLI" {
|
2020-04-09 08:05:17 +07:00
|
|
|
if err := waitUntilAutheliaFrontendIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-30 23:49:52 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2020-11-27 16:59:22 +07:00
|
|
|
if suite == "ActiveDirectory" {
|
|
|
|
if err := waitUntilSambaIsReady(dockerEnvironment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-30 23:49:52 +07:00
|
|
|
log.Info("Authelia is now ready!")
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-16 04:10:12 +07:00
|
|
|
return nil
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|